You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by ne...@apache.org on 2001/03/07 02:58:23 UTC

cvs commit: xml-soap/java/src/org/apache/soap/server/http MessageRouterServlet.java RPCRouterServlet.java

neyama      01/03/06 17:58:23

  Modified:    java/src/org/apache/soap/server/http
                        MessageRouterServlet.java RPCRouterServlet.java
  Log:
  Modified {RPC,Message}RouterServlet.java to improve the robustness and
  usability.
  
  The detail of the change is as follows:
  
  1. Servlet#init() throws ServletException if an error occurs in
  creating an EnvelopeEditor. So far, even if an error occurs, the
  servlet was instantiated successfully.  It was not reasonable and
  helpful, because all requests will fail in that case.
  
  2. Puts the value of ServletContext#getRealPath("") into the
  properties so that EnvelopeEditors can know what is the application
  path.
  
  Revision  Changes    Path
  1.20      +28 -22    xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java
  
  Index: MessageRouterServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- MessageRouterServlet.java	2001/02/22 06:01:37	1.19
  +++ MessageRouterServlet.java	2001/03/07 01:58:18	1.20
  @@ -104,27 +104,32 @@
     private String configFilename = null;
     private EnvelopeEditor editor = null;
     private XMLParserLiaison xpl = new XercesParserLiaison();
  -  public void init() {
  +  public void init() throws ServletException {
       if (System.getProperty(TRANSPORT_HOOK_EXTENSION) != null) {
         EnvelopeEditorFactory factory =
           (EnvelopeEditorFactory)createObject(ENVELOPE_EDITOR_FACTORY);
  -      if (factory != null) {
  -        try {
  -          Properties props = new Properties();
  -          Enumeration enum = getServletConfig().getInitParameterNames();
  -          while(enum.hasMoreElements()) {
  -            String name = (String)enum.nextElement();
  -            if (!ENVELOPE_EDITOR_FACTORY.equals(name) &&
  -                !XML_PARSER.equals(name))
  -              props.put(name,
  -                        getServletConfig().getInitParameter(name));
  +        if (factory != null) {
  +          try {
  +            Properties props = new Properties();
  +            Enumeration enum = getServletConfig().getInitParameterNames();
  +            while(enum.hasMoreElements()) {
  +              String name = (String)enum.nextElement();
  +              if (!ENVELOPE_EDITOR_FACTORY.equals(name) &&
  +                  !XML_PARSER.equals(name))
  +                props.put(name, getServletConfig().getInitParameter(name));
  +            }
  +
  +            // Puts the real path into the properties
  +            String servletContextPath;
  +            if ((servletContextPath = getServletContext().getRealPath("")) != null)
  +                props.put("SOAPServerContextPath", servletContextPath);
  +
  +            // Creates an editor by calling the factory
  +            editor = factory.create(props);
  +          } catch (SOAPException e) {
  +              throw new ServletException("Can't create editor", e);
             }
  -          editor = factory.create(props);
  -        } catch (SOAPException e) {
  -          System.err.println("WARNING: Can't create editor: " +
  -                             e.getMessage());
           }
  -      }
         if ((xpl = (XMLParserLiaison)createObject(XML_PARSER)) == null)
           xpl = new XercesParserLiaison();
       }
  @@ -139,7 +144,9 @@
       ServerHTTPUtils.setServletClassLoaderIntoContext(getServletConfig().getServletContext(), this.getClass().getClassLoader());
     }
   
  -  private Object createObject(String name) {
  +  private Object createObject(String name)
  +    throws ServletException
  +  {
       String value;
       if ((value = getServletConfig().getInitParameter(name)) == null) {
         System.err.println(getClass().getName() +
  @@ -147,17 +154,16 @@
         return null;
       }
       System.err.println(getClass().getName() +
  -                       " god a init parameter '" + name + "'=" + value);
  +                       " got a init parameter '" + name + "'=" + value);
       try {
         return Class.forName(value).newInstance();
       } catch (ClassNotFoundException e) {
  -      System.err.println("WARNING: Can't find class named '" + value + "'");
  +      throw new ServletException("Can't find class named '" + value + "'");
       } catch (InstantiationException e) {
  -      System.err.println("WARNING: Can't instantiate class '" + value + "'");
  +      throw new ServletException("Can't instantiate class '" + value + "'");
       } catch (IllegalAccessException e) {
  -      System.err.println("WARNING: Can't access constructor of class '" + value + "'");
  +      throw new ServletException("WARNING: Can't access the constructor of the class '" + value + "'");
       }
  -    return null;
     }
   
     public void doGet (HttpServletRequest req, HttpServletResponse res)
  
  
  
  1.24      +17 -24    xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java
  
  Index: RPCRouterServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- RPCRouterServlet.java	2001/02/22 06:01:38	1.23
  +++ RPCRouterServlet.java	2001/03/07 01:58:19	1.24
  @@ -70,16 +70,9 @@
   import org.apache.soap.transport.*;
   import org.apache.soap.util.* ;
   import org.apache.soap.util.xml.* ;
  +import org.apache.soap.transport.EnvelopeEditor;
  +import org.apache.soap.transport.EnvelopeEditorFactory;
   
  -/*
  - * Begin Transport-Hook-Extension
  - */
  -import org.apache.soap.transport.EnvelopeEditor ;
  -import org.apache.soap.transport.EnvelopeEditorFactory ;
  -/*
  - * End Transport-Hook-Extension
  - */
  -
   /**
    * This servlet routes RPC requests to the intended method of
    * the intended object.
  @@ -92,9 +85,6 @@
    * @author Wouter Cloetens (wcloeten@raleigh.ibm.com)
    */
   public class RPCRouterServlet extends HttpServlet {
  -  /*
  -   * Begin Transport-Hook-Extension
  -   */
     // Unlike client-side, EnvelopeEditorFactory, which creates an
     // EnvelopeEditor, and XMLParser are specified by servlet
     // init-parameters at the server-side.  For example, you may add
  @@ -120,7 +110,7 @@
     private XMLParserLiaison xpl = new XercesParserLiaison();
     private String configFilename = null;
   
  -  public void init() {
  +  public void init() throws ServletException {
         if (System.getProperty(Constants.TRANSPORT_HOOK_EXTENSION) != null) {
           EnvelopeEditorFactory factory =
             (EnvelopeEditorFactory)createObject(ENVELOPE_EDITOR_FACTORY);
  @@ -134,10 +124,16 @@
                     !XML_PARSER.equals(name))
                   props.put(name, getServletConfig().getInitParameter(name));
               }
  +
  +            // Puts the real path into the properties
  +            String servletContextPath;
  +            if ((servletContextPath = getServletContext().getRealPath("")) != null)
  +                props.put("SOAPServerContextPath", servletContextPath);
  +
  +            // Creates an editor by calling the factory
               editor = factory.create(props);
             } catch (SOAPException e) {
  -            System.err.println("WARNING: Can't create editor: " +
  -                               e.getMessage());
  +              throw new ServletException("Can't create editor", e);
             }
           }
           if ((xpl = (XMLParserLiaison)createObject(XML_PARSER)) == null)
  @@ -154,7 +150,9 @@
         ServerHTTPUtils.setServletClassLoaderIntoContext(getServletConfig().getServletContext(), this.getClass().getClassLoader());
     }
   
  -  private Object createObject(String name) {
  +  private Object createObject(String name)
  +    throws ServletException
  +  {
       String value;
       if ((value = getServletConfig().getInitParameter(name)) == null) {
         System.err.println(getClass().getName() +
  @@ -166,18 +164,13 @@
       try {
         return Class.forName(value).newInstance();
       } catch (ClassNotFoundException e) {
  -      System.err.println("WARNING: Can't find class named '" + value + "'");
  +      throw new ServletException("Can't find class named '" + value + "'");
       } catch (InstantiationException e) {
  -      System.err.println("WARNING: Can't instantiate class '" + value + "'");
  +      throw new ServletException("Can't instantiate class '" + value + "'");
       } catch (IllegalAccessException e) {
  -      System.err.println("WARNING: Can't access constructor of class '" +
  -                         value + "'");
  +      throw new ServletException("WARNING: Can't access the constructor of the class '" + value + "'");
       }
  -    return null;
     }
  -  /*
  -   * End Transport-Hook-Extension
  -   */
   
     public void doGet (HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException {