Changeset 11023 for trunk/gsdl3


Ignore:
Timestamp:
2005-12-22T13:28:31+13:00 (18 years ago)
Author:
kjdon
Message:

servlet init params - can now have remote_site_name, remote_site_type, remote_site_address instead of site_name, and a communicator will be set up instead of a message router

File:
1 edited

Legend:

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

    r10297 r11023  
    11package org.greenstone.gsdl3;
    22
     3import org.greenstone.gsdl3.comms.*;
    34import org.greenstone.gsdl3.core.*;
    45import org.greenstone.gsdl3.util.*;
     
    4041    /** the cgi stuff - the Receptionist can add new args to this
    4142     * its used by the servlet to determine what args to save */
    42     //protected GSCGI cgi = null;
    4343    protected GSParams params = null;
    4444
     
    5757    String library_name = config.getInitParameter(GSConstants.LIBRARY_NAME);
    5858    String gsdl3_home = config.getInitParameter(GSConstants.GSDL3_HOME);
    59     String site_name = config.getInitParameter(GSConstants.SITE_NAME);
    6059    String interface_name = config.getInitParameter(GSConstants.INTERFACE_NAME);
    6160    this.default_lang = config.getInitParameter(GSConstants.DEFAULT_LANG);
    62     if (library_name == null || site_name ==null ||  interface_name ==null) {
     61    if (library_name == null || interface_name ==null) {
    6362        // must have this
    6463        System.err.println("initialisation parameters not all set!");
    65         System.err.println(" you must have libraryname, sitename, interfacename");
     64        System.err.println(" you must have libraryname and interfacename");
    6665        System.exit(1);
    6766    }
    6867
     68    String site_name = config.getInitParameter(GSConstants.SITE_NAME);
     69    String remote_site_name = null;
     70    String remote_site_type = null;
     71    String remote_site_address = null;
     72   
     73    if (site_name == null) {
     74        // no site, try for communicator
     75        remote_site_name = config.getInitParameter("remote_site_name");
     76        remote_site_type = config.getInitParameter("remote_site_type");
     77        remote_site_address = config.getInitParameter("remote_site_address");
     78        if (remote_site_name == null || remote_site_type == null || remote_site_address == null) {
     79        System.err.println("initialisation paramters not all set!");
     80        System.err.println("if site_name is not set, then you must have remote_site_name, remote_site_type and remote_site_address set");
     81        System.exit(1);
     82        }
     83    }
     84   
    6985    if (this.default_lang == null) {
    7086        // choose english
     
    7591   
    7692    config_params.put(GSConstants.LIBRARY_NAME, library_name);
    77     config_params.put(GSConstants.SITE_NAME, site_name);
    7893    config_params.put(GSConstants.INTERFACE_NAME, interface_name);
    79    
     94    if (site_name != null) {
     95        config_params.put(GSConstants.SITE_NAME, site_name);
     96    }
    8097    this.converter = new XMLConverter();
    8198    this.doc = this.converter.newDOM();
    82    
    83     // now try and create MR and recpt
    84     // new message router - create it and pass reference to recept.
    85     // the servlet wont use this directly
    86     String mr_name = (String)config.getInitParameter("messagerouter_class");
    87     MessageRouter message_router = null;
    88     if (mr_name == null) { // just use the normal MR
    89         message_router = new MessageRouter();
    90     } else { // try the specified one
    91         try {
    92         message_router = (MessageRouter)Class.forName("org.greenstone.gsdl3.core."+mr_name).newInstance();
    93         } catch (Exception e) { // cant use this new one, so use normal one
    94         System.err.println("LibraryServlet configure exception when trying to use a new MessageRouter "+mr_name+": "+e.getMessage());
    95         e.printStackTrace();
    96         message_router = new MessageRouter();
    97         }   
    98     }
    99    
    100     message_router.setSiteName(site_name);
    101     message_router.configure();
    10299   
    103100    // the receptionist -the servlet will talk to this
     
    115112    }
    116113    this.recept.setConfigParams(config_params);
    117     this.recept.setMessageRouter(message_router);
     114
     115    // the receptionist uses a MessageRouter or Communicator to send its requests to. We either create a MessageRouter here for the designated site (if site_name set), or we create a Communicator for a remote site. The is given to teh Receptionist, and the servlet never talks to it again.directly.
     116    if (site_name != null) {
     117        String mr_name = (String)config.getInitParameter("messagerouter_class");
     118        MessageRouter message_router = null;
     119        if (mr_name == null) { // just use the normal MR
     120        message_router = new MessageRouter();
     121        } else { // try the specified one
     122        try {
     123            message_router = (MessageRouter)Class.forName("org.greenstone.gsdl3.core."+mr_name).newInstance();
     124        } catch (Exception e) { // cant use this new one, so use normal one
     125            System.err.println("LibraryServlet configure exception when trying to use a new MessageRouter "+mr_name+": "+e.getMessage());
     126            e.printStackTrace();
     127            message_router = new MessageRouter();
     128        }   
     129        }
     130       
     131        message_router.setSiteName(site_name);
     132        message_router.configure();
     133        this.recept.setMessageRouter(message_router);
     134    } else {
     135        // talking to a remote site, create a communicator
     136        Communicator communicator = null;
     137        // we need to create the XML to configure the communicator
     138        Element site_elem = this.doc.createElement(GSXML.SITE_ELEM);
     139        site_elem.setAttribute(GSXML.TYPE_ATT, remote_site_type);
     140        site_elem.setAttribute(GSXML.NAME_ATT, remote_site_name);
     141        site_elem.setAttribute(GSXML.ADDRESS_ATT, remote_site_address);
     142
     143        if (remote_site_type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) {
     144        communicator = new SOAPCommunicator();
     145        } else {
     146        System.err.println("LibraryServlet.init Error: invalid Communicator type: "+remote_site_type);
     147        System.exit(1);
     148        }
     149       
     150        if (!communicator.configure(site_elem)) {
     151        System.err.println("LibraryServlet.init Error: Couldn't configure communicator");
     152        System.exit(1);
     153        }
     154        this.recept.setMessageRouter(communicator);
     155    }
     156   
    118157    // the params arg thingy
    119158   
Note: See TracChangeset for help on using the changeset viewer.