stevel      2003/08/15 12:19:32

  Modified:    java/src/org/apache/axis/transport/http QSWSDLHandler.java
                        QSMethodHandler.java QSListHandler.java
                        QSHandler.java
  Added:       java/src/org/apache/axis/transport/http
                        AbstractQueryStringHandler.java
  Log:
  refactored out repeated code from all the new QS handlers, pulled them in to a new 
base class. There is still reptition between here and AxisServlet; the common stuff 
needs to be pulled into a ServletHelper class for all to use. This is just a first 
step.
  
  Revision  Changes    Path
  1.2       +154 -169  
xml-axis/java/src/org/apache/axis/transport/http/QSWSDLHandler.java
  
  Index: QSWSDLHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/transport/http/QSWSDLHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QSWSDLHandler.java        7 Aug 2003 00:12:45 -0000       1.1
  +++ QSWSDLHandler.java        15 Aug 2003 19:19:31 -0000      1.2
  @@ -1,21 +1,72 @@
  -package org.apache.axis.transport.http;
  +/*
  +* The Apache Software License, Version 1.1
  +*
  +*
  +* Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  +* reserved.
  +*
  +* Redistribution and use in source and binary forms, with or without
  +* modification, are permitted provided that the following conditions
  +* are met:
  +*
  +* 1. Redistributions of source code must retain the above copyright
  +*    notice, this list of conditions and the following disclaimer.
  +*
  +* 2. Redistributions in binary form must reproduce the above copyright
  +*    notice, this list of conditions and the following disclaimer in
  +*    the documentation and/or other materials provided with the
  +*    distribution.
  +*
  +* 3. The end-user documentation included with the redistribution,
  +*    if any, must include the following acknowledgment:
  +*       "This product includes software developed by the
  +*        Apache Software Foundation (http://www.apache.org/)."
  +*    Alternately, this acknowledgment may appear in the software itself,
  +*    if and wherever such third-party acknowledgments normally appear.
  +*
  +* 4. The names "Axis" and "Apache Software Foundation" must
  +*    not be used to endorse or promote products derived from this
  +*    software without prior written permission. For written
  +*    permission, please contact [EMAIL PROTECTED]
  +*
  +* 5. Products derived from this software may not be called "Apache",
  +*    nor may "Apache" appear in their name, without prior written
  +*    permission of the Apache Software Foundation.
  +*
  +* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  +* DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  +* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  +* SUCH DAMAGE.
  +* ====================================================================
  +*
  +* This software consists of voluntary contributions made by many
  +* individuals on behalf of the Apache Software Foundation.  For more
  +* information on the Apache Software Foundation, please see
  +* <http://www.apache.org/>.
  +*/
   
  -import java.io.PrintWriter;
  -import java.net.HttpURLConnection;
  -import javax.servlet.http.HttpServletRequest;
  -import javax.servlet.http.HttpServletResponse;
  +package org.apache.axis.transport.http;
   
   import org.apache.axis.AxisFault;
   import org.apache.axis.Constants;
   import org.apache.axis.MessageContext;
   import org.apache.axis.server.AxisServer;
  -import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.utils.Messages;
   import org.apache.axis.utils.XMLUtils;
  -import org.apache.commons.logging.Log;
  -
   import org.w3c.dom.Document;
  -import org.w3c.dom.Element;
  +
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +import java.io.PrintWriter;
  +import java.net.HttpURLConnection;
   
   /**
    * The QSWSDLHandler class is a handler which provides an AXIS service's WSDL
  @@ -27,166 +78,100 @@
    * @author Steve Loughran
    */
   
  -public class QSWSDLHandler implements QSHandler {
  -     private boolean development;
  -     private Log log;
  -     private Log exceptionLog;
  -     
  -     /**
  -      * probe for the system being 'production'
  -      * @return true for a dev system.
  -      */
  -     
  -     private boolean isDevelopment () {
  -          return this.development;
  -     }
  -     
  -     /**
  -      * Performs the action associated with this particular query string
  -      * handler.
  -      *
  -      * @param msgContext a MessageContext object containing message context
  -      *        information for this query string handler.
  -      * @throws AxisFault if an error occurs.
  -      */
  -     
  -     public void invoke (MessageContext msgContext) throws AxisFault {
  -          // Obtain objects relevant to the task at hand from the provided
  -          // MessageContext's bag.
  -          
  -          AxisServer engine = (AxisServer) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_ENGINE);
  -          PrintWriter writer = (PrintWriter) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_WRITER);
  -          HttpServletRequest request = (HttpServletRequest)
  -               msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
  -          HttpServletResponse response = (HttpServletResponse)
  -               msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE);
  -          this.development = ((Boolean) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_IS_DEVELOPMENT)).booleanValue();
  -          this.log = (Log) msgContext.getProperty (HTTPConstants.PLUGIN_LOG);
  -          this.exceptionLog = (Log) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_EXCEPTION_LOG);
  -          
  -          try {
  -               engine.generateWSDL (msgContext);
  -               
  -               Document doc = (Document) msgContext.getProperty ("WSDL");
  -               
  -               if (doc != null) {
  -                    response.setContentType ("text/xml");
  -                    XMLUtils.DocumentToWriter (doc, writer);
  -               }
  -               
  -               else {
  -                    if (log.isDebugEnabled()) {
  -                         log.debug ("processWsdlRequest: failed to create WSDL");
  -                    }
  -                    
  -                    reportNoWSDL (response, writer, "noWSDL02", null);
  -               }
  -          }
  -          
  -          catch (AxisFault axisFault) {
  -               //the no-service fault is mapped to a no-wsdl error
  -               
  -               if (axisFault.getFaultCode().equals
  +public class QSWSDLHandler extends AbstractQueryStringHandler {
  +
  +    /**
  +     * Performs the action associated with this particular query string
  +     * handler.
  +     *
  +     * @param msgContext a MessageContext object containing message context
  +     *        information for this query string handler.
  +     * @throws AxisFault if an error occurs.
  +     */
  +
  +    public void invoke (MessageContext msgContext) throws AxisFault {
  +        // Obtain objects relevant to the task at hand from the provided
  +        // MessageContext's bag.
  +        configureFromContext(msgContext);
  +
  +        AxisServer engine = (AxisServer) msgContext.getProperty
  +                (HTTPConstants.PLUGIN_ENGINE);
  +        PrintWriter writer = (PrintWriter) msgContext.getProperty
  +                (HTTPConstants.PLUGIN_WRITER);
  +        HttpServletRequest request = (HttpServletRequest)
  +                msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
  +        HttpServletResponse response = (HttpServletResponse)
  +                msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE);
  +
  +        try {
  +            engine.generateWSDL (msgContext);
  +
  +            Document doc = (Document) msgContext.getProperty ("WSDL");
  +
  +            if (doc != null) {
  +                response.setContentType ("text/xml");
  +                XMLUtils.DocumentToWriter (doc, writer);
  +            }
  +
  +            else {
  +                if (log.isDebugEnabled()) {
  +                    log.debug ("processWsdlRequest: failed to create WSDL");
  +                }
  +
  +                reportNoWSDL (response, writer, "noWSDL02", null);
  +            }
  +        }
  +
  +        catch (AxisFault axisFault) {
  +            //the no-service fault is mapped to a no-wsdl error
  +
  +            if (axisFault.getFaultCode().equals
                       (Constants.QNAME_NO_SERVICE_FAULT_CODE)) {
  -                    //which we log
  -                    
  -                    processAxisFault (axisFault);
  -                    
  -                    //then report under a 404 error
  -                    
  -                    response.setStatus (HttpURLConnection.HTTP_NOT_FOUND);
  -                    
  -                    reportNoWSDL (response, writer, "noWSDL01", axisFault);
  -               }
  -               
  -               else {
  -                    //all other faults get thrown
  -                    
  -                    throw axisFault;
  -               }
  -          }
  -     }
  -     
  -     /**
  -      * report that we have no WSDL
  -      * @param res
  -      * @param writer
  -      * @param moreDetailCode optional name of a message to provide more detail
  -      * @param axisFault optional fault string, for extra info at debug time only
  -      */
  -     
  -     private void reportNoWSDL (HttpServletResponse res, PrintWriter writer,
  -          String moreDetailCode, AxisFault axisFault) {
  -          res.setStatus (HttpURLConnection.HTTP_NOT_FOUND);
  -          res.setContentType ("text/html");
  -          
  -          writer.println ("<h2>" + Messages.getMessage ("error00") + "</h2>");
  -          writer.println ("<p>" + Messages.getMessage ("noWSDL00") + "</p>");
  -          
  -          if (moreDetailCode != null) {
  -               writer.println("<p>" + Messages.getMessage (moreDetailCode)
  +                //which we log
  +
  +                processAxisFault (axisFault);
  +
  +                //then report under a 404 error
  +
  +                response.setStatus (HttpURLConnection.HTTP_NOT_FOUND);
  +
  +                reportNoWSDL (response, writer, "noWSDL01", axisFault);
  +            }
  +
  +            else {
  +                //all other faults get thrown
  +
  +                throw axisFault;
  +            }
  +        }
  +    }
  +
  +    /**
  +     * report that we have no WSDL
  +     * @param res
  +     * @param writer
  +     * @param moreDetailCode optional name of a message to provide more detail
  +     * @param axisFault optional fault string, for extra info at debug time only
  +     */
  +
  +    private void reportNoWSDL (HttpServletResponse res, PrintWriter writer,
  +                               String moreDetailCode, AxisFault axisFault) {
  +        res.setStatus (HttpURLConnection.HTTP_NOT_FOUND);
  +        res.setContentType ("text/html");
  +
  +        writer.println ("<h2>" + Messages.getMessage ("error00") + "</h2>");
  +        writer.println ("<p>" + Messages.getMessage ("noWSDL00") + "</p>");
  +
  +        if (moreDetailCode != null) {
  +            writer.println("<p>" + Messages.getMessage (moreDetailCode)
                       + "</p>");
  -          }
  -          
  -          if (axisFault != null && isDevelopment()) {
  -               //dev systems only give fault dumps
  -               
  -               writeFault (writer, axisFault);
  -          }
  -     }
  -     
  -     /**
  -      * this method writes a fault out to an HTML stream. This includes
  -      * escaping the strings to defend against cross-site scripting attacks
  -      * @param writer
  -      * @param axisFault
  -      */
  -      
  -     private void writeFault (PrintWriter writer, AxisFault axisFault) {
  -          String localizedMessage = XMLUtils.xmlEncodeString
  -               (axisFault.getLocalizedMessage());
  -          
  -          writer.println ("<pre>Fault - " + localizedMessage + "<br>");
  -          writer.println (axisFault.dumpToString());
  -          writer.println ("</pre>");
  -     }
  -     
  -     /**
  -      * routine called whenever an axis fault is caught; where they
  -      * are logged and any other business. The method may modify the fault
  -      * in the process
  -      * @param fault what went wrong.
  -      */
  -     
  -     private void processAxisFault (AxisFault fault) {
  -          //log the fault
  -          
  -          Element runtimeException = fault.lookupFaultDetail
  -               (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
  -          
  -          if (runtimeException != null) {
  -               exceptionLog.info (Messages.getMessage ("axisFault00"), fault);
  -               
  -               //strip runtime details
  -               
  -               fault.removeFaultDetail
  -                    (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
  -          }
  -          
  -          else if (exceptionLog.isDebugEnabled()) {
  -               exceptionLog.debug (Messages.getMessage ("axisFault00"), fault);
  -          }
  -          
  -          //dev systems only give fault dumps
  -          
  -          if (!isDevelopment()) {
  -               //strip out the stack trace
  -               
  -               fault.removeFaultDetail (Constants.QNAME_FAULTDETAIL_STACKTRACE);
  -          }
  -     }
  +        }
  +
  +        if (axisFault != null && isDevelopment()) {
  +            //dev systems only give fault dumps
  +
  +            writeFault (writer, axisFault);
  +        }
  +    }
  +
   }
  
  
  
  1.2       +180 -251  
xml-axis/java/src/org/apache/axis/transport/http/QSMethodHandler.java
  
  Index: QSMethodHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/transport/http/QSMethodHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QSMethodHandler.java      7 Aug 2003 00:12:45 -0000       1.1
  +++ QSMethodHandler.java      15 Aug 2003 19:19:31 -0000      1.2
  @@ -1,3 +1,58 @@
  +/*
  +* The Apache Software License, Version 1.1
  +*
  +*
  +* Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  +* reserved.
  +*
  +* Redistribution and use in source and binary forms, with or without
  +* modification, are permitted provided that the following conditions
  +* are met:
  +*
  +* 1. Redistributions of source code must retain the above copyright
  +*    notice, this list of conditions and the following disclaimer.
  +*
  +* 2. Redistributions in binary form must reproduce the above copyright
  +*    notice, this list of conditions and the following disclaimer in
  +*    the documentation and/or other materials provided with the
  +*    distribution.
  +*
  +* 3. The end-user documentation included with the redistribution,
  +*    if any, must include the following acknowledgment:
  +*       "This product includes software developed by the
  +*        Apache Software Foundation (http://www.apache.org/)."
  +*    Alternately, this acknowledgment may appear in the software itself,
  +*    if and wherever such third-party acknowledgments normally appear.
  +*
  +* 4. The names "Axis" and "Apache Software Foundation" must
  +*    not be used to endorse or promote products derived from this
  +*    software without prior written permission. For written
  +*    permission, please contact [EMAIL PROTECTED]
  +*
  +* 5. Products derived from this software may not be called "Apache",
  +*    nor may "Apache" appear in their name, without prior written
  +*    permission of the Apache Software Foundation.
  +*
  +* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  +* DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  +* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  +* SUCH DAMAGE.
  +* ====================================================================
  +*
  +* This software consists of voluntary contributions made by many
  +* individuals on behalf of the Apache Software Foundation.  For more
  +* information on the Apache Software Foundation, please see
  +* <http://www.apache.org/>.
  +*/
  +
   package org.apache.axis.transport.http;
   
   import java.io.ByteArrayInputStream;
  @@ -27,258 +82,132 @@
    * @author Steve Loughran
    */
   
  -public class QSMethodHandler implements QSHandler {
  -     private boolean development;
  -     private Log exceptionLog;
  -     
  -     /**
  -      * probe for the system being 'production'
  -      * @return true for a dev system.
  -      */
  -     
  -     private boolean isDevelopment () {
  -          return this.development;
  -     }
  -     
  -     /**
  -      * Performs the action associated with this particular query string
  -      * handler.
  -      *
  -      * @param msgContext a MessageContext object containing message context
  -      *        information for this query string handler.
  -      * @throws AxisFault if an error occurs.
  -      */
  -     
  -     public void invoke (MessageContext msgContext) throws AxisFault {
  -          // Obtain objects relevant to the task at hand from the provided
  -          // MessageContext's bag.
  -          
  -          AxisServer engine = (AxisServer) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_ENGINE);
  -          PrintWriter writer = (PrintWriter) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_WRITER);
  -          HttpServletRequest request = (HttpServletRequest)
  -               msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
  -          HttpServletResponse response = (HttpServletResponse)
  -               msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE);
  -          this.development = ((Boolean) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_IS_DEVELOPMENT)).booleanValue();
  -          this.exceptionLog = (Log) msgContext.getProperty
  -               (HTTPConstants.PLUGIN_EXCEPTION_LOG);
  -          
  -          String method = null;
  -          String args = "";
  -          Enumeration enum = request.getParameterNames();
  -          
  -          while (enum.hasMoreElements()) {
  -               String param = (String) enum.nextElement();
  -               if (param.equalsIgnoreCase ("method")) {
  -                    method = request.getParameter (param);
  -               }
  -               
  -               else {
  -                    args += "<" + param + ">" + request.getParameter (param) +
  -                         "</" + param + ">";
  -               }
  -          }
  -          
  -          if (method == null) {
  -               response.setContentType ("text/html");
  -               response.setStatus (HttpServletResponse.SC_BAD_REQUEST);
  -               
  -               writer.println ("<h2>" + Messages.getMessage ("error00") +
  +public class QSMethodHandler extends AbstractQueryStringHandler  {
  +
  +    /**
  +     * Performs the action associated with this particular query string
  +     * handler.
  +     *
  +     * @param msgContext a MessageContext object containing message context
  +     *        information for this query string handler.
  +     * @throws AxisFault if an error occurs.
  +     */
  +
  +    public void invoke (MessageContext msgContext) throws AxisFault {
  +        // Obtain objects relevant to the task at hand from the provided
  +        // MessageContext's bag.
  +
  +        configureFromContext(msgContext);
  +        AxisServer engine = (AxisServer) msgContext.getProperty
  +                (HTTPConstants.PLUGIN_ENGINE);
  +        PrintWriter writer = (PrintWriter) msgContext.getProperty
  +                (HTTPConstants.PLUGIN_WRITER);
  +        HttpServletRequest request = (HttpServletRequest)
  +                msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST);
  +        HttpServletResponse response = (HttpServletResponse)
  +                msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE);
  +
  +
  +        String method = null;
  +        String args = "";
  +        Enumeration enum = request.getParameterNames();
  +
  +        while (enum.hasMoreElements()) {
  +            String param = (String) enum.nextElement();
  +            if (param.equalsIgnoreCase ("method")) {
  +                method = request.getParameter (param);
  +            }
  +
  +            else {
  +                args += "<" + param + ">" + request.getParameter (param) +
  +                        "</" + param + ">";
  +            }
  +        }
  +
  +        if (method == null) {
  +            response.setContentType ("text/html");
  +            response.setStatus (HttpServletResponse.SC_BAD_REQUEST);
  +
  +            writer.println ("<h2>" + Messages.getMessage ("error00") +
                       ":  " + Messages.getMessage ("invokeGet00") + "</h2>");
  -               writer.println ("<p>" + Messages.getMessage ("noMethod01") +
  +            writer.println ("<p>" + Messages.getMessage ("noMethod01") +
                       "</p>");
  -          }
  -          
  -          else {
  -               invokeEndpointFromGet (msgContext, response, writer, method, args);
  -          }
  -     }
  -     
  -     /**
  -      * invoke an endpoint from a get request by building an XML request and
  -      * handing it down. If anything goes wrong, we generate an XML formatted
  -      * axis fault
  -      * @param msgContext current message
  -      * @param response to return data
  -      * @param writer output stream
  -      * @param method method to invoke (may be null)
  -      * @param args argument list in XML form
  -      * @throws AxisFault iff something goes wrong when turning the response message
  -      * into a SOAP string.
  -      */
  -     
  -     private void invokeEndpointFromGet (MessageContext msgContext,
  -          HttpServletResponse response, PrintWriter writer, String method,
  -          String args) throws AxisFault {
  -          String body = "<" + method + ">" + args + "</" + method + ">";
  -          String msgtxt = "<SOAP-ENV:Envelope" +
  -               " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\";>" +
  -               "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" +
  -               "</SOAP-ENV:Envelope>";
  -          ByteArrayInputStream istream =
  -               new ByteArrayInputStream (msgtxt.getBytes());
  -          Message responseMsg = null;
  -          
  -          try {
  -               AxisServer engine = (AxisServer) msgContext.getProperty
  +        }
  +
  +        else {
  +            invokeEndpointFromGet (msgContext, response, writer, method, args);
  +        }
  +    }
  +
  +    /**
  +     * invoke an endpoint from a get request by building an XML request and
  +     * handing it down. If anything goes wrong, we generate an XML formatted
  +     * axis fault
  +     * @param msgContext current message
  +     * @param response to return data
  +     * @param writer output stream
  +     * @param method method to invoke (may be null)
  +     * @param args argument list in XML form
  +     * @throws AxisFault iff something goes wrong when turning the response message
  +     * into a SOAP string.
  +     */
  +
  +    private void invokeEndpointFromGet (MessageContext msgContext,
  +                                        HttpServletResponse response, PrintWriter 
writer, String method,
  +                                        String args) throws AxisFault {
  +        String body = "<" + method + ">" + args + "</" + method + ">";
  +        String msgtxt = "<SOAP-ENV:Envelope" +
  +                " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\";>" +
  +                "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" +
  +                "</SOAP-ENV:Envelope>";
  +        ByteArrayInputStream istream =
  +                new ByteArrayInputStream (msgtxt.getBytes());
  +        Message responseMsg = null;
  +
  +        try {
  +            AxisServer engine = (AxisServer) msgContext.getProperty
                       (HTTPConstants.PLUGIN_ENGINE);
  -               Message msg = new Message (istream, false);
  -               
  -               msgContext.setRequestMessage (msg);
  -               engine.invoke (msgContext);
  -               
  -               responseMsg = msgContext.getResponseMessage();
  -               
  -               //turn off caching for GET requests
  -               
  -               response.setHeader ("Cache-Control", "no-cache");
  -               response.setHeader ("Pragma", "no-cache");
  -               
  -               if (responseMsg == null) {
  -                    //tell everyone that something is wrong
  -                    
  -                    throw new Exception (Messages.getMessage ("noResponse01"));
  -               }
  -               
  -          }
  -          
  -          catch (AxisFault fault) {
  -               processAxisFault (fault);
  -               
  -               configureResponseFromAxisFault (response, fault);
  -               
  -               if (responseMsg == null) {
  -                    responseMsg = new Message (fault);
  -               }
  -          }
  -          
  -          catch (Exception e) {
  -               response.setStatus (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  -               responseMsg = convertExceptionToAxisFault (e, responseMsg);
  -          }
  -          
  -          //this call could throw an AxisFault. We delegate it up, because
  -          //if we cant write the message there is not a lot we can do in pure SOAP 
terms.
  -          
  -          response.setContentType ("text/xml");
  -          
  -          writer.println (responseMsg.getSOAPPartAsString());
  -     }
  -     
  -     /**
  -      * routine called whenever an axis fault is caught; where they
  -      * are logged and any other business. The method may modify the fault
  -      * in the process
  -      * @param fault what went wrong.
  -      */
  -     
  -     private void processAxisFault (AxisFault fault) {
  -          //log the fault
  -          
  -          Element runtimeException = fault.lookupFaultDetail
  -               (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
  -          
  -          if (runtimeException != null) {
  -               exceptionLog.info (Messages.getMessage ("axisFault00"), fault);
  -               
  -               //strip runtime details
  -               
  -               fault.removeFaultDetail
  -                    (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
  -          }
  -          
  -          else if (exceptionLog.isDebugEnabled()) {
  -               exceptionLog.debug (Messages.getMessage ("axisFault00"), fault);
  -          }
  -          
  -          //dev systems only give fault dumps
  -          
  -          if (!isDevelopment()) {
  -               //strip out the stack trace
  -               
  -               fault.removeFaultDetail (Constants.QNAME_FAULTDETAIL_STACKTRACE);
  -          }
  -     }
  -     
  -     /**
  -      * Configure the servlet response status code and maybe other headers
  -      * from the fault info.
  -      * @param response response to configure
  -      * @param fault what went wrong
  -      */
  -     
  -     private void configureResponseFromAxisFault (HttpServletResponse response,
  -          AxisFault fault) {
  -          // then get the status code
  -          // It's been suggested that a lack of SOAPAction
  -          // should produce some other error code (in the 400s)...
  -          
  -          int status = getHttpServletResponseStatus (fault);
  -          
  -          if (status == HttpServletResponse.SC_UNAUTHORIZED) {
  -               // unauth access results in authentication request
  -               // TODO: less generic realm choice?
  -               
  -               response.setHeader ("WWW-Authenticate", "Basic realm=\"AXIS\"");
  -          }
  -          
  -          response.setStatus (status);
  -     }
  -     
  -     /**
  -      * turn any Exception into an AxisFault, log it, set the response
  -      * status code according to what the specifications say and
  -      * return a response message for posting. This will be the response
  -      * message passed in if non-null; one generated from the fault otherwise.
  -      *
  -      * @param exception what went wrong
  -      * @param responseMsg what response we have (if any)
  -      * @return a response message to send to the user
  -      */
  -     
  -     private Message convertExceptionToAxisFault (Exception exception,
  -          Message responseMsg) {
  -          logException (exception);
  -          
  -          if (responseMsg == null) {
  -               AxisFault fault = AxisFault.makeFault (exception);
  -               
  -               processAxisFault (fault);
  -               
  -               responseMsg = new Message (fault);
  -          }
  -          
  -          return responseMsg;
  -     }
  -     
  -     /**
  -      * Extract information from AxisFault and map it to a HTTP Status code.
  -      *
  -      * @param af Axis Fault
  -      * @return HTTP Status code.
  -      */
  -     
  -     private int getHttpServletResponseStatus (AxisFault af) {
  -          // TODO: Should really be doing this with explicit AxisFault
  -          // subclasses... --Glen
  -          
  -          return af.getFaultCode().getLocalPart().startsWith ("Server.Unauth")
  -               ? HttpServletResponse.SC_UNAUTHORIZED
  -               : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
  -          
  -          // This will raise a 401 for both
  -          // "Unauthenticated" & "Unauthorized"...
  -     }
  -     
  -     /**
  -      * log any exception to our output log, at our chosen level
  -      * @param e what went wrong
  -      */
  -     
  -     private void logException (Exception e) {
  -          exceptionLog.info (Messages.getMessage ("exception00"), e);
  -     }
  +            Message msg = new Message (istream, false);
  +
  +            msgContext.setRequestMessage (msg);
  +            engine.invoke (msgContext);
  +
  +            responseMsg = msgContext.getResponseMessage();
  +
  +            //turn off caching for GET requests
  +
  +            response.setHeader ("Cache-Control", "no-cache");
  +            response.setHeader ("Pragma", "no-cache");
  +
  +            if (responseMsg == null) {
  +                //tell everyone that something is wrong
  +
  +                throw new Exception (Messages.getMessage ("noResponse01"));
  +            }
  +
  +        }
  +
  +        catch (AxisFault fault) {
  +            processAxisFault (fault);
  +
  +            configureResponseFromAxisFault (response, fault);
  +
  +            if (responseMsg == null) {
  +                responseMsg = new Message (fault);
  +            }
  +        }
  +
  +        catch (Exception e) {
  +            response.setStatus (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  +            responseMsg = convertExceptionToAxisFault (e, responseMsg);
  +        }
  +
  +        //this call could throw an AxisFault. We delegate it up, because
  +        //if we cant write the message there is not a lot we can do in pure SOAP 
terms.
  +
  +        response.setContentType ("text/xml");
  +
  +        writer.println (responseMsg.getSOAPPartAsString());
  +    }
  +
   }
  
  
  
  1.2       +56 -1     
xml-axis/java/src/org/apache/axis/transport/http/QSListHandler.java
  
  Index: QSListHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/transport/http/QSListHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QSListHandler.java        7 Aug 2003 00:12:45 -0000       1.1
  +++ QSListHandler.java        15 Aug 2003 19:19:31 -0000      1.2
  @@ -1,3 +1,58 @@
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + *
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Axis" and "Apache Software Foundation" must
  + *    not be used to endorse or promote products derived from this
  + *    software without prior written permission. For written
  + *    permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    nor may "Apache" appear in their name, without prior written
  + *    permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
   package org.apache.axis.transport.http;
   
   import java.io.PrintWriter;
  @@ -25,7 +80,7 @@
    * @author Steve Loughran
    */
   
  -public class QSListHandler implements QSHandler {
  +public class QSListHandler extends AbstractQueryStringHandler  {
        /**
         * Performs the action associated with this particular query string
         * handler.
  
  
  
  1.2       +55 -0     xml-axis/java/src/org/apache/axis/transport/http/QSHandler.java
  
  Index: QSHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/QSHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QSHandler.java    7 Aug 2003 00:12:45 -0000       1.1
  +++ QSHandler.java    15 Aug 2003 19:19:31 -0000      1.2
  @@ -1,3 +1,58 @@
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + *
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Axis" and "Apache Software Foundation" must
  + *    not be used to endorse or promote products derived from this
  + *    software without prior written permission. For written
  + *    permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    nor may "Apache" appear in their name, without prior written
  + *    permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
   package org.apache.axis.transport.http;
   
   import org.apache.axis.AxisFault;
  
  
  
  1.1                  
xml-axis/java/src/org/apache/axis/transport/http/AbstractQueryStringHandler.java
  
  Index: AbstractQueryStringHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.transport.http;
  
  import org.apache.axis.MessageContext;
  import org.apache.axis.AxisFault;
  import org.apache.axis.Constants;
  import org.apache.axis.Message;
  import org.apache.axis.utils.Messages;
  import org.apache.axis.utils.XMLUtils;
  import org.apache.commons.logging.Log;
  import org.w3c.dom.Element;
  
  import javax.servlet.http.HttpServletResponse;
  import java.io.PrintWriter;
  
  /**
   * An optional base class for query string handlers; provides various helper methods
   * and extracts things from the the message context
   */
  public abstract class AbstractQueryStringHandler implements QSHandler {
      /** cache of development flag */
      private boolean development;
      /** log for exceptions */
      protected Log exceptionLog;
  
      /** the other log */
      protected Log log;
  
      /**
       * probe for the system being 'production'
       * @return true for a dev system.
       */
  
      protected boolean isDevelopment () {
           return this.development;
      }
  
      /**
       * configure our elements from the context. Call this in the invoke()
       * implementation to set up the base class
       * @param msgContext
       */
      protected void configureFromContext(MessageContext msgContext) {
          this.development = ((Boolean) msgContext.getProperty
               (HTTPConstants.PLUGIN_IS_DEVELOPMENT)).booleanValue();
          this.exceptionLog = (Log) msgContext.getProperty
               (HTTPConstants.PLUGIN_EXCEPTION_LOG);
          this.log = (Log) msgContext.getProperty(HTTPConstants.PLUGIN_LOG);
      }
  
      /**
       * routine called whenever an axis fault is caught; where they
       * are logged and any other business. The method may modify the fault
       * in the process
       * @param fault what went wrong.
       */
  
      protected void processAxisFault (AxisFault fault) {
           //log the fault
  
           Element runtimeException = fault.lookupFaultDetail
                (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
  
           if (runtimeException != null) {
                exceptionLog.info (Messages.getMessage ("axisFault00"), fault);
  
                //strip runtime details
  
                fault.removeFaultDetail
                     (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
           }
  
           else if (exceptionLog.isDebugEnabled()) {
                exceptionLog.debug (Messages.getMessage ("axisFault00"), fault);
           }
  
           //dev systems only give fault dumps
  
           if (!isDevelopment()) {
                //strip out the stack trace
  
                fault.removeFaultDetail (Constants.QNAME_FAULTDETAIL_STACKTRACE);
           }
      }
  
      /**
        * Configure the servlet response status code and maybe other headers
        * from the fault info.
        * @param response response to configure
        * @param fault what went wrong
        */
  
       protected void configureResponseFromAxisFault (HttpServletResponse response,
            AxisFault fault) {
            // then get the status code
            // It's been suggested that a lack of SOAPAction
            // should produce some other error code (in the 400s)...
  
            int status = getHttpServletResponseStatus (fault);
  
            if (status == HttpServletResponse.SC_UNAUTHORIZED) {
                 // unauth access results in authentication request
                 // TODO: less generic realm choice?
  
                 response.setHeader ("WWW-Authenticate", "Basic realm=\"AXIS\"");
            }
  
            response.setStatus (status);
       }
  
      /**
        * turn any Exception into an AxisFault, log it, set the response
        * status code according to what the specifications say and
        * return a response message for posting. This will be the response
        * message passed in if non-null; one generated from the fault otherwise.
        *
        * @param exception what went wrong
        * @param responseMsg what response we have (if any)
        * @return a response message to send to the user
        */
  
       protected Message convertExceptionToAxisFault (Exception exception,
            Message responseMsg) {
            logException (exception);
  
            if (responseMsg == null) {
                 AxisFault fault = AxisFault.makeFault (exception);
  
                 processAxisFault (fault);
  
                 responseMsg = new Message (fault);
            }
  
            return responseMsg;
       }
  
      /**
        * Extract information from AxisFault and map it to a HTTP Status code.
        *
        * @param af Axis Fault
        * @return HTTP Status code.
        */
  
       private int getHttpServletResponseStatus (AxisFault af) {
            // TODO: Should really be doing this with explicit AxisFault
            // subclasses... --Glen
  
            return af.getFaultCode().getLocalPart().startsWith ("Server.Unauth")
                 ? HttpServletResponse.SC_UNAUTHORIZED
                 : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
  
            // This will raise a 401 for both
            // "Unauthenticated" & "Unauthorized"...
       }
  
      /**
        * log any exception to our output log, at our chosen level
        * @param e what went wrong
        */
  
       private void logException (Exception e) {
            exceptionLog.info (Messages.getMessage ("exception00"), e);
       }
  
      /**
       * this method writes a fault out to an HTML stream. This includes
       * escaping the strings to defend against cross-site scripting attacks
       * @param writer
       * @param axisFault
       */
  
      protected void writeFault (PrintWriter writer, AxisFault axisFault) {
          String localizedMessage = XMLUtils.xmlEncodeString
                  (axisFault.getLocalizedMessage());
  
          writer.println ("<pre>Fault - " + localizedMessage + "<br>");
          writer.println (axisFault.dumpToString());
          writer.println ("</pre>");
      }
  }
  
  
  

Reply via email to