📄 axisconnector.java
字号:
/* * $Id: AxisConnector.java 12420 2008-07-29 18:58:27Z tcarlson $ * -------------------------------------------------------------------------------------- * 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.api.MuleException;import org.mule.api.context.notification.MuleContextNotificationListener;import org.mule.api.context.notification.ServerNotification;import org.mule.api.endpoint.EndpointBuilder;import org.mule.api.endpoint.EndpointURI;import org.mule.api.endpoint.ImmutableEndpoint;import org.mule.api.endpoint.InboundEndpoint;import org.mule.api.lifecycle.InitialisationException;import org.mule.api.service.Service;import org.mule.api.transport.MessageReceiver;import org.mule.component.DefaultJavaComponent;import org.mule.config.ExceptionHelper;import org.mule.config.i18n.CoreMessages;import org.mule.context.notification.MuleContextNotification;import org.mule.endpoint.EndpointURIEndpointBuilder;import org.mule.model.seda.SedaService;import org.mule.object.SingletonObjectFactory;import org.mule.transport.AbstractConnector;import org.mule.transport.service.TransportFactory;import org.mule.transport.servlet.ServletConnector;import org.mule.transport.soap.axis.extensions.MuleConfigProvider;import org.mule.transport.soap.axis.extensions.MuleTransport;import org.mule.transport.soap.axis.extensions.WSDDFileProvider;import org.mule.transport.soap.axis.extensions.WSDDJavaMuleProvider;import org.mule.transport.soap.axis.i18n.AxisMessages;import org.mule.util.ClassUtils;import org.mule.util.MuleUrlStreamHandlerFactory;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.xml.namespace.QName;import org.apache.axis.client.Call;import org.apache.axis.configuration.SimpleProvider;import org.apache.axis.deployment.wsdd.WSDDConstants;import org.apache.axis.deployment.wsdd.WSDDProvider;import org.apache.axis.encoding.TypeMappingRegistryImpl;import org.apache.axis.encoding.ser.BeanDeserializerFactory;import org.apache.axis.encoding.ser.BeanSerializerFactory;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.server.AxisServer;import org.apache.axis.wsdl.fromJava.Namespaces;import org.apache.axis.wsdl.fromJava.Types;/** * <code>AxisConnector</code> is used to maintain one or more Services for Axis * server instance. * <p/> * Some of the Axis specific service initialisation code was adapted from the Ivory * project (http://ivory.codehaus.org). Thanks guys :) */public class AxisConnector extends AbstractConnector implements MuleContextNotificationListener{ /* Register the AxisFault Exception reader if this class gets loaded */ static { ExceptionHelper.registerExceptionReader(new AxisFaultExceptionReader()); } public static final QName QNAME_MULE_PROVIDER = new QName(WSDDConstants.URI_WSDD_JAVA, "Mule"); public static final QName QNAME_MULE_TYPE_MAPPINGS = new QName("http://www.muleumo.org/ws/mappings", "Mule"); public static final String DEFAULT_MULE_NAMESPACE_URI = "http://www.muleumo.org"; public static final String DEFAULT_MULE_AXIS_SERVER_CONFIG = "mule-axis-server-config.wsdd"; public static final String DEFAULT_MULE_AXIS_CLIENT_CONFIG = "mule-axis-client-config.wsdd"; public static final String AXIS_SERVICE_COMPONENT_NAME = "_axisServiceComponent"; public static final String AXIS_SERVICE_PROPERTY = "_axisService"; public static final String AXIS_CLIENT_CONFIG_PROPERTY = "clientConfig"; public static final String SERVICE_PROPERTY_COMPONENT_NAME = "componentName"; public static final String SERVICE_PROPERTY_SERVCE_PATH = "servicePath"; public static final String AXIS = "axis"; // used by dispatcher and receiver public static final String SOAP_METHODS = "soapMethods"; public static final String STYLE = "style"; public static final String USE = "use"; private String serverConfig = DEFAULT_MULE_AXIS_SERVER_CONFIG; private AxisServer axis = null; private SimpleProvider serverProvider = null; private String clientConfig = DEFAULT_MULE_AXIS_CLIENT_CONFIG; private SimpleProvider clientProvider = null; private List beanTypes; private Service axisComponent; //this will store the name of the descriptor of the current connector's AxisServiceComponent //private String specificAxisServiceComponentName; /** * These protocols will be set on client invocations. By default Mule uses it's * own transports rather that Axis's. This is only because it gives us more * flexibility inside Mule and simplifies the code */ private Map axisTransportProtocols = null; /** * A store of registered servlet services that need to have their endpoints * re-written with the 'real' http url instead of the servlet:// one. This is * only required to ensure wsdl is generated correctly. I would like a clearer * way of doing this so I can remove this workaround */ private List servletServices = new ArrayList(); private List supportedSchemes = null; private boolean doAutoTypes = true; private boolean treatMapAsNamedParams = true; public AxisConnector() { super(); this.registerProtocols(); } protected void registerProtocols() { if (supportedSchemes == null) { // Default supported schemes, these can be restricted // through configuration supportedSchemes = new ArrayList(); supportedSchemes.add("http"); supportedSchemes.add("https"); supportedSchemes.add("servlet"); supportedSchemes.add("vm"); supportedSchemes.add("jms"); supportedSchemes.add("xmpp"); supportedSchemes.add("ssl"); supportedSchemes.add("tcp"); supportedSchemes.add("smtp"); supportedSchemes.add("smtps"); supportedSchemes.add("pop3"); supportedSchemes.add("pop3s"); supportedSchemes.add("imap"); supportedSchemes.add("imaps"); } for (Iterator iterator = supportedSchemes.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); registerSupportedProtocol(s); } } protected void doInitialise() throws InitialisationException { axisTransportProtocols = new HashMap(); //specificAxisServiceComponentName = AXIS_SERVICE_COMPONENT_NAME + "_" + name; axisTransportProtocols = new HashMap(); try { for (Iterator iterator = supportedSchemes.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); axisTransportProtocols.put(s, MuleTransport.getTransportClass(s)); registerSupportedProtocol(s); } muleContext.registerListener(this); } catch (Exception e) { throw new InitialisationException(e, this); } // TODO DO: call registerSupportedProtocol if axisTransportProtocols are set from external? if (clientProvider == null) { clientProvider = createAxisProvider(clientConfig); } else { if (!DEFAULT_MULE_AXIS_CLIENT_CONFIG.equals(clientConfig)) { logger.warn(AxisMessages.clientProviderAndClientConfigConfigured()); } } if (axis == null) { if (serverProvider == null) { serverProvider = this.createAxisProvider(serverConfig); } else { if (!DEFAULT_MULE_AXIS_SERVER_CONFIG.equals(serverConfig)) { logger.warn(AxisMessages.serverProviderAndServerConfigConfigured()); } } // Create the AxisServer axis = new AxisServer(serverProvider); // principle of least surprise: doAutoTypes only has effect on our self-configured AxisServer axis.setOption("axis.doAutoTypes", Boolean.valueOf(doAutoTypes)); } // Register the Mule service serverProvider WSDDProvider.registerProvider(QNAME_MULE_PROVIDER, new WSDDJavaMuleProvider(this)); try { registerTransportTypes(); } catch (ClassNotFoundException e) { throw new InitialisationException( CoreMessages.cannotLoadFromClasspath(e.getMessage()), e, this); } // Register all our UrlStreamHandlers here so they can be resolved. This is necessary // to make Mule work in situations where modification of system properties at runtime // is not reliable, e.g. when running in maven's surefire test executor. MuleUrlStreamHandlerFactory.registerHandler("jms", new org.mule.transport.soap.axis.transport.jms.Handler()); MuleUrlStreamHandlerFactory.registerHandler("pop3", new org.mule.transport.soap.axis.transport.pop3.Handler()); MuleUrlStreamHandlerFactory.registerHandler("smtp", new org.mule.transport.soap.axis.transport.smtp.Handler()); MuleUrlStreamHandlerFactory.registerHandler("vm", new org.mule.transport.soap.axis.transport.vm.Handler()); try { registerTypes((TypeMappingRegistryImpl) axis.getTypeMappingRegistry(), beanTypes); } catch (ClassNotFoundException e) { throw new InitialisationException(e, this); } } protected void registerTransportTypes() throws ClassNotFoundException { // Register Transport handlers // By default these will all be handled by Mule, however some companies may // have their own they wish to use for (Iterator iterator = getAxisTransportProtocols().keySet().iterator(); iterator.hasNext();) { String protocol = (String) iterator.next(); Object temp = getAxisTransportProtocols().get(protocol); Class clazz; if (temp instanceof String) { clazz = ClassUtils.loadClass(temp.toString(), getClass()); } else { clazz = (Class) temp; } Call.setTransportForProtocol(protocol, clazz); } } protected SimpleProvider createAxisProvider(String config) throws InitialisationException { // Use our custom file provider that does not require services to be declared // in the WSDD. This only affects the // client side as the client will fallback to the FileProvider when invoking // a service. WSDDFileProvider fileProvider = new WSDDFileProvider(config); fileProvider.setSearchClasspath(true); /* * Wrap the FileProvider with a SimpleProvider so we can programmatically * configure the Axis server (you can only use wsdd descriptors with the * FileProvider) */ return new MuleConfigProvider(fileProvider); } public String getProtocol() { return AXIS; } /** * The method determines the key used to store the receiver against. * * @param component the component for which the endpoint is being registered * @param endpoint the endpoint being registered for the component * @return the key to store the newly created receiver against. In this case it * is the component name, which is equivalent to the Axis service name. */ protected Object getReceiverKey(Service component, InboundEndpoint endpoint) { if (endpoint.getEndpointURI().getPort() == -1) { return component.getName(); } else { return endpoint.getEndpointURI().getAddress() + "/" + component.getName(); } } protected void unregisterReceiverWithMuleService(MessageReceiver receiver, EndpointURI ep) throws MuleException { String endpointKey = getCounterEndpointKey(receiver.getEndpointURI()); for (Iterator iterator = axisComponent.getInboundRouter().getEndpoints().iterator(); iterator.hasNext();) { ImmutableEndpoint umoEndpoint = (ImmutableEndpoint) iterator.next(); if (endpointKey.startsWith(umoEndpoint.getEndpointURI().getAddress())) { logger.info("Unregistering Axis endpoint: " + endpointKey + " for service: " + ((AxisMessageReceiver) receiver).getSoapService().getName()); } try { umoEndpoint.getConnector() .unregisterListener(receiver.getService(), receiver.getEndpoint()); } catch (Exception e) { logger.error("Failed to unregister Axis endpoint: " + endpointKey + " for service: " + receiver.getService().getName() + ". Error is: " + e.getMessage(), e); } } } protected void registerReceiverWithMuleService(MessageReceiver receiver, EndpointURI ep)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -