⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 axisservicecomponent.java

📁 提供ESB 应用mule源代码 提供ESB 应用mule源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: AxisServiceComponent.java 11964 2008-06-05 19:31:23Z dfeist $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */package org.mule.transport.soap.axis;import org.mule.DefaultMuleMessage;import org.mule.RequestContext;import org.mule.api.MessagingException;import org.mule.api.MuleEventContext;import org.mule.api.MuleException;import org.mule.api.MuleMessage;import org.mule.api.config.MuleProperties;import org.mule.api.endpoint.EndpointException;import org.mule.api.endpoint.EndpointURI;import org.mule.api.lifecycle.Callable;import org.mule.api.lifecycle.Initialisable;import org.mule.api.lifecycle.InitialisationException;import org.mule.config.MuleManifest;import org.mule.config.i18n.CoreMessages;import org.mule.config.i18n.MessageFactory;import org.mule.endpoint.MuleEndpointURI;import org.mule.transport.WriterMessageAdapter;import org.mule.transport.http.HttpConnector;import org.mule.transport.http.HttpConstants;import org.mule.transport.soap.SoapConstants;import org.mule.transport.soap.axis.extensions.AxisMuleSession;import org.mule.transport.soap.axis.extensions.MuleConfigProvider;import org.mule.util.StringUtils;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.StringWriter;import java.util.ArrayList;import java.util.Iterator;import java.util.Map;import java.util.Properties;import javax.xml.namespace.QName;import org.apache.axis.AxisEngine;import org.apache.axis.AxisFault;import org.apache.axis.ConfigurationException;import org.apache.axis.Constants;import org.apache.axis.Message;import org.apache.axis.MessageContext;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.i18n.Messages;import org.apache.axis.security.servlet.ServletSecurityProvider;import org.apache.axis.server.AxisServer;import org.apache.axis.transport.http.HTTPConstants;import org.apache.axis.transport.http.ServletEndpointContextImpl;import org.apache.axis.utils.Admin;import org.apache.axis.utils.XMLUtils;import org.apache.commons.logging.Log;import org.w3c.dom.Document;/** * <code>AxisServiceComponent</code> is a Mule component implementation of the Axis * servlet. This component supports all the features of the Axis servlet except - * <ol> * <li>Jws class services are not supported as they don't add any value to the Mule * model</li> * <li>Currently there is no HttpSession support. This will be fixed when MuleSession * support is added to the Http Connector</li> * </ol> */public class AxisServiceComponent implements Initialisable, Callable{    protected static final Log logger = org.apache.commons.logging.LogFactory.getLog(AxisServiceComponent.class);    public static final String INIT_PROPERTY_TRANSPORT_NAME = "transport.name";    public static final String INIT_PROPERTY_USE_SECURITY = "use-servlet-security";    public static final String INIT_PROPERTY_ENABLE_LIST = "axis.enableListQuery";    public static final String DEFAULT_AXIS_HOME = "/axisHome";    private String transportName = "http";    private ServletSecurityProvider securityProvider = null;    private boolean enableList = true;    private String homeDir;    private AxisServer axis;    /** For IoC */    public AxisServiceComponent()    {        // do nothing    }    /**     * Passes the context to the listener     *      * @param context the context to process     * @return Object this object can be anything. When the     *         <code>LifecycleAdapter</code> for the component receives this     *         object it will first see if the Object is an <code>MuleEvent</code>     *         if not and the Object is not null a new context will be created using     *         the returned object as the payload. This new context will then get     *         published to the configured outbound endpoint if-     *         <ol>     *         <li>One has been configured for the UMO.</li>     *         <li>the <code>setStopFurtherProcessing(true)</code> wasn't called     *         on the previous context.</li>     *         </ol>     * @throws Exception if the context fails to process properly. If exceptions     *             aren't handled by the implementation they will be handled by the     *             exceptionListener associated with the component     */    public Object onCall(MuleEventContext context) throws Exception    {        WriterMessageAdapter response = new WriterMessageAdapter(new StringWriter(4096));        String method = context.getMessage().getStringProperty(HttpConnector.HTTP_METHOD_PROPERTY,            HttpConstants.METHOD_POST);        if (HttpConstants.METHOD_GET.equalsIgnoreCase(method))        {            doGet(context, response);        }        else        {            doPost(context, response);        }        response.getWriter().close();        return new DefaultMuleMessage(response);    }    public void initialise() throws InitialisationException    {        if (axis == null)        {            throw new InitialisationException(MessageFactory.createStaticMessage("No Axis instance, this component has not been initialized properly."), this);        }    }    public void doGet(MuleEventContext context, WriterMessageAdapter response)        throws MuleException, IOException    {        try        {            // We parse a new uri based on the listening host and port with the            // request parameters appended            // Using the soap prefix ensures that we use a soap endpoint builder            EndpointURI endpointUri = context.getEndpointURI();            if (!"servlet".equalsIgnoreCase(context.getEndpointURI().getSchemeMetaInfo()))            {                String uri = SoapConstants.SOAP_ENDPOINT_PREFIX + context.getEndpointURI().getScheme()                                + "://" + context.getEndpointURI().getHost() + ":"                                + context.getEndpointURI().getPort();                uri += context.getMessage().getStringProperty(HttpConnector.HTTP_REQUEST_PROPERTY, "");                endpointUri = new MuleEndpointURI(uri);                endpointUri.initialise();            }            AxisEngine engine = getAxis();            String pathInfo = endpointUri.getPath();            boolean wsdlRequested = false;            boolean listRequested = false;            if (endpointUri.getAddress().endsWith(".jws"))            {                throw new AxisFault("Jws not supported by the Mule Axis service");            }            String queryString = endpointUri.getQuery();            if (queryString != null)            {                if (queryString.equalsIgnoreCase(SoapConstants.WSDL_PROPERTY))                {                    wsdlRequested = true;                }                else                {                    if (queryString.equalsIgnoreCase(SoapConstants.LIST_PROPERTY))                    {                        listRequested = true;                    }                }            }            boolean hasNoPath = (StringUtils.isEmpty(pathInfo) || pathInfo.equals("/"));            if (!wsdlRequested && !listRequested && hasNoPath)            {                reportAvailableServices(context, response);            }            else            {                MessageContext msgContext = new MessageContext(engine);                populateMessageContext(msgContext, context, endpointUri);                msgContext.setProperty("transport.url", endpointUri.toString());                if (wsdlRequested)                {                    processWsdlRequest(msgContext, response);                }                else if (listRequested)                {                    processListRequest(response);                }                else                {                    processMethodRequest(msgContext, context, response, endpointUri);                }            }        }        catch (AxisFault fault)        {            reportTroubleInGet(fault, response);        }        catch (Exception e)        {            reportTroubleInGet(e, response);        }    }    private void reportTroubleInGet(Exception exception, WriterMessageAdapter response)    {        response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html");        response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500");        response.write("<h2>" + Messages.getMessage("error00") + "</h2>");        response.write("<p>" + Messages.getMessage("somethingWrong00") + "</p>");        if (exception instanceof AxisFault)        {            AxisFault fault = (AxisFault)exception;            processAxisFault(fault);            writeFault(response, fault);        }        else        {            logger.error(exception.getMessage(), exception);            response.write("<pre>Exception - " + exception + "<br>");            response.write("</pre>");        }    }    protected void processAxisFault(AxisFault fault)    {        org.w3c.dom.Element runtimeException = fault            .lookupFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);        if (runtimeException != null)        {            logger.info(Messages.getMessage("axisFault00"), fault);            fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);        }        else if (logger.isDebugEnabled())        {            logger.debug(Messages.getMessage("axisFault00"), fault);        }    }    private void writeFault(WriterMessageAdapter response, AxisFault axisFault)    {        String localizedMessage = XMLUtils.xmlEncodeString(axisFault.getLocalizedMessage());        response.write("<pre>Fault - " + localizedMessage + "<br>");        response.write(axisFault.dumpToString());        response.write("</pre>");    }    protected void processMethodRequest(MessageContext msgContext,                                        MuleEventContext context,                                        WriterMessageAdapter response,                                        EndpointURI endpointUri) throws AxisFault    {        Properties params = endpointUri.getUserParams();        String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY);        if (method == null)        {            method = endpointUri.getPath().substring(endpointUri.getPath().lastIndexOf("/") + 1);        }        StringBuffer args = new StringBuffer(64);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -