You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Tom Jordahl <to...@macromedia.com> on 2003/08/11 16:40:11 UTC

RE: cvs commit: xml-axis/java/src/org/apache/axis/transport/http AxisServlet.java

+1
Thanks Dug!

--
Tom Jordahl
Macromedia Server Development

-----Original Message-----
From: dug@apache.org [mailto:dug@apache.org] 
Sent: Monday, August 11, 2003 10:20 AM
To: xml-axis-cvs@apache.org
Subject: cvs commit: xml-axis/java/src/org/apache/axis/transport/http AxisServlet.java

dug         2003/08/11 07:20:23

  Modified:    java/docs reference.html
               java/src/org/apache/axis/transport/http AxisServlet.java
  Log:
  Use qs. instead of qs:
  Add default for query strings
  Add a compat. flag
  and of course docs
  Submitted by:  Curtiss Howard - cjhoward@us.ibm.com
  
  Revision  Changes    Path
  1.30      +8 -4      xml-axis/java/docs/reference.html
  
  Index: reference.html
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/docs/reference.html,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- reference.html	9 Aug 2003 12:54:39 -0000	1.29
  +++ reference.html	11 Aug 2003 14:20:23 -0000	1.30
  @@ -520,7 +520,7 @@
       <b>&lt;service&gt;</b> element above). Typically handlers in the transport 
       request/response flows implement transport-specific functionality, such as 
       parsing protocol headers, etc.</dd><br><br>
  -  <dd>For HTTP transports, users may allow Axis servlets to perform arbitrary actions 
  +  <dd>For any kind of transport (though usually this relates to HTTP transports), users may allow Axis servlets to perform arbitrary actions 
       (by means of a &quot;plug-in&quot;) when specific query strings are passed to the servlet (see the section 
       <a href="developers-guide.html#Axis Servlet Query String Plug-ins">Axis Servlet Query String Plug-ins</a> 
       in the <a href="developers-guide.html">Axis Developer's Guide</a> for more information on what this means 
  @@ -529,16 +529,20 @@
       <b>&lt;transport&gt;</b> element.  An example configuration might look like the following:<br><br>
       <code>
       &lt;transport name=&quot;http&quot;&gt;<br>
  -    &nbsp;&nbsp;&lt;parameter name=&quot;qs:name&quot; value=&quot;class.name&quot; /&gt;<br>
  +    &nbsp;&nbsp;&lt;parameter name=&quot;useDefaultQueryStrings&quot; value=&quot;false&quot; /&gt;<br>
  +    &nbsp;&nbsp;&lt;parameter name=&quot;qs.name&quot; value=&quot;class.name&quot; /&gt;<br>
       &lt;/transport&gt;<br>
       </code><br>
       In this example, the query string that the Axis servlet should respond to is <i>?name</i> and the class 
       that it should invoke when this query string is encountered is named <code>class.name</code>.  The 
  -    <code>name</code> attribute of the <b>&lt;parameter&gt;</b> element must start with the string &quot;qs:&quot; 
  +    <code>name</code> attribute of the <b>&lt;parameter&gt;</b> element must start with the string &quot;qs.&quot; 
       to indicate that this <b>&lt;parameter&gt;</b> element defines a query string handler.  The <code>value</code> 
       attribute must point to the name of a class implementing the <code>org.apache.axis.transport.http.QSHandler</code> 
       interface.  By default, Axis provides for three Axis servlet query string handlers (<i>?list</i>, <i>?method</i>, 
  -    and <i>?wsdl</i>).  See the Axis server configuration file for their definitions.</dd>
  +    and <i>?wsdl</i>).  See the Axis server configuration file for their definitions.  If the user wishes not to use
  +    these default query string handlers (as in the example), a <b>&lt;parameter&gt;</b> element with a <code>name</code>
  +    attribute equal to &quot;useDefaultQueryStrings&quot; should have its <code>value</code> attribute set to <code>false</code>.
  +    By default it is set to <code>true</code> and the element is not necessary if the user wishes to have this default behavior.
     <dt>&nbsp;</dt>
     <dt><b><font face="Courier New, Courier, mono">&lt;transport name=&quot;</font></b><font face="Courier New, Courier, mono"><i>name</i></font><b><font face="Courier New, Courier, mono">&quot; 
       pivot=&quot;</font></b><font face="Courier New, Courier, mono"><i>handler 
  
  
  
  1.165     +73 -6     xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java
  
  Index: AxisServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java,v
  retrieving revision 1.164
  retrieving revision 1.165
  diff -u -r1.164 -r1.165
  --- AxisServlet.java	7 Aug 2003 00:12:45 -0000	1.164
  +++ AxisServlet.java	11 Aug 2003 14:20:23 -0000	1.165
  @@ -62,6 +62,7 @@
   import org.apache.axis.Handler;
   import org.apache.axis.Message;
   import org.apache.axis.MessageContext;
  +import org.apache.axis.SimpleTargetedChain;
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.axis.description.OperationDesc;
   import org.apache.axis.description.ServiceDesc;
  @@ -131,7 +132,9 @@
   
       // These have default values.
       private String transportName;
  -
  +    
  +    private Handler transport;
  +    
       private ServletSecurityProvider securityProvider = null;
   
       /**
  @@ -201,6 +204,8 @@
           } else {
               jwsClassDir = getDefaultJWSClassDir();
           }
  +        
  +        initQueryStringHandlers();
       }
   
   
  @@ -962,6 +967,62 @@
       }
       
       /**
  +     * Initialize a Handler for the transport defined in the Axis server config.
  +     * This includes optionally filling in query string handlers.
  +     */
  +    
  +    public void initQueryStringHandlers () {
  +          try {
  +               this.transport = getEngine().getTransport (this.transportName);
  +               
  +               if (this.transport == null) {
  +                    // No transport by this name is defined.  Therefore, fill in default
  +                    // query string handlers.
  +                    
  +                    this.transport = new SimpleTargetedChain();
  +                    
  +                    this.transport.setOption ("qs.list", "org.apache.axis.transport.http.QSListHandler");
  +                    this.transport.setOption ("qs.method", "org.apache.axis.transport.http.QSMethodHandler");
  +                    this.transport.setOption ("qs.wsdl", "org.apache.axis.transport.http.QSWSDLHandler");
  +                    
  +                    return;
  +               }
  +               
  +               else {
  +                    // See if we should use the default query string handlers.
  +                    // By default, set this to true (for backwards compatibility).
  +                    
  +                    boolean defaultQueryStrings = true;
  +                    String useDefaults = (String) this.transport.getOption ("useDefaultQueryStrings");
  +                    
  +                    if ((useDefaults != null) && useDefaults.toLowerCase().equals ("false")) {
  +                         defaultQueryStrings = false;
  +                    }
  +                    
  +                    if (defaultQueryStrings == true) {
  +                         // We should use defaults, so fill them in.
  +                         
  +                         this.transport.setOption ("qs.list", "org.apache.axis.transport.http.QSListHandler");
  +                         this.transport.setOption ("qs.method", "org.apache.axis.transport.http.QSMethodHandler");
  +                         this.transport.setOption ("qs.wsdl", "org.apache.axis.transport.http.QSWSDLHandler");
  +                    }
  +               }
  +          }
  +          
  +          catch (AxisFault e) {
  +               // Some sort of problem occurred, let's just make a default transport.
  +               
  +               this.transport = new SimpleTargetedChain();
  +               
  +               this.transport.setOption ("qs.list", "org.apache.axis.transport.http.QSListHandler");
  +               this.transport.setOption ("qs.method", "org.apache.axis.transport.http.QSMethodHandler");
  +               this.transport.setOption ("qs.wsdl", "org.apache.axis.transport.http.QSWSDLHandler");
  +               
  +               return;
  +          }
  +    }
  +    
  +    /**
        * Attempts to invoke a plugin for the query string supplied in the URL.
        *
        * @param request the servlet's HttpServletRequest object.
  @@ -978,8 +1039,7 @@
             String queryString = request.getQueryString();
             String serviceName;
             AxisEngine engine = getEngine();
  -          Handler httpTransport = engine.getTransport ("http");
  -          Iterator i = httpTransport.getOptions().keySet().iterator();
  +          Iterator i = this.transport.getOptions().keySet().iterator();
             
             if (queryString == null) {
                  return false;
  @@ -991,12 +1051,12 @@
             while (i.hasNext() == true) {
                  String queryHandler = (String) i.next();
                  
  -               if (queryHandler.startsWith ("qs:") == true) {
  +               if (queryHandler.startsWith ("qs.") == true) {
                       // Only attempt to match the query string with transport
                       // parameters prefixed with "qs:".
                       
                       String handlerName = queryHandler.substring
  -                         (queryHandler.indexOf (":") + 1).toLowerCase();
  +                         (queryHandler.indexOf (".") + 1).toLowerCase();
                       
                       // Determine the name of the plugin to invoke by using all text
                       // in the query string up to the first occurence of &, =, or the
  @@ -1022,12 +1082,19 @@
                       if (queryString.toLowerCase().equals (handlerName) == true) {
                            // Query string matches a defined query string handler name.
                            
  +                         // If the defined class name for this query string handler is blank,
  +                         // just return (the handler is "turned off" in effect).
  +                         
  +                         if (((String) this.transport.getOption (queryHandler)).equals ("")) {
  +                              return false;
  +                         }
  +                         
                            try {
                                 // Attempt to dynamically load the query string handler
                                 // and its "invoke" method.
                                 
                                 MessageContext msgContext = createMessageContext (engine, request, response);
  -                              Class plugin = Class.forName ((String) httpTransport.getOption (queryHandler));
  +                              Class plugin = Class.forName ((String) this.transport.getOption (queryHandler));
                                 Method pluginMethod = plugin.getDeclaredMethod ("invoke",
                                   new Class[] { msgContext.getClass() });
                                 String url = HttpUtils.getRequestURL (request).toString();