Coverage Report - org.mule.transport.soap.axis.AxisServiceComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisServiceComponent
0%
0/361
0%
0/140
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.soap.axis;
 8  
 
 9  
 import org.mule.DefaultMuleMessage;
 10  
 import org.mule.RequestContext;
 11  
 import org.mule.api.MessagingException;
 12  
 import org.mule.api.MuleEventContext;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.config.MuleProperties;
 16  
 import org.mule.api.endpoint.EndpointURI;
 17  
 import org.mule.api.lifecycle.Callable;
 18  
 import org.mule.api.lifecycle.Initialisable;
 19  
 import org.mule.api.lifecycle.InitialisationException;
 20  
 import org.mule.config.MuleManifest;
 21  
 import org.mule.config.i18n.CoreMessages;
 22  
 import org.mule.config.i18n.MessageFactory;
 23  
 import org.mule.endpoint.MuleEndpointURI;
 24  
 import org.mule.module.cxf.SoapConstants;
 25  
 import org.mule.transport.http.HttpConnector;
 26  
 import org.mule.transport.http.HttpConstants;
 27  
 import org.mule.transport.soap.axis.extensions.AxisMuleSession;
 28  
 import org.mule.transport.soap.axis.extensions.MuleConfigProvider;
 29  
 import org.mule.util.StringUtils;
 30  
 
 31  
 import java.io.ByteArrayInputStream;
 32  
 import java.io.ByteArrayOutputStream;
 33  
 import java.io.File;
 34  
 import java.io.FileInputStream;
 35  
 import java.io.IOException;
 36  
 import java.util.ArrayList;
 37  
 import java.util.Iterator;
 38  
 import java.util.Map;
 39  
 import java.util.Properties;
 40  
 
 41  
 import javax.xml.namespace.QName;
 42  
 
 43  
 import org.apache.axis.AxisEngine;
 44  
 import org.apache.axis.AxisFault;
 45  
 import org.apache.axis.ConfigurationException;
 46  
 import org.apache.axis.Constants;
 47  
 import org.apache.axis.Message;
 48  
 import org.apache.axis.MessageContext;
 49  
 import org.apache.axis.description.OperationDesc;
 50  
 import org.apache.axis.description.ServiceDesc;
 51  
 import org.apache.axis.handlers.soap.SOAPService;
 52  
 import org.apache.axis.i18n.Messages;
 53  
 import org.apache.axis.security.servlet.ServletSecurityProvider;
 54  
 import org.apache.axis.server.AxisServer;
 55  
 import org.apache.axis.transport.http.HTTPConstants;
 56  
 import org.apache.axis.transport.http.ServletEndpointContextImpl;
 57  
 import org.apache.axis.utils.Admin;
 58  
 import org.apache.axis.utils.XMLUtils;
 59  
 import org.apache.commons.logging.Log;
 60  
 import org.w3c.dom.Document;
 61  
 
 62  
 /**
 63  
  * <code>AxisServiceComponent</code> is a Mule component implementation of the Axis
 64  
  * servlet. This component supports all the features of the Axis servlet except -
 65  
  * <ol>
 66  
  * <li>Jws class services are not supported as they don't add any value to the Mule�
 67  
  * model</li>
 68  
  * <li>Currently there is no HttpSession support. This will be fixed when MuleSession
 69  
  * support is added to the Http Connector</li>
 70  
  * </ol>
 71  
  */
 72  
 
 73  
 public class AxisServiceComponent implements Initialisable, Callable
 74  
 {
 75  0
     protected static final Log logger = org.apache.commons.logging.LogFactory.getLog(AxisServiceComponent.class);
 76  
 
 77  
     public static final String INIT_PROPERTY_TRANSPORT_NAME = "transport.name";
 78  
     public static final String INIT_PROPERTY_USE_SECURITY = "use-servlet-security";
 79  
     public static final String INIT_PROPERTY_ENABLE_LIST = "axis.enableListQuery";
 80  
     public static final String DEFAULT_AXIS_HOME = "/axisHome";
 81  
 
 82  0
     private String transportName = "http";
 83  0
     private ServletSecurityProvider securityProvider = null;
 84  0
     private boolean enableList = true;
 85  
     private String homeDir;
 86  
     private AxisServer axis;
 87  
 
 88  
     /** For IoC */
 89  
     public AxisServiceComponent()
 90  0
     {
 91  
         // do nothing
 92  0
     }
 93  
 
 94  
     /**
 95  
      * Passes the context to the listener
 96  
      * 
 97  
      * @param context the context to process
 98  
      * @return Object this object can be anything. When the
 99  
      *         <code>LifecycleAdapter</code> for the component receives this
 100  
      *         object it will first see if the Object is an <code>MuleEvent</code>
 101  
      *         if not and the Object is not null a new context will be created using
 102  
      *         the returned object as the payload. This new context will then get
 103  
      *         published to the configured outbound endpoint if-
 104  
      *         <ol>
 105  
      *         <li>One has been configured for the component.</li>
 106  
      *         <li>the <code>setStopFurtherProcessing(true)</code> wasn't called
 107  
      *         on the previous context.</li>
 108  
      *         </ol>
 109  
      * @throws Exception if the context fails to process properly. If exceptions
 110  
      *             aren't handled by the implementation they will be handled by the
 111  
      *             exceptionListener associated with the component
 112  
      */
 113  
     public Object onCall(MuleEventContext context) throws Exception
 114  
     {
 115  0
         AxisStringWriter response = new AxisStringWriter();
 116  0
         String method = context.getMessage().getInboundProperty(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_POST);
 117  0
         if (HttpConstants.METHOD_GET.equalsIgnoreCase(method))
 118  
         {
 119  0
             doGet(context, response);
 120  
         }
 121  
         else
 122  
         {
 123  0
             doPost(context, response);
 124  
         }
 125  0
         response.close();
 126  
         
 127  0
         String payload = response.getWriter().toString();
 128  0
         Map<String, Object> properties = response.getProperties();
 129  0
         return new DefaultMuleMessage(payload, properties, context.getMuleContext());
 130  
     }
 131  
 
 132  
     public void initialise() throws InitialisationException
 133  
     {
 134  0
         if (axis == null)
 135  
         {
 136  0
             throw new InitialisationException(MessageFactory.createStaticMessage("No Axis instance, this component has not been initialized properly."), this);
 137  
         }
 138  0
     }
 139  
 
 140  
     public void doGet(MuleEventContext context, AxisStringWriter response)
 141  
         throws MuleException, IOException
 142  
     {
 143  
         try
 144  
         {
 145  
             // We parse a new uri based on the listening host and port with the
 146  
             // request parameters appended
 147  
             // Using the soap prefix ensures that we use a soap endpoint builder
 148  0
             EndpointURI endpointUri = context.getEndpointURI();
 149  
             //We need to re-parse the URI here because we are only give the listening endpoint, not the actual
 150  
             //request endpoint. The request endpoint needs to have the query parameters from the client
 151  
             //There is no need to do this for Servlet because it does things differently
 152  0
             if (!"true".equalsIgnoreCase(context.getEndpointURI().getParams().getProperty("servlet.endpoint")))
 153  
             {
 154  0
                 String uri = SoapConstants.SOAP_ENDPOINT_PREFIX + context.getEndpointURI().getScheme()
 155  
                                 + "://" + context.getEndpointURI().getHost() + ":"
 156  
                                 + context.getEndpointURI().getPort();
 157  0
                 uri += context.getMessage().getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY, StringUtils.EMPTY);
 158  0
                 endpointUri = new MuleEndpointURI(uri, context.getMuleContext());
 159  0
                 endpointUri.initialise();
 160  
             }
 161  
 
 162  0
             AxisEngine engine = getAxis();
 163  0
             String pathInfo = endpointUri.getPath();
 164  0
             boolean wsdlRequested = false;
 165  0
             boolean listRequested = false;
 166  
 
 167  0
             if (endpointUri.getAddress().endsWith(".jws"))
 168  
             {
 169  0
                 throw new AxisFault("Jws not supported by the Mule Axis service");
 170  
             }
 171  
 
 172  0
             String queryString = endpointUri.getQuery();
 173  0
             if (queryString != null)
 174  
             {
 175  0
                 if (queryString.equalsIgnoreCase(SoapConstants.WSDL_PROPERTY))
 176  
                 {
 177  0
                     wsdlRequested = true;
 178  
                 }
 179  
                 else
 180  
                 {
 181  0
                     if (queryString.equalsIgnoreCase(SoapConstants.LIST_PROPERTY))
 182  
                     {
 183  0
                         listRequested = true;
 184  
                     }
 185  
                 }
 186  
             }
 187  
 
 188  0
             boolean hasNoPath = (StringUtils.isEmpty(pathInfo) || pathInfo.equals("/"));
 189  0
             if (!wsdlRequested && !listRequested && hasNoPath)
 190  
             {
 191  0
                 reportAvailableServices(context, response);
 192  
             }
 193  
             else
 194  
             {
 195  0
                 MessageContext msgContext = new MessageContext(engine);
 196  0
                 populateMessageContext(msgContext, context, endpointUri);
 197  
 
 198  0
                 msgContext.setProperty("transport.url", endpointUri.toString());
 199  0
                 if (wsdlRequested)
 200  
                 {
 201  0
                     processWsdlRequest(msgContext, response);
 202  
                 }
 203  0
                 else if (listRequested)
 204  
                 {
 205  0
                     processListRequest(response);
 206  
                 }
 207  
                 else
 208  
                 {
 209  0
                     processMethodRequest(msgContext, context, response, endpointUri);
 210  
                 }
 211  
             }
 212  
         }
 213  0
         catch (AxisFault fault)
 214  
         {
 215  0
             reportTroubleInGet(fault, response);
 216  
         }
 217  0
         catch (Exception e)
 218  
         {
 219  0
             reportTroubleInGet(e, response);
 220  0
         }
 221  0
     }
 222  
 
 223  
     protected void doPost(MuleEventContext context, AxisStringWriter response)
 224  
         throws Exception
 225  
     {
 226  
         String soapAction;
 227  
         Message responseMsg;
 228  0
         AxisEngine engine = getAxis();
 229  0
         if (engine == null)
 230  
         {
 231  
 
 232  0
             throw new MessagingException(CoreMessages.objectIsNull("Axis Engine"), context.getMessage());
 233  
         }
 234  0
         MessageContext msgContext = new MessageContext(engine);
 235  
 
 236  
         String contentType;
 237  
         try
 238  
         {
 239  
             //EndpointURI endpointUri = getEndpoint(context);
 240  0
             EndpointURI endpointUri = context.getEndpointURI();
 241  0
             populateMessageContext(msgContext, context, endpointUri);
 242  0
             if (securityProvider != null)
 243  
             {
 244  0
                 if (logger.isDebugEnabled())
 245  
                 {
 246  0
                     logger.debug("securityProvider:" + securityProvider);
 247  
                 }
 248  0
                 msgContext.setProperty("securityProvider", securityProvider);
 249  
             }
 250  
 
 251  0
             Object request = context.getMessage().getPayload();
 252  0
             if (request instanceof File)
 253  
             {
 254  0
                 request = new FileInputStream((File)request);
 255  
             }
 256  0
             else if (request instanceof byte[])
 257  
             {
 258  0
                 request = new ByteArrayInputStream((byte[])request);
 259  
             }
 260  
 
 261  0
             final String cType = context.getMessage().getInboundProperty(HTTPConstants.HEADER_CONTENT_TYPE);
 262  0
             final String cLocation = context.getMessage().getInboundProperty(HTTPConstants.HEADER_CONTENT_LOCATION);
 263  0
             Message requestMsg = new Message(request, false, cType, cLocation);
 264  
 
 265  0
             if (logger.isDebugEnabled())
 266  
             {
 267  0
                 logger.debug("Request Message:" + requestMsg);
 268  
             }
 269  0
             msgContext.setRequestMessage(requestMsg);
 270  0
             msgContext.setProperty("transport.url", endpointUri.toString());
 271  
 
 272  0
             soapAction = getSoapAction(context);
 273  0
             if (soapAction != null)
 274  
             {
 275  0
                 msgContext.setUseSOAPAction(true);
 276  0
                 msgContext.setSOAPActionURI(soapAction);
 277  
             }
 278  0
             msgContext.setSession(new AxisMuleSession(context.getSession()));
 279  
 
 280  0
             if (logger.isDebugEnabled())
 281  
             {
 282  0
                 logger.debug("Invoking Axis Engine.");
 283  
             }
 284  0
             AxisServiceProxy.setProperties(RequestContext.getEvent().getEndpoint().getProperties());
 285  0
             engine.invoke(msgContext);
 286  0
             if (logger.isDebugEnabled())
 287  
             {
 288  0
                 logger.debug("Return from Axis Engine.");
 289  
             }
 290  0
             if (RequestContext.getExceptionPayload() instanceof Exception)
 291  
             {
 292  0
                 throw (Exception)RequestContext.getExceptionPayload().getException();
 293  
             }
 294  
             // remove temporary file used for soap message with attachment
 295  0
             if (request instanceof File)
 296  
             {
 297  0
                 ((File)request).delete();
 298  
             }
 299  0
             responseMsg = msgContext.getResponseMessage();
 300  0
             if (responseMsg == null)
 301  
             {
 302  0
                 throw new Exception(Messages.getMessage("noResponse01"));
 303  
             }
 304  
         }
 305  0
         catch (AxisFault fault)
 306  
         {
 307  0
             logger.error(fault.toString() + " target service is: " + msgContext.getTargetService()
 308  
                             + ". MuleEvent is: " + context.toString(), fault);
 309  0
             processAxisFault(fault);
 310  0
             configureResponseFromAxisFault(response, fault);
 311  0
             responseMsg = msgContext.getResponseMessage();
 312  0
             if (responseMsg == null)
 313  
             {
 314  0
                 responseMsg = new Message(fault);
 315  
             }
 316  
         }
 317  0
         catch (Exception e)
 318  
         {
 319  0
             responseMsg = msgContext.getResponseMessage();
 320  0
             response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500");
 321  0
             responseMsg = convertExceptionToAxisFault(e, responseMsg);
 322  0
         }
 323  
 
 324  0
         contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
 325  
 
 326  0
         sendResponse(contentType, response, responseMsg);
 327  
 
 328  0
         if (logger.isDebugEnabled())
 329  
         {
 330  0
             logger.debug("Response sent.");
 331  
         }
 332  0
     }
 333  
 
 334  
     private void reportTroubleInGet(Exception exception, AxisStringWriter response)
 335  
     {
 336  0
         response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");
 337  0
         response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500");
 338  0
         response.write("<h2>" + Messages.getMessage("error00") + "</h2>");
 339  0
         response.write("<p>" + Messages.getMessage("somethingWrong00") + "</p>");
 340  0
         if (exception instanceof AxisFault)
 341  
         {
 342  0
             AxisFault fault = (AxisFault)exception;
 343  0
             processAxisFault(fault);
 344  0
             writeFault(response, fault);
 345  0
         }
 346  
         else
 347  
         {
 348  0
             logger.error(exception.getMessage(), exception);
 349  0
             response.write("<pre>Exception - " + exception + "<br>");
 350  0
             response.write("</pre>");
 351  
         }
 352  0
     }
 353  
 
 354  
     protected void processAxisFault(AxisFault fault)
 355  
     {
 356  0
         org.w3c.dom.Element runtimeException = fault
 357  
             .lookupFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
 358  0
         if (runtimeException != null)
 359  
         {
 360  0
             logger.info(Messages.getMessage("axisFault00"), fault);
 361  0
             fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
 362  
         }
 363  0
         else if (logger.isDebugEnabled())
 364  
         {
 365  0
             logger.debug(Messages.getMessage("axisFault00"), fault);
 366  
         }
 367  
 
 368  0
     }
 369  
 
 370  
     private void writeFault(AxisStringWriter response, AxisFault axisFault)
 371  
     {
 372  0
         String localizedMessage = XMLUtils.xmlEncodeString(axisFault.getLocalizedMessage());
 373  0
         response.write("<pre>Fault - " + localizedMessage + "<br>");
 374  0
         response.write(axisFault.dumpToString());
 375  0
         response.write("</pre>");
 376  0
     }
 377  
 
 378  
     protected void processMethodRequest(MessageContext msgContext,
 379  
                                         MuleEventContext context,
 380  
                                         AxisStringWriter response,
 381  
                                         EndpointURI endpointUri) throws AxisFault
 382  
     {
 383  0
         Properties params = endpointUri.getUserParams();
 384  
 
 385  0
         String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY);
 386  0
         if (method == null)
 387  
         {
 388  0
             method = endpointUri.getPath().substring(endpointUri.getPath().lastIndexOf("/") + 1);
 389  
         }
 390  0
         StringBuffer args = new StringBuffer(64);
 391  
 
 392  
         Map.Entry entry;
 393  0
         for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();)
 394  
         {
 395  0
             entry = (Map.Entry)iterator.next();
 396  0
             args.append("<").append(entry.getKey()).append(">");
 397  0
             args.append(entry.getValue());
 398  0
             args.append("</").append(entry.getKey()).append(">");
 399  
         }
 400  
 
 401  0
         if (method == null)
 402  
         {
 403  0
             response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");
 404  0
             response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "400");
 405  0
             response.write("<h2>" + Messages.getMessage("error00") + ":  "
 406  
                             + Messages.getMessage("invokeGet00") + "</h2>");
 407  0
             response.write("<p>" + Messages.getMessage("noMethod01") + "</p>");
 408  
         }
 409  
         else
 410  
         {
 411  0
             invokeEndpointFromGet(msgContext, response, method, args.toString());
 412  
         }
 413  0
     }
 414  
 
 415  
     protected void processWsdlRequest(MessageContext msgContext, AxisStringWriter response)
 416  
         throws AxisFault
 417  
     {
 418  0
         AxisEngine engine = getAxis();
 419  
         try
 420  
         {
 421  0
             engine.generateWSDL(msgContext);
 422  0
             Document doc = (Document)msgContext.getProperty("WSDL");
 423  0
             if (doc != null)
 424  
             {
 425  0
                 response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/xml");
 426  0
                 XMLUtils.DocumentToWriter(doc, response.getWriter());
 427  
             }
 428  
             else
 429  
             {
 430  0
                 if (logger.isDebugEnabled())
 431  
                 {
 432  0
                     logger.debug("processWsdlRequest: failed to create WSDL");
 433  
                 }
 434  0
                 reportNoWSDL(response, "noWSDL02", null);
 435  
             }
 436  
         }
 437  0
         catch (AxisFault axisFault)
 438  
         {
 439  0
             if (axisFault.getFaultCode().equals(Constants.QNAME_NO_SERVICE_FAULT_CODE))
 440  
             {
 441  0
                 processAxisFault(axisFault);
 442  0
                 response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404");
 443  0
                 reportNoWSDL(response, "noWSDL01", axisFault);
 444  
             }
 445  
             else
 446  
             {
 447  0
                 throw axisFault;
 448  
             }
 449  0
         }
 450  0
     }
 451  
 
 452  
     protected void invokeEndpointFromGet(MessageContext msgContext,
 453  
                                          AxisStringWriter response,
 454  
                                          String method,
 455  
                                          String args) throws AxisFault
 456  
     {
 457  0
         String body = "<" + method + ">" + args + "</" + method + ">";
 458  0
         String msgtxt = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body>"
 459  
                         + body + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";
 460  0
         Message responseMsg = null;
 461  
         try
 462  
         {
 463  0
             ByteArrayInputStream istream = new ByteArrayInputStream(msgtxt.getBytes("ISO-8859-1"));
 464  0
             AxisEngine engine = getAxis();
 465  0
             Message msg = new Message(istream, false);
 466  0
             msgContext.setRequestMessage(msg);
 467  0
             AxisServiceProxy.setProperties(RequestContext.getEvent().getEndpoint().getProperties());
 468  0
             engine.invoke(msgContext);
 469  0
             responseMsg = msgContext.getResponseMessage();
 470  0
             response.setProperty(HTTPConstants.HEADER_CACHE_CONTROL, "no-cache");
 471  0
             response.setProperty(HTTPConstants.HEADER_PRAGMA, "no-cache");
 472  0
             if (responseMsg == null)
 473  
             {
 474  0
                 throw new Exception(Messages.getMessage("noResponse01"));
 475  
             }
 476  
         }
 477  0
         catch (AxisFault fault)
 478  
         {
 479  0
             processAxisFault(fault);
 480  0
             configureResponseFromAxisFault(response, fault);
 481  0
             responseMsg = new Message(fault);
 482  
         }
 483  0
         catch (Exception e)
 484  
         {
 485  0
             response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500");
 486  0
             responseMsg = convertExceptionToAxisFault(e, responseMsg);
 487  0
         }
 488  0
         response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/xml");
 489  0
         response.write(responseMsg.getSOAPPartAsString());
 490  0
     }
 491  
 
 492  
     protected void reportServiceInfo(AxisStringWriter response, SOAPService service, String serviceName)
 493  
     {
 494  0
         response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");
 495  0
         response.write("<h1>" + service.getName() + "</h1>");
 496  0
         response.write("<p>" + Messages.getMessage("axisService00") + "</p>");
 497  0
         response.write("<i>" + Messages.getMessage("perhaps00") + "</i>");
 498  0
     }
 499  
 
 500  
     protected void processListRequest(AxisStringWriter response) throws AxisFault
 501  
     {
 502  0
         AxisEngine engine = getAxis();
 503  0
         response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/html");
 504  0
         if (enableList)
 505  
         {
 506  0
             Document doc = Admin.listConfig(engine);
 507  0
             if (doc != null)
 508  
             {
 509  0
                 XMLUtils.DocumentToWriter(doc, response.getWriter());
 510  
             }
 511  
             else
 512  
             {
 513  0
                 response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404");
 514  0
                 response.write("<h2>" + Messages.getMessage("error00") + "</h2>");
 515  0
                 response.write("<p>" + Messages.getMessage("noDeploy00") + "</p>");
 516  
             }
 517  0
         }
 518  
         else
 519  
         {
 520  0
             response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "403");
 521  0
             response.write("<h2>" + Messages.getMessage("error00") + "</h2>");
 522  0
             response.write("<p><i>?list</i> " + Messages.getMessage("disabled00") + "</p>");
 523  
         }
 524  0
     }
 525  
 
 526  
     private void reportNoWSDL(AxisStringWriter response, String moreDetailCode, AxisFault axisFault)
 527  
     {
 528  0
         response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404");
 529  0
         response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/html");
 530  0
         response.write("<h2>" + Messages.getMessage("error00") + "</h2>");
 531  0
         response.write("<p>" + Messages.getMessage("noWSDL00") + "</p>");
 532  0
         if (moreDetailCode != null)
 533  
         {
 534  0
             response.write("<p>" + Messages.getMessage(moreDetailCode) + "</p>");
 535  
         }
 536  
 
 537  0
     }
 538  
 
 539  
     protected void reportAvailableServices(MuleEventContext context, AxisStringWriter response)
 540  
         throws ConfigurationException, AxisFault
 541  
     {
 542  0
         AxisEngine engine = getAxis();
 543  0
         response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");
 544  0
         response.write("<h2>And now... Some Services</h2>");
 545  0
         String version = MuleManifest.getProductVersion();
 546  0
         if (version == null)
 547  
         {
 548  0
             version = "Version Not Set";
 549  
         }
 550  0
         response.write("<h5>(Mule - " + version + ")</h5>");
 551  
         Iterator i;
 552  
 
 553  
         try
 554  
         {
 555  0
             response
 556  
                 .write("<table width=\"400\"><tr><th>Mule Component Services</th><th>Axis Services</th></tr><tr><td width=\"200\" valign=\"top\">");
 557  0
             i = engine.getConfig().getDeployedServices();
 558  0
             listServices(i, response);
 559  0
             response.write("</td><td width=\"200\" valign=\"top\">");
 560  0
             i = ((MuleConfigProvider)engine.getConfig()).getAxisDeployedServices();
 561  0
             listServices(i, response);
 562  0
             response.write("</td></tr></table>");
 563  
         }
 564  0
         catch (ConfigurationException configException)
 565  
         {
 566  0
             if (configException.getContainedException() instanceof AxisFault)
 567  
             {
 568  0
                 throw (AxisFault)configException.getContainedException();
 569  
             }
 570  
             else
 571  
             {
 572  0
                 throw configException;
 573  
             }
 574  0
         }
 575  
 
 576  0
     }
 577  
 
 578  
     private void listServices(Iterator i, AxisStringWriter response)
 579  
     {
 580  0
         response.write("<ul>");
 581  0
         while (i.hasNext())
 582  
         {
 583  0
             ServiceDesc sd = (ServiceDesc)i.next();
 584  0
             StringBuffer sb = new StringBuffer(512);
 585  0
             sb.append("<li>");
 586  0
             String name = sd.getName();
 587  0
             sb.append(name);
 588  0
             sb.append(" <a href=\"");
 589  0
             if (sd.getEndpointURL() != null)
 590  
             {
 591  0
                 sb.append(sd.getEndpointURL());
 592  0
                 if (!sd.getEndpointURL().endsWith("/"))
 593  
                 {
 594  0
                     sb.append("/");
 595  
                 }
 596  
             }
 597  0
             sb.append(name);
 598  0
             sb.append("?wsdl\"><i>(wsdl)</i></a></li>");
 599  0
             response.write(sb.toString());
 600  0
             if (sd.getDocumentation() != null)
 601  
             {
 602  0
                 response.write("<ul><h6>" + sd.getDocumentation() + "</h6></ul>");
 603  
             }
 604  0
             ArrayList operations = sd.getOperations();
 605  0
             if (!operations.isEmpty())
 606  
             {
 607  0
                 response.write("<ul>");
 608  
                 OperationDesc desc;
 609  0
                 for (Iterator it = operations.iterator(); it.hasNext();)
 610  
                 {
 611  0
                     desc = (OperationDesc)it.next();
 612  0
                     response.write("<li>" + desc.getName());
 613  
                 }
 614  0
                 response.write("</ul>");
 615  
             }
 616  0
         }
 617  0
         response.write("</ul>");
 618  0
     }
 619  
 
 620  
     protected void reportCantGetAxisService(MuleEventContext context, AxisStringWriter response)
 621  
     {
 622  0
         response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404");
 623  0
         response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");
 624  0
         response.write("<h2>" + Messages.getMessage("error00") + "</h2>");
 625  0
         response.write("<p>" + Messages.getMessage("noService06") + "</p>");
 626  0
     }
 627  
 
 628  
     private void configureResponseFromAxisFault(AxisStringWriter response, AxisFault fault)
 629  
     {
 630  0
         int status = getHttpResponseStatus(fault);
 631  0
         if (status == 401)
 632  
         {
 633  0
             response.setProperty(HttpConstants.HEADER_WWW_AUTHENTICATE, "Basic realm=\"AXIS\"");
 634  
         }
 635  0
         response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, String.valueOf(status));
 636  0
     }
 637  
 
 638  
     private Message convertExceptionToAxisFault(Exception exception, Message responseMsg)
 639  
     {
 640  0
         logger.error(exception.getMessage(), exception);
 641  0
         if (responseMsg == null)
 642  
         {
 643  0
             AxisFault fault = AxisFault.makeFault(exception);
 644  0
             processAxisFault(fault);
 645  0
             responseMsg = new Message(fault);
 646  
         }
 647  0
         return responseMsg;
 648  
     }
 649  
 
 650  
     protected int getHttpResponseStatus(AxisFault af)
 651  
     {
 652  0
         return af.getFaultCode().getLocalPart().startsWith("Server.Unauth") ? 401 : '\u01F4';
 653  
     }
 654  
 
 655  
     private void sendResponse(String contentType,
 656  
                               AxisStringWriter response,
 657  
                               Message responseMsg) throws Exception
 658  
     {
 659  0
         if (responseMsg == null)
 660  
         {
 661  0
             response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "204");
 662  0
             if (logger.isDebugEnabled())
 663  
             {
 664  0
                 logger.debug("NO AXIS MESSAGE TO RETURN!");
 665  
             }
 666  
         }
 667  
         else
 668  
         {
 669  0
             if (logger.isDebugEnabled())
 670  
             {
 671  0
                 logger.debug("Returned Content-Type:" + contentType);
 672  
             }
 673  0
                 response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, contentType);
 674  0
                 ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
 675  0
                 responseMsg.writeTo(baos);
 676  0
                 response.write(baos.toString());
 677  
         }
 678  0
     }
 679  
 
 680  
     private void populateMessageContext(MessageContext msgContext,
 681  
                                         MuleEventContext context,
 682  
                                         EndpointURI endpointUri) throws AxisFault, ConfigurationException
 683  
     {
 684  0
         MuleMessage msg = context.getMessage();
 685  
 
 686  0
         if (logger.isDebugEnabled())
 687  
         {
 688  0
             logger.debug("MessageContext:" + msgContext);
 689  0
             logger.debug("HEADER_CONTENT_TYPE:" + msg.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
 690  0
             logger.debug("HEADER_CONTENT_LOCATION:" + msg.getInboundProperty(HttpConstants.HEADER_CONTENT_LOCATION));
 691  0
             logger.debug("Constants.MC_HOME_DIR:" + String.valueOf(getHomeDir()));
 692  0
             logger.debug("Constants.MC_RELATIVE_PATH:" + endpointUri.getPath());
 693  0
             logger.debug("HTTPConstants.HEADER_AUTHORIZATION:" + msg.getInboundProperty("Authorization"));
 694  0
             logger.debug("Constants.MC_REMOTE_ADDR:" + endpointUri.getHost());
 695  
         }
 696  
 
 697  0
         msgContext.setTransportName(transportName);
 698  0
         msgContext.setProperty("home.dir", getHomeDir());
 699  0
         msgContext.setProperty("path", endpointUri.getPath());
 700  0
         msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLET, this);
 701  0
         msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION, endpointUri.getPath());
 702  
         // determine service name
 703  0
         String serviceName = getServiceName(context, endpointUri);
 704  
         // Validate Service path against request path
 705  0
         SOAPService service = msgContext.getAxisEngine().getConfig().getService(
 706  
             new QName(serviceName.substring(1)));
 707  
 
 708  
         // if using jms or vm we can skip this
 709  0
         String scheme = endpointUri.getScheme();
 710  0
         if (!("vm".equalsIgnoreCase(scheme)
 711  
                         || "jms".equalsIgnoreCase(scheme)
 712  
                         || "servlet".equalsIgnoreCase(scheme)))
 713  
         {
 714  
             // Component Name is set by Mule so if its null we can skip this check
 715  0
             if (service.getOption(AxisConnector.SERVICE_PROPERTY_COMPONENT_NAME) != null)
 716  
             {
 717  0
                 String servicePath = (String)service.getOption("servicePath");
 718  0
                 if (StringUtils.isEmpty(endpointUri.getPath()))
 719  
                 {
 720  0
                     if (!("/" + endpointUri.getAddress()).startsWith(servicePath + serviceName))
 721  
                     {
 722  0
                         throw new AxisFault("Failed to find service: " + "/" + endpointUri.getAddress());
 723  
                     }
 724  
                 }
 725  
                 //We use ends with rather than starts with because if a servlet binding is used we do not have the full
 726  
                 //path info when the service is registered.  Track MULE-3931 for more info.
 727  0
                 else if (!endpointUri.getPath().endsWith(servicePath + serviceName))
 728  
                 {
 729  0
                     throw new AxisFault("Failed to find service: " + endpointUri.getPath());
 730  
                 }
 731  
             }
 732  
         }
 733  
 
 734  0
         msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, serviceName);
 735  0
         msgContext.setProperty("serviceName", serviceName);
 736  
 
 737  0
         msgContext.setProperty("Authorization", msg.getInboundProperty("Authorization"));
 738  0
         msgContext.setProperty("remoteaddr", endpointUri.getHost());
 739  0
         ServletEndpointContextImpl sec = new ServletEndpointContextImpl();
 740  0
         msgContext.setProperty("servletEndpointContext", sec);
 741  0
     }
 742  
 
 743  
     private String getSoapAction(MuleEventContext context) throws AxisFault
 744  
     {
 745  0
         String soapAction = context.getMessage().getInboundProperty(SoapConstants.SOAP_ACTION_PROPERTY_CAPS);
 746  0
         if (logger.isDebugEnabled())
 747  
         {
 748  0
             logger.debug("Header Soap Action:" + soapAction);
 749  
         }
 750  
 
 751  0
         if (StringUtils.isEmpty(soapAction))
 752  
         {
 753  0
             soapAction = context.getEndpointURI().getAddress();
 754  
         }
 755  0
         return soapAction;
 756  
     }
 757  
 
 758  
     protected String getServiceName(MuleEventContext context, EndpointURI endpointUri) throws AxisFault
 759  
     {
 760  0
         String serviceName = endpointUri.getPath();
 761  0
         if (StringUtils.isEmpty(serviceName))
 762  
         {
 763  0
             serviceName = getSoapAction(context);
 764  0
             serviceName = serviceName.replaceAll("\"", "");
 765  0
             int i = serviceName.indexOf("/", serviceName.indexOf("//"));
 766  0
             if (i < -1)
 767  
             {
 768  0
                 serviceName = serviceName.substring(i + 2);
 769  
             }
 770  
 
 771  
         }
 772  
 
 773  0
         int i = serviceName.lastIndexOf('/');
 774  0
         if (i > -1)
 775  
         {
 776  0
             serviceName = serviceName.substring(i);
 777  
         }
 778  0
         i = serviceName.lastIndexOf('?');
 779  0
         if (i > -1)
 780  
         {
 781  0
             serviceName = serviceName.substring(0, i);
 782  
         }
 783  0
         return serviceName;
 784  
     }
 785  
 
 786  
     public String getTransportName()
 787  
     {
 788  0
         return transportName;
 789  
     }
 790  
 
 791  
     public void setTransportName(String transportName)
 792  
     {
 793  0
         this.transportName = transportName;
 794  0
     }
 795  
 
 796  
     public boolean isEnableList()
 797  
     {
 798  0
         return enableList;
 799  
     }
 800  
 
 801  
     public void setEnableList(boolean enableList)
 802  
     {
 803  0
         this.enableList = enableList;
 804  0
     }
 805  
 
 806  
     public String getHomeDir()
 807  
     {
 808  0
         if (homeDir == null)
 809  
         {
 810  
             //TODO fix homeDir = muleContext.getConfiguration().getWorkingDirectory() + DEFAULT_AXIS_HOME;
 811  0
             homeDir = DEFAULT_AXIS_HOME;
 812  
         }
 813  0
         return homeDir;
 814  
     }
 815  
 
 816  
     public void setHomeDir(String homeDir)
 817  
     {
 818  0
         this.homeDir = homeDir;
 819  0
     }
 820  
 
 821  
     public AxisServer getAxis()
 822  
     {
 823  0
         return axis;
 824  
     }
 825  
 
 826  
     public void setAxis(AxisServer axisServer)
 827  
     {
 828  0
         this.axis = axisServer;
 829  0
     }
 830  
 }