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 du...@apache.org on 2001/05/22 20:03:41 UTC

cvs commit: xml-soap/java/src/org/apache/soap/transport TransportMessage.java

duftler     01/05/22 11:03:38

  Modified:    java/src/org/apache/soap Constants.java
               java/src/org/apache/soap/server/http
                        MessageRouterServlet.java RPCRouterServlet.java
               java/src/org/apache/soap/transport TransportMessage.java
  Log:
  Cleaned up handling of servlet init-parameters.
  Removed transport hook system property dependency.
  
  Submitted by: Matthew J. Duftler, William Nagy
  
  Revision  Changes    Path
  1.20      +6 -5      xml-soap/java/src/org/apache/soap/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Constants.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Constants.java	2001/05/21 01:22:32	1.19
  +++ Constants.java	2001/05/22 18:02:59	1.20
  @@ -198,16 +198,17 @@
         Constants.NS_URI_SOAP_ENV +
         "' namespace.";
   
  -  // Transport hook extension
  -  public static final String TRANSPORT_HOOK_EXTENSION =
  -      "org.apache.soap.TransportHookExtension";
  -
     // Well-defined names for the 'bag' in SOAPContext
     public static String BAG_HTTPSERVLET = "HttpServlet" ;
     public static String BAG_HTTPSESSION = "HttpSession" ;
     public static String BAG_HTTPSERVLETREQUEST = "HttpServletRequest" ;
     public static String BAG_HTTPSERVLETRESPONSE = "HttpServletResponse" ;
  -  
  +
  +  // Servlet init-parameter names.
  +  public static final String ENVELOPE_EDITOR_FACTORY = "EnvelopeEditorFactory";
  +  public static final String XML_PARSER = "XMLParser";
  +  public static final String CONFIGFILENAME = "ConfigFile";
  +
     //////////////////////////////////////////////////////
     // Type QNames for the various schemas
     public static final QName string1999QName =
  
  
  
  1.26      +85 -69    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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- MessageRouterServlet.java	2001/05/19 05:41:51	1.25
  +++ MessageRouterServlet.java	2001/05/22 18:03:12	1.26
  @@ -75,96 +75,112 @@
   /**
    * This servlet routes messages to the appropriate listener method.
    *
  - * @author Sanjiva Weerawarana <sa...@watson.ibm.com>
  + * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
  + * @author Matthew J. Duftler (duftler@us.ibm.com)
    */
   public class MessageRouterServlet extends HttpServlet {
  -  // 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
  -  // the following description to web.xml with Tomcat.
  -  // <servlet>
  -  //  <servlet-name>MessageRouterServlet</servlet-name>
  -  //    <servlet-class>org.apache.soap.server.http.MessageRouterServlet</servlet-class>
  -  //    <init-param>
  -  //      <param-name>EnvelopeEditor</param-name>
  -  //      <param-value>MyEnvelopeEditorFactory</param-value>
  -  //    </init-param>
  -  //    <init-param>
  -  //      <param-name>XMLParser</param-name>
  -  //      <param-value>SampleXMLDocumentBuilderFactory</param-value>
  -  //    </init-param>
  -  // </servlet>
  -  private static final String ENVELOPE_EDITOR_FACTORY =
  -    "EnvelopeEditorFactory";
  -  private static final String XML_PARSER = "XMLParser";
  -
  -  private static final String TRANSPORT_HOOK_EXTENSION =
  -    "org.apache.soap.TransportHookExtension" ;
  -  private static final String CONFIGFILENAME = "ConfigFile";
  -
  -  private String configFilename = null;
  +  /*
  +    EnvelopeEditorFactory, XMLParser, and ConfigFile are
  +    all server-side parameters which can be set using Servlet
  +    init-parameters. For example, you may add the following
  +    description to web.xml when using Tomcat:
  +
  +    <servlet>
  +      <servlet-name>MessageRouterServlet</servlet-name>
  +      <servlet-class>org.apache.soap.server.http.MessageRouterServlet</servlet-class>
  +      <init-param>
  +        <param-name>EnvelopeEditorFactory</param-name>
  +        <param-value>MyEnvelopeEditorFactory</param-value>
  +      </init-param>
  +      <init-param>
  +        <param-name>XMLParser</param-name>
  +        <param-value>SampleXMLDocumentBuilderFactory</param-value>
  +      </init-param>
  +      <init-param>
  +        <param-name>ConfigFile</param-name>
  +        <param-value>myconfig.xml</param-value>
  +      </init-param>
  +    </servlet>
  +  */
     private EnvelopeEditor editor = null;
  +  private String configFilename = null;
   
     public void init() throws ServletException {
  -    if (System.getProperty(TRANSPORT_HOOK_EXTENSION) != null) {
  +    ClassLoader servletClassLoader = getClass().getClassLoader();
  +    ServletConfig servletConfig = getServletConfig();
  +    ServletContext servletContext = servletConfig.getServletContext();
  +    String envelopeEditorFactoryClassName =
  +      servletConfig.getInitParameter(Constants.ENVELOPE_EDITOR_FACTORY);
  +
  +    // Is there an envelope editory factory?
  +    if (envelopeEditorFactoryClassName != 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));
  +        (EnvelopeEditorFactory)createObject(envelopeEditorFactoryClassName,
  +                                            servletClassLoader);
  +
  +      if (factory != null) {
  +        try {
  +          Properties props = new Properties();
  +          Enumeration enum = servletConfig.getInitParameterNames();
  +
  +          while (enum.hasMoreElements()) {
  +            String name = (String)enum.nextElement();
  +
  +            if (!Constants.ENVELOPE_EDITOR_FACTORY.equals(name)
  +                && !Constants.XML_PARSER.equals(name)) {
  +              props.put(name, servletConfig.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);
  +          // Put the real path into the properties, if it can be found.
  +          String servletContextPath = servletContext.getRealPath("");
  +
  +          if (servletContextPath != null) {
  +            props.put("SOAPServerContextPath", servletContextPath);
             }
  +
  +          // Create an editor by calling the factory.
  +          editor = factory.create(props);
  +        } catch (SOAPException e) {
  +          throw new ServletException("Can't create editor", e);
           }
  +      }
       }
  -    Enumeration enum = getServletConfig().getInitParameterNames();
  -    while(enum.hasMoreElements()) {
  -      String name = (String)enum.nextElement();
  -      String value = getServletConfig().getInitParameter(name);
  -      if (CONFIGFILENAME.equals(name))
  -        configFilename = value;
  -      else if (XML_PARSER.equals(name))
  -        XMLParserUtils.refreshDocumentBuilderFactory(value,
  -                                                     true,   // namespaceAware
  -                                                     false); // validating
  +
  +    String tempStr = servletConfig.getInitParameter(Constants.CONFIGFILENAME);
  +
  +    // Is there a user-specified config filename?
  +    if (tempStr != null) {
  +      configFilename = tempStr;
       }
   
  -    ServerHTTPUtils.setServletClassLoaderIntoContext(getServletConfig().getServletContext(), this.getClass().getClassLoader());
  +    tempStr = servletConfig.getInitParameter(Constants.XML_PARSER);
  +
  +    // Is there a user-specified JAXP implementation?
  +    if (tempStr != null) {
  +      XMLParserUtils.refreshDocumentBuilderFactory(tempStr,
  +                                                   true,  // namespaceAware
  +                                                   false);// validating
  +    }
  +
  +    ServerHTTPUtils.setServletClassLoaderIntoContext(servletContext,
  +                                                     servletClassLoader);
     }
   
  -  private Object createObject(String name)
  +  private Object createObject(String className, ClassLoader classLoader)
       throws ServletException
     {
  -    String value;
  -    if ((value = getServletConfig().getInitParameter(name)) == null) {
  -      throw new ServletException(getClass().getName() +
  -                                 " cannot get init parameter '" +
  -                                 name + "'.");
  -    }
  -
       try {
  -      return this.getClass().getClassLoader().loadClass(value).newInstance();
  +      return classLoader.loadClass(className).newInstance();
       } catch (ClassNotFoundException e) {
  -      throw new ServletException("Can't find class named '" + value + "'");
  +      throw new ServletException("Can't find class named '" + className +
  +                                 "'.");
       } catch (InstantiationException e) {
  -      throw new ServletException("Can't instantiate class '" + value + "'");
  +      throw new ServletException("Can't instantiate class '" + className +
  +                                 "'.");
       } catch (IllegalAccessException e) {
  -      throw new ServletException("WARNING: Can't access the constructor of the class '" + value + "'");
  +      throw new ServletException("WARNING: Can't access the constructor " +
  +                                 "of the class '" + className + "'.");
       }
     }
   
  
  
  
  1.30      +87 -69    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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- RPCRouterServlet.java	2001/05/19 05:41:51	1.29
  +++ RPCRouterServlet.java	2001/05/22 18:03:16	1.30
  @@ -78,98 +78,116 @@
    * This servlet routes RPC requests to the intended method of
    * the intended object.
    *
  - * @author Sanjiva Weerawarana <sa...@watson.ibm.com>
  - * @author Matthew J. Duftler <du...@us.ibm.com>
  - * @author Steven McDowall <sj...@aptest.com>
  + * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
  + * @author Matthew J. Duftler (duftler@us.ibm.com)
  + * @author Steven McDowall (sjm@aptest.com)
    * @author Eric M. Dashofy (edashofy@ics.uci.edu)
    * @author Kevin J. Mitchell (kevin.mitchell@xmls.com)
    * @author Wouter Cloetens (wcloeten@raleigh.ibm.com)
    */
   public class RPCRouterServlet extends HttpServlet {
  -  // 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
  -  // the following description to web.xml with Tomcat.
  -  // <servlet>
  -  //  <servlet-name>MessageRouterServlet</servlet-name>
  -  //    <servlet-class>org.apache.soap.server.http.MessageRouterServlet</servlet-class>
  -  //    <init-param>
  -  //      <param-name>EnvelopeEditor</param-name>
  -  //      <param-value>MyEnvelopeEditorFactory</param-value>
  -  //    </init-param>
  -  //    <init-param>
  -  //      <param-name>XMLParser</param-name>
  -  //      <param-value>SampleXMLDocumentBuilderFactory</param-value>
  -  //    </init-param>
  -  // </servlet>
  -  private static final String ENVELOPE_EDITOR_FACTORY =
  -      "EnvelopeEditorFactory";
  -  private static final String XML_PARSER = "XMLParser";
  -  private static final String CONFIGFILENAME = "ConfigFile";
  -
  +  /*
  +    EnvelopeEditorFactory, XMLParser, and ConfigFile are
  +    all server-side parameters which can be set using Servlet
  +    init-parameters. For example, you may add the following
  +    description to web.xml when using Tomcat:
  +
  +    <servlet>
  +      <servlet-name>RPCRouterServlet</servlet-name>
  +      <servlet-class>org.apache.soap.server.http.RPCRouterServlet</servlet-class>
  +      <init-param>
  +        <param-name>EnvelopeEditorFactory</param-name>
  +        <param-value>MyEnvelopeEditorFactory</param-value>
  +      </init-param>
  +      <init-param>
  +        <param-name>XMLParser</param-name>
  +        <param-value>SampleXMLDocumentBuilderFactory</param-value>
  +      </init-param>
  +      <init-param>
  +        <param-name>ConfigFile</param-name>
  +        <param-value>myconfig.xml</param-value>
  +      </init-param>
  +    </servlet>
  +  */
     private EnvelopeEditor editor = null;
     private String configFilename = null;
   
     public void init() throws ServletException {
  -      if (System.getProperty(Constants.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));
  +    ClassLoader servletClassLoader = getClass().getClassLoader();
  +    ServletConfig servletConfig = getServletConfig();
  +    ServletContext servletContext = servletConfig.getServletContext();
  +    String envelopeEditorFactoryClassName =
  +      servletConfig.getInitParameter(Constants.ENVELOPE_EDITOR_FACTORY);
  +
  +    // Is there an envelope editory factory?
  +    if (envelopeEditorFactoryClassName != null) {
  +      EnvelopeEditorFactory factory =
  +        (EnvelopeEditorFactory)createObject(envelopeEditorFactoryClassName,
  +                                            servletClassLoader);
  +
  +      if (factory != null) {
  +        try {
  +          Properties props = new Properties();
  +          Enumeration enum = servletConfig.getInitParameterNames();
  +
  +          while (enum.hasMoreElements()) {
  +            String name = (String)enum.nextElement();
  +
  +            if (!Constants.ENVELOPE_EDITOR_FACTORY.equals(name)
  +                && !Constants.XML_PARSER.equals(name)) {
  +              props.put(name, servletConfig.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);
  +          // Put the real path into the properties, if it can be found.
  +          String servletContextPath = servletContext.getRealPath("");
  +
  +          if (servletContextPath != null) {
  +            props.put("SOAPServerContextPath", servletContextPath);
             }
  +
  +          // Create an editor by calling the factory.
  +          editor = factory.create(props);
  +        } catch (SOAPException e) {
  +          throw new ServletException("Can't create editor", e);
           }
         }
  -      Enumeration enum = getServletConfig().getInitParameterNames();
  -      while(enum.hasMoreElements()) {
  -        String name = (String)enum.nextElement();
  -        String value = getServletConfig().getInitParameter(name);
  -        if (CONFIGFILENAME.equals(name))
  -          configFilename = value;
  -        else if (XML_PARSER.equals(name))
  -          XMLParserUtils.refreshDocumentBuilderFactory(value,
  -                                                       true,  // namespaceAware
  -                                                       false);// validating
  -      }
  +    }
  +
  +    String tempStr = servletConfig.getInitParameter(Constants.CONFIGFILENAME);
   
  -      ServerHTTPUtils.setServletClassLoaderIntoContext(getServletConfig().getServletContext(), this.getClass().getClassLoader());
  +    // Is there a user-specified config filename?
  +    if (tempStr != null) {
  +      configFilename = tempStr;
  +    }
  +
  +    tempStr = servletConfig.getInitParameter(Constants.XML_PARSER);
  +
  +    // Is there a user-specified JAXP implementation?
  +    if (tempStr != null) {
  +      XMLParserUtils.refreshDocumentBuilderFactory(tempStr,
  +                                                   true,  // namespaceAware
  +                                                   false);// validating
  +    }
  +
  +    ServerHTTPUtils.setServletClassLoaderIntoContext(servletContext,
  +                                                     servletClassLoader);
     }
   
  -  private Object createObject(String name)
  +  private Object createObject(String className, ClassLoader classLoader)
       throws ServletException
     {
  -    String value;
  -    if ((value = getServletConfig().getInitParameter(name)) == null) {
  -      throw new ServletException(getClass().getName() +
  -                                 " cannot get init parameter '" +
  -                                 name + "'.");
  -    }
  -
       try {
  -      return this.getClass().getClassLoader().loadClass(value).newInstance();
  +      return classLoader.loadClass(className).newInstance();
       } catch (ClassNotFoundException e) {
  -      throw new ServletException("Can't find class named '" + value + "'");
  +      throw new ServletException("Can't find class named '" + className +
  +                                 "'.");
       } catch (InstantiationException e) {
  -      throw new ServletException("Can't instantiate class '" + value + "'");
  +      throw new ServletException("Can't instantiate class '" + className +
  +                                 "'.");
       } catch (IllegalAccessException e) {
  -      throw new ServletException("WARNING: Can't access the constructor of the class '" + value + "'");
  +      throw new ServletException("WARNING: Can't access the constructor " +
  +                                 "of the class '" + className + "'.");
       }
     }
   
  
  
  
  1.12      +1 -3      xml-soap/java/src/org/apache/soap/transport/TransportMessage.java
  
  Index: TransportMessage.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/transport/TransportMessage.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TransportMessage.java	2001/03/23 07:46:36	1.11
  +++ TransportMessage.java	2001/05/22 18:03:30	1.12
  @@ -173,9 +173,7 @@
        */
       protected void editEnvelope(EnvelopeEditor editor, boolean isIncoming)
           throws SOAPException, IOException, MessagingException {
  -        String opt = System.getProperty(Constants.TRANSPORT_HOOK_EXTENSION);
  -
  -        if (opt != null && editor != null) {
  +        if (editor != null) {
               // Do nothing if the root part is not text.
               if (getEnvelope() == null)
                   return;