Changeset 10285


Ignore:
Timestamp:
2005-07-25T15:28:42+12:00 (19 years ago)
Author:
kjdon
Message:

soap servers now use GlobalProperties to find gsdl3_home, not SOAPServer.cfg

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServer.java.in

    r10124 r10285  
    11/*
    2  *    SOAPServer.java
     2 *    SOAPServer.java.in: a template for a new SOAPServer
    33 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
    44 *
     
    2020package org.greenstone.gsdl3;
    2121
    22 import org.greenstone.gsdl3.core.*;
     22import org.greenstone.gsdl3.core.MessageRouter;
     23import org.greenstone.gsdl3.util.GlobalProperties;
    2324import org.greenstone.gsdl3.util.GSFile;
    2425import org.greenstone.gsdl3.util.GSXML;
    2526import org.w3c.dom.Element;
    2627import java.io.File;
    27 import java.io.BufferedReader;
    28 import java.io.FileReader;
    29 import java.net.URL;
    3028
    3129/**
     
    3836public class SOAPServer@sitename@
    3937{
    40     private String config_file_name = "SOAPServer.cfg";
    4138   
    42   /** The message router we're talking to */
    43     MessageRouter mr_=null;
     39    /** The message router we're talking to */
     40    protected MessageRouter mr=null;
     41    /** the name of the site we are serving */
     42    protected String site_name = @sitename@;
    4443 
    45   /** The no-args constructor */
     44    /** The no-args constructor */
    4645    public SOAPServer@sitename@() {
    47     // find out gsdl3home - need to use the web app class loader
    48     ClassLoader class_loader = this.getClass().getClassLoader();
    49     URL url = class_loader.getResource(config_file_name);
    50     if (url == null) {
    51         System.err.println("Couldn't find the config file "+config_file_name+". Can't initialise the SOAP server");
     46    String gsdl3_home = GlobalProperties.getGSDL3Home();
     47    if (gsdl3_home == null || gsdl3_home.equals("")) {
     48        System.err.println("Couldn't access GSDL3Home from GlobalProerties.getGSDL3HOME, can't initialize the SOAP Server.");
    5249        return;
    5350    }
    54     String gsdl3_home = readInFile(url);
    55     if (gsdl3_home == null || gsdl3_home.equals("")) {
    56         return;
    57     }
    58     String site_home = GSFile.siteHome(gsdl3_home, "@sitename@");
     51    String site_home = GSFile.siteHome(gsdl3_home, this.site_name);
    5952   
    6053    File site_file = new File(site_home);
    6154    if (!site_file.isDirectory()) {
    62         System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialsie the SOAP server.");
     55        System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
    6356        return;
    6457    }       
    65     mr_ = new MessageRouter();
    66     mr_.setSiteHome(site_home);
    67     mr_.configure();
     58    mr = new MessageRouter();
     59    mr.setSiteName(this.site_name);
     60    mr.configure();
    6861    }
     62   
    6963   
    7064    public Element [] process (Element [] xml_in) {
     
    8074        }
    8175        Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true);
    82         Element r = mr_.process(new_req);
     76        Element r = mr.process(new_req);
    8377        // add the namespace back on
    8478        //Element new_res = r;
     
    8983    }
    9084    return result;
    91     }
    92 
    93     private String readInFile(URL url) {
    94     String file_name = url.getFile();
    95     // any spaces are encoded as %20
    96     file_name = file_name.replaceAll("%20", " ");
    97     try {
    98         BufferedReader reader = new BufferedReader(new FileReader(file_name));
    99         String line = reader.readLine();
    100         line = line.trim();
    101         return line;
    102     } catch (Exception e) {
    103         System.err.println("Exception occurred when reading in the file "+file_name+": "+e);
    104     }
    105     return null;
    106     }
    107    
     85    }   
    10886}
    10987
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java

    r10123 r10285  
    1717 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1818 */
     19
    1920package org.greenstone.gsdl3;
    2021
    21 import org.greenstone.gsdl3.core.*;
     22import org.greenstone.gsdl3.core.MessageRouter;
     23import org.greenstone.gsdl3.util.GlobalProperties;
    2224import org.greenstone.gsdl3.util.GSFile;
    2325import org.greenstone.gsdl3.util.GSXML;
    2426import org.w3c.dom.Element;
    2527import java.io.File;
    26 import java.io.BufferedReader;
    27 import java.io.FileReader;
    28 import java.net.URL;
    2928
    3029/**
     
    3231 *
    3332 * @author <a href="mailto:[email protected]">Katherine Don</a>
    34  * @version $Revision$
    3533 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
    3634 */
    3735
    3836public class SOAPServerlocalsite
    39     //implements ModuleInterface {
    4037{
    41     private String config_file_name = "SOAPServer.cfg";
    42    
    43   /** The message router we're talking to */
    44     MessageRouter mr_=null;
    45  
    46   /** The no-args constructor */
     38    /** The message router we're talking to */
     39    protected MessageRouter mr=null;
     40    /** the name of the site we are serving */
     41    protected String site_name = "localsite";
     42
     43    /** The no-args constructor */
    4744    public SOAPServerlocalsite() {
    48     // find out gsdl3home - need to use the web app class loader
    49     ClassLoader class_loader = this.getClass().getClassLoader();
    50     URL url = class_loader.getResource(config_file_name);
    51     if (url == null) {
    52         System.err.println("Couldn't find the config file "+config_file_name+". Can't initialise the SOAP server");
     45    String gsdl3_home = GlobalProperties.getGSDL3Home();
     46    if (gsdl3_home == null || gsdl3_home.equals("")) {
     47        System.err.println("Couldn't access GSDL3Home from GlobalProerties.getGSDL3HOME, can't initialize the SOAP Server.");
    5348        return;
    5449    }
    55     String gsdl3_home = readInFile(url);
    56     if (gsdl3_home == null || gsdl3_home.equals("")) {
    57         return;
    58     }
    59     String site_home = GSFile.siteHome(gsdl3_home, "localsite");
     50    String site_home = GSFile.siteHome(gsdl3_home, this.site_name);
    6051   
    6152    File site_file = new File(site_home);
    6253    if (!site_file.isDirectory()) {
    63         System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialsie the SOAP server.");
     54        System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
    6455        return;
    6556    }       
    66     mr_ = new MessageRouter();
    67     mr_.setSiteHome(site_home);
    68     mr_.configure();
     57    mr = new MessageRouter();
     58    mr.setSiteName(this.site_name);
     59    mr.configure();
    6960    }
    7061   
    71    
    72     /** Process a String request */
    73 //     public String process(String xml_in) {
    74 //  return mr_.process(xml_in);
     62    public Element [] process (Element [] xml_in) {
    7563   
    76 //     }
    77 
    78 //     /** Process an Element request  */
    79 //     public Element process(Element xml_in) {
    80 //  return mr_.process(xml_in);
    81 //     }
    82 
    83     public Element [] process (Element [] xml_in) {
    8464    Element [] result = new Element[xml_in.length];
    8565    for (int i=0; i<xml_in.length; i++) {
     
    8868        String tag_name = req.getTagName();
    8969        String namespace="";
    90         Element new_req = req;
    9170        if (tag_name.indexOf(':')!= -1) {
    9271        namespace = tag_name.substring(0, tag_name.indexOf(':'));
    93         tag_name = tag_name.substring(tag_name.indexOf(':')+1);
    94         new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true);
     72        tag_name = tag_name.substring(tag_name.indexOf(':')+1);
    9573        }
    96         Element r = mr_.process(new_req);
     74        Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true);
     75        Element r = mr.process(new_req);
    9776        // add the namespace back on
    9877        //Element new_res = r;
    9978        //if (!namespace.equals("")) {
    10079        //  new_res = GSXML.duplicateWithNewName(r.getOwnerDocument(), r, namespace+r.getTagName(), true);
    101         //}
     80        //}
    10281        result[i] = r;
    10382    }
    10483    return result;
    105     }
    106 
    107     private String readInFile(URL url) {
    108     String file_name = url.getFile();
    109     // any spaces are encoded as %20
    110     file_name = file_name.replaceAll("%20", " ");
    111     try {
    112         BufferedReader reader = new BufferedReader(new FileReader(file_name));
    113         String line = reader.readLine();
    114         line = line.trim();
    115         return line;
    116     } catch (Exception e) {
    117         System.err.println("Exception occurred when reading in the file "+file_name+": "+e);
    118     }
    119     return null;
    120     }
    121 
     84    }   
    12285}
    12386
Note: See TracChangeset for help on using the changeset viewer.