FileDocCategorySizeDatePackage
AbstractQueryStringHandler.javaAPI DocApache Axis 1.46374Sat Apr 22 18:57:26 BST 2006org.apache.axis.transport.http

AbstractQueryStringHandler

public abstract class AbstractQueryStringHandler extends Object implements QSHandler
An optional base class for query string handlers; provides various helper methods and extracts things from the the message context

Fields Summary
private boolean
development
cache of development flag
protected Log
exceptionLog
log for exceptions
protected Log
log
the other log
Constructors Summary
Methods Summary
protected voidconfigureFromContext(org.apache.axis.MessageContext msgContext)
configure our elements from the context. Call this in the invoke() implementation to set up the base class

param
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);
    
protected voidconfigureResponseFromAxisFault(javax.servlet.http.HttpServletResponse response, org.apache.axis.AxisFault fault)
Configure the servlet response status code and maybe other headers from the fault info.

param
response response to configure
param
fault what went wrong

          // 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);
     
protected org.apache.axis.MessageconvertExceptionToAxisFault(java.lang.Exception exception, org.apache.axis.Message responseMsg)
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

          logException (exception);

          if (responseMsg == null) {
               AxisFault fault = AxisFault.makeFault (exception);

               processAxisFault (fault);

               responseMsg = new Message (fault);
          }

          return responseMsg;
     
private intgetHttpServletResponseStatus(org.apache.axis.AxisFault af)
Extract information from AxisFault and map it to a HTTP Status code.

param
af Axis Fault
return
HTTP Status code.

          // 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"...
     
protected booleanisDevelopment()
probe for the system being 'production'

return
true for a dev system.

         return this.development;
    
private voidlogException(java.lang.Exception e)
log any exception to our output log, at our chosen level

param
e what went wrong

          exceptionLog.info (Messages.getMessage ("exception00"), e);
     
protected voidprocessAxisFault(org.apache.axis.AxisFault fault)
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.

         //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);
         }
    
protected voidwriteFault(java.io.PrintWriter writer, org.apache.axis.AxisFault 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

        String localizedMessage = XMLUtils.xmlEncodeString
                (axisFault.getLocalizedMessage());

        writer.println ("<pre>Fault - " + localizedMessage + "<br>");
        writer.println (axisFault.dumpToString());
        writer.println ("</pre>");