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