diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src')
11 files changed, 728 insertions, 1240 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java index fe10e6a4eb..58de97d74b 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java @@ -41,10 +41,6 @@ import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; -import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingBasicAuthenticationConfigurator; -import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; -import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; import org.apache.tuscany.sca.interfacedef.util.FaultException; import org.apache.tuscany.sca.invocation.DataExchangeSemantics; import org.apache.tuscany.sca.invocation.Invoker; @@ -77,8 +73,8 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { private WebServiceBinding wsBinding; private BasicAuthenticationPolicy basicAuthenticationPolicy = null; - private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; - private List<Axis2HeaderPolicy> axis2HeaderPolicies = new ArrayList<Axis2HeaderPolicy>(); +// private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; +// private List<Axis2HeaderPolicy> axis2HeaderPolicies = new ArrayList<Axis2HeaderPolicy>(); public Axis2BindingInvoker(Axis2ServiceClient serviceClient, QName wsdlOperationName, @@ -149,6 +145,7 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { */ // set policy specified headers +/* for (Axis2HeaderPolicy policy : axis2HeaderPolicies){ Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, policy.getHeaderName()); } @@ -160,6 +157,7 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { if (axis2TokenAuthenticationPolicy != null) { Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, axis2TokenAuthenticationPolicy.getTokenName()); } +*/ // Allow privileged access to read properties. Requires PropertiesPermission read in // security policy. diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java deleted file mode 100644 index a7dc09ea6d..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.ws.axis2; - -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.deployment.URLBasedAxisConfigurator; -import org.apache.tuscany.sca.extensibility.ClassLoaderContext; -import org.oasisopen.sca.ServiceRuntimeException; - -/** - * The Helper class that loades the Axis2 configuration from the axis2.xml - */ -public class Axis2ConfiguratorHelper { - - /** - * We cannot hold this method directly in the {@link TuscanyAxisConfigurator} class as the super class - * uses the TCCL to load classes - * - * @param isRampartRequired - * @return - */ - public static ConfigurationContext getAxis2ConfigurationContext(final boolean isRampartRequired) { - try { - // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); - // Allow privileged access to read properties. Requires PropertyPermission read in - // security policy. - ConfigurationContext configContext = - AccessController.doPrivileged(new PrivilegedExceptionAction<ConfigurationContext>() { - public ConfigurationContext run() throws AxisFault { - // The tuscany-binding-ws-axis2 class loader. We contribute the message - // receivers in the axis2.xml - ClassLoader cl0 = getClass().getClassLoader(); - - // The axis2 class loader - ClassLoader cl1 = URLBasedAxisConfigurator.class.getClassLoader(); - - ClassLoader tccl = ClassLoaderContext.setContextClassLoader(cl0, cl1); - - try { - return new TuscanyAxisConfigurator(isRampartRequired).getConfigurationContext(); - } finally { - if (tccl != null) { - Thread.currentThread().setContextClassLoader(tccl); - } - } - } - }); - return configContext; - // deployRampartModule(); - // configureSecurity(); - } catch (PrivilegedActionException e) { - throw new ServiceRuntimeException(e.getException()); - } - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java new file mode 100644 index 0000000000..8cd963f4ca --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java @@ -0,0 +1,656 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.Constants.Configuration; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.util.Utils; +import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.description.TransportOutDescription; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.transport.jms.JMSListener; +import org.apache.axis2.transport.jms.JMSSender; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.AssemblyFactory; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceClient.URIResolverImpl; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class Axis2EngineIntegration { + private static final Logger logger = Logger.getLogger(Axis2EngineIntegration.class.getName()); + + private ConfigurationContext configContext; + + //============================ + + public static final String IMPORT_TAG = "import"; + public static final String INCLUDE_TAG = "include"; + + private RuntimeEndpoint endpoint; + private RuntimeComponent component; + private AbstractContract contract; + private WebServiceBinding wsBinding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private FactoryExtensionPoint modelFactories; + private RuntimeAssemblyFactory assemblyFactory; + + private JMSSender jmsSender; + private JMSListener jmsListener; + private Map<String, Port> urlMap = new HashMap<String, Port>(); + + + public static final QName QNAME_WSA_ADDRESS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM); + public static final QName QNAME_WSA_REFERENCE_PARAMETERS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS); + + private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = + new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912", "transport.jms"); + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + + //Schema element names + public static final String ELEM_SCHEMA = "schema"; + + //Schema URI + public static final String NS_URI_XSD_1999 = "http://www.w3.org/1999/XMLSchema"; + public static final String NS_URI_XSD_2000 = "http://www.w3.org/2000/10/XMLSchema"; + public static final String NS_URI_XSD_2001 = "http://www.w3.org/2001/XMLSchema"; + + //Schema QNames + public static final QName Q_ELEM_XSD_1999 = new QName(NS_URI_XSD_1999, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2000 = new QName(NS_URI_XSD_2000, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2001 = new QName(NS_URI_XSD_2001, ELEM_SCHEMA); + public static final List<QName> XSD_QNAME_LIST = + Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); + + /** + * Construct the service provider. This creates the base configuration for + * Axis2 but with no services deployed yet. + * + * @param endpoint + * @param component + * @param contract + * @param wsBinding + * @param servletHost + * @param messageFactory + * @param modelFactories + */ + public Axis2EngineIntegration(RuntimeEndpoint endpoint, + RuntimeComponent component, + AbstractContract contract, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory, + final FactoryExtensionPoint modelFactories) { + this.endpoint = endpoint; + this.component = component; + this.contract = contract; + this.wsBinding = wsBinding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.modelFactories = modelFactories; + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + + final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding); + + // get the axis configuration context from the Tuscany axis2.xml file + // TODO - java security + ClassLoader wsBindingCL = getClass().getClassLoader(); + + // TODO - taken the Tuscany configurator out for a while + // but may need to re-introduce a simplified version if we feel + // that it's important to not deploy rampart when it's not required + try { + URL axis2xmlURL = wsBindingCL.getResource("org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml"); + if (axis2xmlURL != null){ + URL repositoryURL = new URL(axis2xmlURL.toExternalForm().replaceFirst("conf/tuscany-axis2.xml", "repository")); + configContext = ConfigurationContextFactory.createConfigurationContextFromURIs(axis2xmlURL, repositoryURL); + } else { + // throw an exception + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + // set the root context for this instance of Axis + configContext.setContextRoot(servletHost.getContextPath()); + + // TODO - Cycle through all policy providers asking if there is configuration + // todo. Should this be in the + // MTOM + // JMS + // Security (turn rampart on) + // Enable MTOM if the policy intent is specified. + if (AxisPolicyHelper.isIntentRequired(wsBinding, AxisPolicyHelper.MTOM_INTENT)) { + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setLocked(false); + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setValue("true"); + } + + // Update port addresses with runtime information, and create a + // map from endpoint URIs to WSDL ports that eliminates duplicate + // ports for the same endpoint. + for (Object port : wsBinding.getService().getPorts().values()) { + String portAddress = getPortAddress((Port)port); + String endpointURI = computeEndpointURI(portAddress, servletHost); + setPortAddress((Port)port, endpointURI); + urlMap.put(endpointURI, (Port)port); + } + + } + + + static String getPortAddress(Port port) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + return ((SOAPAddress)ext).getLocationURI(); + } + if (ext instanceof SOAP12Address) { + return ((SOAP12Address)ext).getLocationURI(); + } + return null; + } + + static void setPortAddress(Port port, String locationURI) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + ((SOAPAddress)ext).setLocationURI(locationURI); + } + if (ext instanceof SOAP12Address) { + ((SOAP12Address)ext).setLocationURI(locationURI); + } + } + + private String computeEndpointURI(String uri, ServletHost servletHost) { + + if (uri == null) { + return null; + } + + // pull out the binding intents to see what sort of transport is required + PolicySet transportJmsPolicySet = AxisPolicyHelper.getPolicySet(wsBinding, TRANSPORT_JMS_QUALIFIED_INTENT); + if (transportJmsPolicySet != null) { + if (!uri.startsWith("jms:/")) { + uri = "jms:" + uri; + } + + // construct the rest of the URI based on the policy. All the details are put + // into the URI here rather than being place directly into the Axis configuration + // as the Axis JMS sender relies on parsing the target URI +/* + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + for (Object policy : transportJmsPolicySet.getPolicies()) { + if (policy instanceof Axis2ConfigParamPolicy) { + axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + Iterator paramIterator = + axis2ConfigParamPolicy.getParamElements().get(DEFAULT_QUEUE_CONNECTION_FACTORY) + .getChildElements(); + + if (paramIterator.hasNext()) { + StringBuffer uriParams = new StringBuffer("?"); + + while (paramIterator.hasNext()) { + OMElement parameter = (OMElement)paramIterator.next(); + uriParams.append(parameter.getAttributeValue(new QName("", "name"))); + uriParams.append("="); + uriParams.append(parameter.getText()); + + if (paramIterator.hasNext()) { + uriParams.append("&"); + } + } + + uri = uri + uriParams; + } + } + } +*/ + } else { + if (!uri.startsWith("jms:")) { + uri = servletHost.getURLMapping(uri).toString(); + } + } + + return uri; + } + + /** + * Add the Tuscany services that this binding instance represents to the + * Axis runtime. + */ + public void start() { + + try { + //createPolicyHandlers(); + for (Map.Entry<String, Port> entry : urlMap.entrySet()) { + AxisService axisService = createAxisService(entry.getKey(), entry.getValue()); + configContext.getAxisConfiguration().addService(axisService); + } + + Axis2ServiceServlet servlet = null; + for (String endpointURL : urlMap.keySet()) { + if (endpointURL.startsWith("http://") || endpointURL.startsWith("https://") + || endpointURL.startsWith("/")) { + if (servlet == null) { + servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + } + //[nash] configContext.setContextRoot(endpointURL); + servletHost.addServletMapping(endpointURL, servlet); + } else if (endpointURL.startsWith("jms")) { + logger.log(Level.INFO, "Axis2 JMS URL=" + endpointURL); + + jmsListener = new JMSListener(); + jmsSender = new JMSSender(); + ListenerManager listenerManager = configContext.getListenerManager(); + TransportInDescription trsIn = + configContext.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_JMS); + + // get JMS transport parameters from the computed URL +// not in Axis2 1.5.1 +// Map<String, String> jmsProps = JMSUtils.getProperties(endpointURL); + + // collect the parameters used to configure the JMS transport + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement parms = fac.createOMElement(DEFAULT_QUEUE_CONNECTION_FACTORY, null); +/* + for (String key : jmsProps.keySet()) { + OMElement param = fac.createOMElement("parameter", null); + param.addAttribute("name", key, null); + param.addChild(fac.createOMText(param, jmsProps.get(key))); + parms.addChild(param); + } +*/ + Parameter queueConnectionFactory = new Parameter(DEFAULT_QUEUE_CONNECTION_FACTORY, parms); + trsIn.addParameter(queueConnectionFactory); + + trsIn.setReceiver(jmsListener); + + configContext.getAxisConfiguration().addTransportIn(trsIn); + TransportOutDescription trsOut = + configContext.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_JMS); + //configContext.getAxisConfiguration().addTransportOut( trsOut ); + trsOut.setSender(jmsSender); + + if (listenerManager == null) { + listenerManager = new ListenerManager(); + listenerManager.init(configContext); + } + listenerManager.addListener(trsIn, true); + jmsSender.init(configContext, trsOut); + jmsListener.init(configContext, trsIn); + jmsListener.start(); + } + } + } catch (AxisFault e) { + throw new RuntimeException(e); + } +/* + catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } +*/ + } + + + public void stop() { + if (jmsListener != null) { +// jmsListener.stop(); + jmsListener.destroy(); + } else { + for (String endpointURL : urlMap.keySet()) { + servletHost.removeServletMapping(endpointURL); + } + } + + servletHost = null; + + if (jmsSender != null) + jmsSender.stop(); + + try { + for (String endpointURL : urlMap.keySet()) { + // get the path to the service + URI uriPath = new URI(endpointURL); + String stringURIPath = uriPath.getPath(); + + /* [nash] Need a leading slash for WSDL imports to work with ?wsdl + // remove any "/" from the start of the path + if (stringURIPath.startsWith("/")) { + stringURIPath = stringURIPath.substring(1, stringURIPath.length()); + } + */ + + configContext.getAxisConfiguration().removeService(stringURIPath); + } + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + private AxisService createAxisService(String endpointURL, Port port) throws AxisFault { + AxisService axisService; + if (wsBinding.getWSDLDocument() != null) { + axisService = createWSDLAxisService(endpointURL, port); + } else { + axisService = createJavaAxisService(endpointURL); + } + initAxisOperations(axisService); + return axisService; + } + + /** + * Create an AxisService from the interface class from the SCA service interface + */ + protected AxisService createJavaAxisService(String endpointURL) throws AxisFault { + + AxisService axisService = new AxisService(); + String path = URI.create(endpointURL).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + endpointURL); + axisService.setClientSide(false); + Parameter classParam = + new Parameter(Constants.SERVICE_CLASS, ((JavaInterface)contract.getInterfaceContract().getInterface()) + .getJavaClass().getName()); + axisService.addParameter(classParam); + try { + Utils.fillAxisService(axisService, configContext.getAxisConfiguration(), null, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + + return axisService; + } + + /** + * Create an AxisService from the WSDL doc used by ws binding + */ + protected AxisService createWSDLAxisService(String endpointURL, Port port) throws AxisFault { + + Definition definition = wsBinding.getWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Definition def = getDefinition(definition, serviceQName); + + final WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(def, serviceQName, port.getName()); + builder.setServerSide(true); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + builder.setCustomResolver(new URIResolverImpl(def)); + builder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // AxisService axisService = builder.populateService(); + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction<AxisService>() { + public AxisService run() throws AxisFault { + return builder.populateService(); + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + String name = URI.create(endpointURL).getPath(); + //[nash] HTTP endpoints need a leading slash for WSDL imports to work with ?wsdl + if (endpointURL.startsWith("jms")) { + name = name.startsWith("/") ? name.substring(1) : name; + } + axisService.setName(name); + axisService.setEndpointURL(endpointURL); + axisService.setDocumentation("Tuscany configured AxisService for service: " + endpointURL); + for (Iterator i = axisService.getEndpoints().values().iterator(); i.hasNext();) { + AxisEndpoint ae = (AxisEndpoint)i.next(); + if (endpointURL.startsWith("jms")) { +// not in Axis2 1.5.1 +// Parameter qcf = new Parameter(JMSConstants.CONFAC_PARAM, null); +// qcf.setValue(DEFAULT_QUEUE_CONNECTION_FACTORY); +// axisService.addParameter(qcf); + break; + } + } + + // Add schema information to the AxisService (needed for "?xsd=" support) + addSchemas(wsBinding.getWSDLDefinition(), axisService); + + // Use the existing WSDL + Parameter wsdlParam = new Parameter("wsdl4jDefinition", null); + wsdlParam.setValue(definition); + axisService.addParameter(wsdlParam); + Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); + axisService.addParameter(userWSDL); + + // Modify schema imports and includes to add "servicename?xsd=" prefix. + // Axis2 does this for schema extensibility elements, but Tuscany has + // overriden the WSDl4J deserializer to create UnknownExtensibilityElement + // elements in place of these. + modifySchemaImportsAndIncludes(definition, name); + + // Axis2 1.3 has a bug with returning incorrect values for the port + // addresses. To work around this, compute the values here. + Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); + axisService.addParameter(modifyAddr); + + return axisService; + } + + /** + * Workaround for https://issues.apache.org/jira/browse/AXIS2-3205 + * @param definition + * @param serviceName + * @return + */ + private static Definition getDefinition(Definition definition, QName serviceName) { + + if (serviceName == null) { + return definition; + } + + if (definition == null) { + return null; + } + Object service = definition.getServices().get(serviceName); + if (service != null) { + return definition; + } + for (Object i : definition.getImports().values()) { + List<Import> imports = (List<Import>)i; + for (Import imp : imports) { + Definition d = getDefinition(imp.getDefinition(), serviceName); + if (d != null) { + return d; + } + } + } + return null; + } + + private void addSchemas(WSDLDefinition wsdlDef, AxisService axisService) { + for (XSDefinition xsDef : wsdlDef.getXmlSchemas()) { + if (xsDef.getSchema() != null) { + axisService.addSchema(xsDef.getSchema()); + updateSchemaRefs(xsDef.getSchema(), axisService.getName()); + } + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + addSchemas(impDef, axisService); + } + } + + private void updateSchemaRefs(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + String location = extSchema.getSchemaLocation(); + if (location.length() > 0 && location.indexOf(":/") < 0 && location.indexOf("?xsd=") < 0) { + extSchema.setSchemaLocation(name + "?xsd=" + location); + } + if (extSchema.getSchema() != null) { + updateSchemaRefs(extSchema.getSchema(), name); + } + } + } + } + + private void modifySchemaImportsAndIncludes(Definition definition, String name) { + // adjust the schema locations in types section + Types types = definition.getTypes(); + if (types != null) { + for (Iterator iter = types.getExtensibilityElements().iterator(); iter.hasNext();) { + Object ext = iter.next(); + if (ext instanceof UnknownExtensibilityElement && XSD_QNAME_LIST + .contains(((UnknownExtensibilityElement)ext).getElementType())) { + changeLocations(((UnknownExtensibilityElement)ext).getElement(), name); + } + } + } + for (Iterator iter = definition.getImports().values().iterator(); iter.hasNext();) { + Vector values = (Vector)iter.next(); + for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { + Import wsdlImport = (Import)valuesIter.next(); + modifySchemaImportsAndIncludes(wsdlImport.getDefinition(), name); + } + } + } + + private void changeLocations(Element element, String name) { + NodeList nodeList = element.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + String tagName = nodeList.item(i).getLocalName(); + if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) { + processImport(nodeList.item(i), name); + } + } + } + + private void processImport(Node importNode, String name) { + NamedNodeMap nodeMap = importNode.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Node attribute = nodeMap.item(i); + if (attribute.getNodeName().equals("schemaLocation")) { + String location = attribute.getNodeValue(); + if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { + attribute.setNodeValue(name + "?xsd=" + location); + } + } + } + } + + protected void initAxisOperations(AxisService axisService) { + for (Iterator<?> i = axisService.getOperations(); i.hasNext();) { + AxisOperation axisOp = (AxisOperation)i.next(); + Operation op = getOperation(axisOp); + if (op != null) { + + if (op.isNonBlocking()) { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY); + } else { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT); + } + + MessageReceiver msgrec = null; + Axis2ServiceProvider serviceProvider = new Axis2ServiceProvider(endpoint, wsBinding, messageFactory, modelFactories); + if (op.isNonBlocking()) { + msgrec = new Axis2ServiceInMessageReceiver(serviceProvider, op); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(serviceProvider, op); + } + axisOp.setMessageReceiver(msgrec); + } + } + } + + protected Operation getOperation(AxisOperation axisOp) { + String operationName = axisOp.getName().getLocalPart(); + Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); + for (Operation op : iface.getOperations()) { + if (op.getName().equalsIgnoreCase(operationName)) { + return op; + } + } + return null; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java index a0dea01cd2..da05b07d3a 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java @@ -37,7 +37,7 @@ public class Axis2ServiceBindingProvider implements ServiceBindingProvider { private RuntimeComponentService service; private WebServiceBinding wsBinding; - private Axis2ServiceProvider axisProvider; + private Axis2EngineIntegration axisProvider; public Axis2ServiceBindingProvider(RuntimeEndpoint endpoint, ServletHost servletHost, @@ -62,7 +62,7 @@ public class Axis2ServiceBindingProvider implements ServiceBindingProvider { InterfaceContract contract = wsBinding.getBindingInterfaceContract(); contract.getInterface().resetDataBinding(OMElement.class.getName()); - axisProvider = new Axis2ServiceProvider(endpoint, component, service, wsBinding, servletHost, messageFactory, modelFactories); + axisProvider = new Axis2EngineIntegration(endpoint, component, service, wsBinding, servletHost, messageFactory, modelFactories); } public void start() { diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java index be4e902eaa..e3b02a5bd5 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.binding.ws.axis2; -import static org.apache.tuscany.sca.binding.ws.axis2.Axis2ConfiguratorHelper.getAxis2ConfigurationContext; import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.SOAP12_INTENT; import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.isIntentRequired; @@ -57,6 +56,7 @@ import org.apache.axis2.addressing.EndpointReferenceHelper; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.description.AxisEndpoint; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; @@ -69,7 +69,6 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; @@ -110,6 +109,7 @@ public class Axis2ServiceClient { if (ps == null) { return; } +/* for (Object policy : ps.getPolicies()) { if (policy instanceof Axis2ConfigParamPolicy) { Axis2ConfigParamPolicy axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; @@ -120,6 +120,7 @@ public class Axis2ServiceClient { } } } +*/ } /** @@ -128,8 +129,26 @@ public class Axis2ServiceClient { protected ServiceClient createServiceClient() { try { final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding); - ConfigurationContext configContext = - getAxis2ConfigurationContext(isRampartRequired); + ConfigurationContext configContext = null; + + // get the axis configuration context from the Tuscany axis2.xml file + // TODO - java security + ClassLoader wsBindingCL = getClass().getClassLoader(); + + // TODO - taken the Tuscany configurator out for a while + // but may need to re-introduce a simplified version if we feel + // that it's important to not deploy rampart when it's not required + try { + URL axis2xmlURL = wsBindingCL.getResource("org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml"); + if (axis2xmlURL != null){ + URL repositoryURL = new URL(axis2xmlURL.toExternalForm().replaceFirst("conf/tuscany-axis2.xml", "repository")); + configContext = ConfigurationContextFactory.createConfigurationContextFromURIs(axis2xmlURL, repositoryURL); + } else { + // throw an exception + } + } catch (Exception ex) { + ex.printStackTrace(); + } createPolicyHandlers(); diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java index 1e62916818..13a4033a0a 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -19,633 +19,68 @@ package org.apache.tuscany.sca.binding.ws.axis2; -import static org.apache.tuscany.sca.binding.ws.axis2.Axis2ConfiguratorHelper.getAxis2ConfigurationContext; - import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; -import java.util.logging.Level; import java.util.logging.Logger; -import javax.wsdl.Definition; -import javax.wsdl.Import; -import javax.wsdl.Port; -import javax.wsdl.Types; -import javax.wsdl.extensions.UnknownExtensibilityElement; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.annotation.Resource; import javax.xml.namespace.QName; +import javax.xml.ws.Provider; +import javax.xml.ws.WebServiceContext; -import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; import org.apache.axiom.soap.SOAPHeader; -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.Constants.Configuration; import org.apache.axis2.addressing.AddressingConstants; -import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; -import org.apache.axis2.deployment.util.Utils; -import org.apache.axis2.description.AxisEndpoint; -import org.apache.axis2.description.AxisOperation; -import org.apache.axis2.description.AxisService; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.description.TransportInDescription; -import org.apache.axis2.description.TransportOutDescription; -import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; -import org.apache.axis2.description.WSDL2Constants; -import org.apache.axis2.description.WSDLToAxisServiceBuilder; -import org.apache.axis2.engine.ListenerManager; -import org.apache.axis2.engine.MessageReceiver; -import org.apache.axis2.transport.jms.JMSConstants; -import org.apache.axis2.transport.jms.JMSListener; -import org.apache.axis2.transport.jms.JMSSender; -import org.apache.axis2.transport.jms.JMSUtils; -import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceClient.URIResolverImpl; -import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; -import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; -import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; -import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; -import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; -import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -import org.apache.tuscany.sca.xsd.XSDefinition; -import org.apache.ws.commons.schema.XmlSchema; -import org.apache.ws.commons.schema.XmlSchemaExternal; -import org.apache.ws.security.WSSecurityEngineResult; -import org.apache.ws.security.handler.WSHandlerConstants; -import org.apache.ws.security.handler.WSHandlerResult; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class Axis2ServiceProvider { - public static final String IMPORT_TAG = "import"; - public static final String INCLUDE_TAG = "include"; +public class Axis2ServiceProvider implements Provider<OMElement> { private static final Logger logger = Logger.getLogger(Axis2ServiceProvider.class.getName()); - - private RuntimeEndpoint endpoint; - private RuntimeComponent component; - private AbstractContract contract; - private WebServiceBinding wsBinding; - private ServletHost servletHost; - private MessageFactory messageFactory; - private FactoryExtensionPoint modelFactories; - private RuntimeAssemblyFactory assemblyFactory; - private ConfigurationContext configContext; - private JMSSender jmsSender; - private JMSListener jmsListener; - private Map<String, Port> urlMap = new HashMap<String, Port>(); - - private BasicAuthenticationPolicy basicAuthenticationPolicy = null; - private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; - private List<Axis2HeaderPolicy> axis2HeaderPolicies = new ArrayList<Axis2HeaderPolicy>(); - + public static final QName QNAME_WSA_ADDRESS = new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); public static final QName QNAME_WSA_FROM = new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM); public static final QName QNAME_WSA_REFERENCE_PARAMETERS = new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS); - - private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = - new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912", "transport.jms"); - private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; - - //Schema element names - public static final String ELEM_SCHEMA = "schema"; - - //Schema URI - public static final String NS_URI_XSD_1999 = "http://www.w3.org/1999/XMLSchema"; - public static final String NS_URI_XSD_2000 = "http://www.w3.org/2000/10/XMLSchema"; - public static final String NS_URI_XSD_2001 = "http://www.w3.org/2001/XMLSchema"; - - //Schema QNames - public static final QName Q_ELEM_XSD_1999 = new QName(NS_URI_XSD_1999, ELEM_SCHEMA); - public static final QName Q_ELEM_XSD_2000 = new QName(NS_URI_XSD_2000, ELEM_SCHEMA); - public static final QName Q_ELEM_XSD_2001 = new QName(NS_URI_XSD_2001, ELEM_SCHEMA); - public static final List<QName> XSD_QNAME_LIST = - Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); - + + + private RuntimeEndpoint endpoint; + private WebServiceBinding wsBinding; + private MessageFactory messageFactory; + private FactoryExtensionPoint modelFactories; + private RuntimeAssemblyFactory assemblyFactory; + + @Resource + WebServiceContext wsContext; + public Axis2ServiceProvider(RuntimeEndpoint endpoint, - RuntimeComponent component, - AbstractContract contract, WebServiceBinding wsBinding, - ServletHost servletHost, MessageFactory messageFactory, - final FactoryExtensionPoint modelFactories) { + FactoryExtensionPoint modelFactories) { this.endpoint = endpoint; - this.component = component; - this.contract = contract; this.wsBinding = wsBinding; - this.servletHost = servletHost; this.messageFactory = messageFactory; this.modelFactories = modelFactories; - this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); - - final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding); - configContext = getAxis2ConfigurationContext(isRampartRequired); - - configContext.setContextRoot(servletHost.getContextPath()); - - // Enable MTOM if the policy intent is specified. - if (AxisPolicyHelper.isIntentRequired(wsBinding, AxisPolicyHelper.MTOM_INTENT)) { - configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setLocked(false); - configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setValue("true"); - } - - // Update port addresses with runtime information, and create a - // map from endpoint URIs to WSDL ports that eliminates duplicate - // ports for the same endpoint. - for (Object port : wsBinding.getService().getPorts().values()) { - String portAddress = getPortAddress((Port)port); - String endpointURI = computeEndpointURI(portAddress, servletHost); - setPortAddress((Port)port, endpointURI); - urlMap.put(endpointURI, (Port)port); - } - - /* - // find out which policies are active - if (wsBinding instanceof PolicySubject) { - List<PolicySet> policySets = ((PolicySubject)wsBinding).getApplicablePolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (BasicAuthenticationPolicy.class.isInstance(p)) { - basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; - } else if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { - axis2TokenAuthenticationPolicy = (Axis2TokenAuthenticationPolicy)p; - } else if (Axis2HeaderPolicy.class.isInstance(p)) { - axis2HeaderPolicies.add((Axis2HeaderPolicy)p); - } else { - // etc. check for other types of policy being present - } - } - } - } - */ + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); } - - static String getPortAddress(Port port) { - Object ext = port.getExtensibilityElements().get(0); - if (ext instanceof SOAPAddress) { - return ((SOAPAddress)ext).getLocationURI(); - } - if (ext instanceof SOAP12Address) { - return ((SOAP12Address)ext).getLocationURI(); - } + + public OMElement invoke(OMElement arg0) { return null; } - - static void setPortAddress(Port port, String locationURI) { - Object ext = port.getExtensibilityElements().get(0); - if (ext instanceof SOAPAddress) { - ((SOAPAddress)ext).setLocationURI(locationURI); - } - if (ext instanceof SOAP12Address) { - ((SOAP12Address)ext).setLocationURI(locationURI); - } - } - - private String computeEndpointURI(String uri, ServletHost servletHost) { - - if (uri == null) { - return null; - } - - // pull out the binding intents to see what sort of transport is required - PolicySet transportJmsPolicySet = AxisPolicyHelper.getPolicySet(wsBinding, TRANSPORT_JMS_QUALIFIED_INTENT); - if (transportJmsPolicySet != null) { - if (!uri.startsWith("jms:/")) { - uri = "jms:" + uri; - } - - // construct the rest of the URI based on the policy. All the details are put - // into the URI here rather than being place directly into the Axis configuration - // as the Axis JMS sender relies on parsing the target URI - Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; - for (Object policy : transportJmsPolicySet.getPolicies()) { - if (policy instanceof Axis2ConfigParamPolicy) { - axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; - Iterator paramIterator = - axis2ConfigParamPolicy.getParamElements().get(DEFAULT_QUEUE_CONNECTION_FACTORY) - .getChildElements(); - - if (paramIterator.hasNext()) { - StringBuffer uriParams = new StringBuffer("?"); - - while (paramIterator.hasNext()) { - OMElement parameter = (OMElement)paramIterator.next(); - uriParams.append(parameter.getAttributeValue(new QName("", "name"))); - uriParams.append("="); - uriParams.append(parameter.getText()); - - if (paramIterator.hasNext()) { - uriParams.append("&"); - } - } - - uri = uri + uriParams; - } - } - } - } else { - if (!uri.startsWith("jms:")) { - uri = servletHost.getURLMapping(uri).toString(); - } - } - - return uri; - } - - public void start() { - - try { - createPolicyHandlers(); - for (Map.Entry<String, Port> entry : urlMap.entrySet()) { - AxisService axisService = createAxisService(entry.getKey(), entry.getValue()); - configContext.getAxisConfiguration().addService(axisService); - } - - Axis2ServiceServlet servlet = null; - for (String endpointURL : urlMap.keySet()) { - if (endpointURL.startsWith("http://") || endpointURL.startsWith("https://") - || endpointURL.startsWith("/")) { - if (servlet == null) { - servlet = new Axis2ServiceServlet(); - servlet.init(configContext); - } - //[nash] configContext.setContextRoot(endpointURL); - servletHost.addServletMapping(endpointURL, servlet); - } else if (endpointURL.startsWith("jms")) { - logger.log(Level.INFO, "Axis2 JMS URL=" + endpointURL); - - jmsListener = new JMSListener(); - jmsSender = new JMSSender(); - ListenerManager listenerManager = configContext.getListenerManager(); - TransportInDescription trsIn = - configContext.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_JMS); - - // get JMS transport parameters from the computed URL - Map<String, String> jmsProps = JMSUtils.getProperties(endpointURL); - - // collect the parameters used to configure the JMS transport - OMFactory fac = OMAbstractFactory.getOMFactory(); - OMElement parms = fac.createOMElement(DEFAULT_QUEUE_CONNECTION_FACTORY, null); - - for (String key : jmsProps.keySet()) { - OMElement param = fac.createOMElement("parameter", null); - param.addAttribute("name", key, null); - param.addChild(fac.createOMText(param, jmsProps.get(key))); - parms.addChild(param); - } - - Parameter queueConnectionFactory = new Parameter(DEFAULT_QUEUE_CONNECTION_FACTORY, parms); - trsIn.addParameter(queueConnectionFactory); - - trsIn.setReceiver(jmsListener); - - configContext.getAxisConfiguration().addTransportIn(trsIn); - TransportOutDescription trsOut = - configContext.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_JMS); - //configContext.getAxisConfiguration().addTransportOut( trsOut ); - trsOut.setSender(jmsSender); - - if (listenerManager == null) { - listenerManager = new ListenerManager(); - listenerManager.init(configContext); - } - listenerManager.addListener(trsIn, true); - jmsSender.init(configContext, trsOut); - jmsListener.init(configContext, trsIn); - jmsListener.start(); - } - } - } catch (AxisFault e) { - throw new RuntimeException(e); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public void stop() { - if (jmsListener != null) { - jmsListener.stop(); - jmsListener.destroy(); - } else { - for (String endpointURL : urlMap.keySet()) { - servletHost.removeServletMapping(endpointURL); - } - } - - servletHost = null; - - if (jmsSender != null) - jmsSender.stop(); - - try { - for (String endpointURL : urlMap.keySet()) { - // get the path to the service - URI uriPath = new URI(endpointURL); - String stringURIPath = uriPath.getPath(); - - /* [nash] Need a leading slash for WSDL imports to work with ?wsdl - // remove any "/" from the start of the path - if (stringURIPath.startsWith("/")) { - stringURIPath = stringURIPath.substring(1, stringURIPath.length()); - } - */ - - configContext.getAxisConfiguration().removeService(stringURIPath); - } - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } catch (AxisFault e) { - throw new RuntimeException(e); - } - } - - private AxisService createAxisService(String endpointURL, Port port) throws AxisFault { - AxisService axisService; - if (wsBinding.getWSDLDocument() != null) { - axisService = createWSDLAxisService(endpointURL, port); - } else { - axisService = createJavaAxisService(endpointURL); - } - initAxisOperations(axisService); - return axisService; - } - - /** - * Create an AxisService from the interface class from the SCA service interface - */ - protected AxisService createJavaAxisService(String endpointURL) throws AxisFault { - AxisService axisService = new AxisService(); - String path = URI.create(endpointURL).getPath(); - axisService.setName(path); - axisService.setServiceDescription("Tuscany configured AxisService for service: " + endpointURL); - axisService.setClientSide(false); - Parameter classParam = - new Parameter(Constants.SERVICE_CLASS, ((JavaInterface)contract.getInterfaceContract().getInterface()) - .getJavaClass().getName()); - axisService.addParameter(classParam); - try { - Utils.fillAxisService(axisService, configContext.getAxisConfiguration(), null, null); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return axisService; - } - - /** - * Workaround for https://issues.apache.org/jira/browse/AXIS2-3205 - * @param definition - * @param serviceName - * @return - */ - private static Definition getDefinition(Definition definition, QName serviceName) { - - if (serviceName == null) { - return definition; - } - - if (definition == null) { - return null; - } - Object service = definition.getServices().get(serviceName); - if (service != null) { - return definition; - } - for (Object i : definition.getImports().values()) { - List<Import> imports = (List<Import>)i; - for (Import imp : imports) { - Definition d = getDefinition(imp.getDefinition(), serviceName); - if (d != null) { - return d; - } - } - } - return null; - } - - /** - * Create an AxisService from the WSDL doc used by ws binding - */ - protected AxisService createWSDLAxisService(String endpointURL, Port port) throws AxisFault { - - Definition definition = wsBinding.getWSDLDocument(); - QName serviceQName = wsBinding.getService().getQName(); - Definition def = getDefinition(definition, serviceQName); - - final WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(def, serviceQName, port.getName()); - builder.setServerSide(true); - // [rfeng] Add a custom resolver to work around WSCOMMONS-228 - builder.setCustomResolver(new URIResolverImpl(def)); - builder.setBaseUri(def.getDocumentBaseURI()); - // [rfeng] - // AxisService axisService = builder.populateService(); - // Allow privileged access to read properties. Requires PropertiesPermission read in - // security policy. - AxisService axisService; - try { - axisService = AccessController.doPrivileged(new PrivilegedExceptionAction<AxisService>() { - public AxisService run() throws AxisFault { - return builder.populateService(); - } - }); - } catch (PrivilegedActionException e) { - throw (AxisFault)e.getException(); - } - - String name = URI.create(endpointURL).getPath(); - //[nash] HTTP endpoints need a leading slash for WSDL imports to work with ?wsdl - if (endpointURL.startsWith("jms")) { - name = name.startsWith("/") ? name.substring(1) : name; - } - axisService.setName(name); - axisService.setEndpointURL(endpointURL); - axisService.setDocumentation("Tuscany configured AxisService for service: " + endpointURL); - for (Iterator i = axisService.getEndpoints().values().iterator(); i.hasNext();) { - AxisEndpoint ae = (AxisEndpoint)i.next(); - if (endpointURL.startsWith("jms")) { - Parameter qcf = new Parameter(JMSConstants.CONFAC_PARAM, null); - qcf.setValue(DEFAULT_QUEUE_CONNECTION_FACTORY); - axisService.addParameter(qcf); - break; - } - } - - // Add schema information to the AxisService (needed for "?xsd=" support) - addSchemas(wsBinding.getWSDLDefinition(), axisService); - - // Use the existing WSDL - Parameter wsdlParam = new Parameter("wsdl4jDefinition", null); - wsdlParam.setValue(definition); - axisService.addParameter(wsdlParam); - Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); - axisService.addParameter(userWSDL); - - // Modify schema imports and includes to add "servicename?xsd=" prefix. - // Axis2 does this for schema extensibility elements, but Tuscany has - // overriden the WSDl4J deserializer to create UnknownExtensibilityElement - // elements in place of these. - modifySchemaImportsAndIncludes(definition, name); - - // Axis2 1.3 has a bug with returning incorrect values for the port - // addresses. To work around this, compute the values here. - Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); - axisService.addParameter(modifyAddr); - - return axisService; - } - - private void addSchemas(WSDLDefinition wsdlDef, AxisService axisService) { - for (XSDefinition xsDef : wsdlDef.getXmlSchemas()) { - if (xsDef.getSchema() != null) { - axisService.addSchema(xsDef.getSchema()); - updateSchemaRefs(xsDef.getSchema(), axisService.getName()); - } - } - for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { - addSchemas(impDef, axisService); - } - } - - private void updateSchemaRefs(XmlSchema parentSchema, String name) { - for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { - Object obj = iter.next(); - if (obj instanceof XmlSchemaExternal) { - XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; - String location = extSchema.getSchemaLocation(); - if (location.length() > 0 && location.indexOf(":/") < 0 && location.indexOf("?xsd=") < 0) { - extSchema.setSchemaLocation(name + "?xsd=" + location); - } - if (extSchema.getSchema() != null) { - updateSchemaRefs(extSchema.getSchema(), name); - } - } - } - } - - private void modifySchemaImportsAndIncludes(Definition definition, String name) { - // adjust the schema locations in types section - Types types = definition.getTypes(); - if (types != null) { - for (Iterator iter = types.getExtensibilityElements().iterator(); iter.hasNext();) { - Object ext = iter.next(); - if (ext instanceof UnknownExtensibilityElement && XSD_QNAME_LIST - .contains(((UnknownExtensibilityElement)ext).getElementType())) { - changeLocations(((UnknownExtensibilityElement)ext).getElement(), name); - } - } - } - for (Iterator iter = definition.getImports().values().iterator(); iter.hasNext();) { - Vector values = (Vector)iter.next(); - for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { - Import wsdlImport = (Import)valuesIter.next(); - modifySchemaImportsAndIncludes(wsdlImport.getDefinition(), name); - } - } - } - - private void changeLocations(Element element, String name) { - NodeList nodeList = element.getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - String tagName = nodeList.item(i).getLocalName(); - if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) { - processImport(nodeList.item(i), name); - } - } - } - - private void processImport(Node importNode, String name) { - NamedNodeMap nodeMap = importNode.getAttributes(); - for (int i = 0; i < nodeMap.getLength(); i++) { - Node attribute = nodeMap.item(i); - if (attribute.getNodeName().equals("schemaLocation")) { - String location = attribute.getNodeValue(); - if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { - attribute.setNodeValue(name + "?xsd=" + location); - } - } - } - } - - protected void initAxisOperations(AxisService axisService) { - for (Iterator<?> i = axisService.getOperations(); i.hasNext();) { - AxisOperation axisOp = (AxisOperation)i.next(); - Operation op = getOperation(axisOp); - if (op != null) { - - if (op.isNonBlocking()) { - axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY); - } else { - axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT); - } - - MessageReceiver msgrec = null; - if (op.isNonBlocking()) { - msgrec = new Axis2ServiceInMessageReceiver(this, op); - } else { - msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op); - } - axisOp.setMessageReceiver(msgrec); - } - } - } - - protected Operation getOperation(AxisOperation axisOp) { - String operationName = axisOp.getName().getLocalPart(); - Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); - for (Operation op : iface.getOperations()) { - if (op.getName().equalsIgnoreCase(operationName)) { - return op; - } - } - return null; - } - - // methods for Axis2 message receivers + public Object invokeTarget(Operation op, Object[] args, MessageContext inMC) throws InvocationTargetException { String callbackAddress = null; String callbackID = null; - Object conversationID = null; // create a message object and set the args as its body Message msg = messageFactory.createMessage(); @@ -659,29 +94,30 @@ public class Axis2ServiceProvider { if (from != null) { OMElement callbackAddrElement = from.getFirstChildWithName(QNAME_WSA_ADDRESS); if (callbackAddrElement != null) { - if (contract.getInterfaceContract().getCallbackInterface() != null) { + if (endpoint.getService().getInterfaceContract().getCallbackInterface() != null) { callbackAddress = callbackAddrElement.getText(); } } } // get policy specified headers +/* for (Axis2HeaderPolicy policy : axis2HeaderPolicies) { //Axis2BindingHeaderConfigurator.getHeader(inMC, msg, policy.getHeaderName()); } - +*/ +/* if (axis2TokenAuthenticationPolicy != null) { Axis2SOAPHeaderString tokenHeader = new Axis2SOAPHeaderString(); + Axis2BindingHeaderConfigurator.getHeader(inMC, msg, axis2TokenAuthenticationPolicy.getTokenName(), - tokenHeader); + tokenHeader); } +*/ } - //fill message with QoS context info - fillQoSContext(msg, inMC); - // Create a from EPR to hold the details of the callback endpoint EndpointReference from = null; if (callbackAddress != null ) { @@ -697,60 +133,10 @@ public class Axis2ServiceProvider { } Message response = endpoint.invoke(op, msg); + if(response.isFault()) { throw new InvocationTargetException((Throwable) response.getBody()); } return response.getBody(); } - - /** - * Return the binding for this provider as a primitive binding type - * For use when looking up wires registered against the binding. - * - * @return the binding - */ - protected Binding getBinding() { - return wsBinding; - } - - private void createPolicyHandlers() throws IllegalAccessException, InstantiationException, ClassNotFoundException { - if (wsBinding instanceof PolicySubject) { - - // code to create policy handlers using a policy SPI based - // on policy providers - /* - List<PolicyProvider> policyProviders = ((RuntimeComponentService)contract).getPolicyProviders(wsBinding); - - for (PolicyProvider policyProvider : policyProviders){ - policyHandler = policyProvider.createHandler(); - if (policyHandler != null) { - policyHandlerList.add(policyHandler); - } - } - */ - } - } - - private void fillQoSContext(Message message, MessageContext axis2MsgCtx) { - if (axis2MsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS) != null && axis2MsgCtx - .getProperty(WSHandlerConstants.RECV_RESULTS) instanceof Vector) { - Vector recvResults = (Vector)axis2MsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS); - for (int count1 = 0; count1 < recvResults.size(); ++count1) { - if (recvResults.elementAt(count1) instanceof WSHandlerResult) { - WSHandlerResult wshr = (WSHandlerResult)recvResults.elementAt(count1); - Vector results = wshr.getResults(); - for (int count2 = 0; count2 < results.size(); ++count2) { - if (results.elementAt(count2) instanceof WSSecurityEngineResult) { - WSSecurityEngineResult securityResult = - (WSSecurityEngineResult)wshr.getResults().elementAt(count2); - if (securityResult.get("principal") != null) { - message.getHeaders().add(securityResult.get("principal")); - } - } - } - } - } - - } - } } diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java index debb2c5764..1909bec0f0 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java @@ -94,54 +94,7 @@ public class Axis2ServiceServlet extends AxisServlet { ServletContext servletContext = config.getServletContext(); servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); - //super.init(config); - - // A copy of the init method from the base class because we need to replace the - // version of the ListenerManager that is used so that we can get it's - // shutdown hook removed properly. - - // prevent this method from being called more than once per instance - if (initCalled == false) { - initCalled = true; - // We can't call super.init() as it will just call the AxisServlet version - // which we are replacing here. So reflect on the base class and - // set the private config field in the base class. - //super.init(config); - try { - Field field = GenericServlet.class.getDeclaredField("config"); - field.setAccessible(true); - field.set(this, config); - } catch (Exception ex){ - ex.printStackTrace(); - } - - try { - this.servletConfig = config; - //ServletContext servletContext = servletConfig.getServletContext(); - this.configContext = - (ConfigurationContext) servletContext.getAttribute(CONFIGURATION_CONTEXT); - if(configContext == null){ - configContext = initConfigContext(config); - config.getServletContext().setAttribute(CONFIGURATION_CONTEXT, configContext); - } - axisConfiguration = configContext.getAxisConfiguration(); - - ListenerManager listenerManager = new TuscanyListenerManager(); - listenerManager.init(configContext); - TransportInDescription transportInDescription = new TransportInDescription( - Constants.TRANSPORT_HTTP); - transportInDescription.setReceiver(this); - listenerManager.addListener(transportInDescription, true); - listenerManager.start(); - ListenerManager.defaultConfigurationContext = configContext; - super.agent = new ListingAgent(configContext); - - initParams(); - - } catch (Exception e) { - throw new ServletException(e); - } - } + super.init(config); } /** @@ -328,6 +281,7 @@ public class Axis2ServiceServlet extends AxisServlet { * Override the AxisServlet method so as to not add "/services" into the URL * and to work with Tuscany service names. can go once moved to Axis2 1.3 */ +/* @Override public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { //RUNNING_PORT @@ -352,5 +306,6 @@ public class Axis2ServiceServlet extends AxisServlet { return new EndpointReference[]{new EndpointReference(epURI.toString())}; } + */ } diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java index 965d29032e..a84b025172 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java @@ -72,8 +72,9 @@ public class AxisPolicyHelper { } public static boolean isRampartRequired(Binding wsBinding) { - return isIntentRequired(wsBinding, AUTHENTICATION_INTENT) || isIntentRequired(wsBinding, INTEGRITY_INTENT) - || isIntentRequired(wsBinding, CONFIDENTIALITY_INTENT); + return isIntentRequired(wsBinding, AUTHENTICATION_INTENT) || + isIntentRequired(wsBinding, INTEGRITY_INTENT) || + isIntentRequired(wsBinding, CONFIDENTIALITY_INTENT); } } diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java deleted file mode 100644 index c8050912d6..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.binding.ws.axis2; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.ConfigurationContextFactory; -import org.apache.axis2.deployment.DeploymentConstants; -import org.apache.axis2.deployment.DeploymentErrorMsgs; -import org.apache.axis2.deployment.DeploymentException; -import org.apache.axis2.deployment.ModuleBuilder; -import org.apache.axis2.deployment.URLBasedAxisConfigurator; -import org.apache.axis2.description.AxisModule; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.engine.AxisConfiguration; -import org.apache.axis2.engine.AxisConfigurator; -import org.apache.axis2.i18n.Messages; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.oasisopen.sca.ServiceRuntimeException; - -/** - * Helps configure Axis2 from a resource in binding.ws.axis2 instead of Axis2.xml - * <p/> TODO: Review: should there be a single global Axis ConfigurationContext - * - * @version $Rev$ $Date$ - */ -public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { - - /* these two fields are part of a temporary fix to solve problems that Maven has with including - * rampart-1.4.mar into the classpath and also at the time of Release 1.0 rampart-1.4.mar seems - * to pull in a SNAPSHOT version of rampart-project pom. Hence rampart.mar has been excluded - * as a Maven dependency and has been packed with this module - */ - /************start of fix *********************************************************************/ - private URL axis2_xml = - getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"); - private URL axis2_repository = null; - private URL rampart_mar_url = - getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar"); - /************** end of fix *************************************************************/ - - private boolean isRampartRequired; - - public TuscanyAxisConfigurator(boolean isRampartRequired) throws AxisFault { - //super(TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"), - // TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart.mar")); - super(getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"), - null); - this.isRampartRequired = isRampartRequired; - } - - private static URL getResource(final String name) { - return AccessController.doPrivileged(new PrivilegedAction<URL>() { - public URL run() { - return TuscanyAxisConfigurator.class.getResource(name); - } - }); - } - - public ConfigurationContext getConfigurationContext() throws AxisFault { - if (configContext == null) { - configContext = ConfigurationContextFactory.createConfigurationContext(this); - } - return configContext; - } - - private InputStream getResourceAsStream(final String resource) { - return AccessController.doPrivileged(new PrivilegedAction<InputStream>() { - public InputStream run() { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - return cl.getResourceAsStream(resource); - } - }); - } - - /* these three methods are part of a temporary fix to solve problems that Maven has with including - * rampart-1.3.mar into the classpath and also at the time of Release 1.0 rampart-1.3.mar seems - * to pull in a SNAPSHOT version of rampart-project pom. Hence rampart.mar has been excluded - * as a Maven dependency and has been packed with this module - */ - /************start of fix *********************************************************************/ - @Override - public AxisConfiguration getAxisConfiguration() throws AxisFault { - InputStream axis2xmlStream; - try { - if (axis2_xml == null) { - axis2xmlStream = - getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE); - } else { - axis2xmlStream = axis2_xml.openStream(); - } - axisConfig = populateAxisConfiguration(axis2xmlStream); - if (isRampartRequired) { - axisConfig.addGlobalModuleRef("rampart"); - } - if (axis2_repository == null) { - Parameter axis2repoPara = axisConfig.getParameter(DeploymentConstants.AXIS2_REPO); - if (axis2repoPara != null) { - String repoValue = (String) axis2repoPara.getValue(); - if (repoValue != null && !"".equals(repoValue.trim())) { - if (repoValue.startsWith("file:/")) { - // we treat this case specially , by assuming file is - // located in the local machine - loadRepository(repoValue); - } else { - loadRepositoryFromURL(new URL(repoValue)); - } - } - } else { - //log.info("No repository found , module will be loaded from classpath"); - try { - loadFromClassPath(); - } catch ( Exception e ) { - if (isRampartRequired) { - loadRampartModule(); - } - } - } - - } else { - loadRepositoryFromURL(axis2_repository); - } - - } catch (IOException e) { - throw new AxisFault(e.getMessage()); - } - axisConfig.setConfigurator(this); - return axisConfig; - } - - public void loadRampartModule() throws DeploymentException { - try { - ClassLoader deploymentClassLoader = - org.apache.axis2.deployment.util.Utils.createClassLoader( - new URL[]{rampart_mar_url}, - axisConfig.getModuleClassLoader(), - true, - (File) axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR)); - final AxisModule module = new AxisModule(); - module.setModuleClassLoader(deploymentClassLoader); - module.setParent(axisConfig); - //String moduleFile = fileUrl.substring(0, fileUrl.indexOf(".mar")); - if (module.getName() == null) { - module.setName("rampart"); - module.setVersion("1.4"); - } - populateModule(module, rampart_mar_url); - module.setFileName(rampart_mar_url); - // Allow privileged access to read properties. Requires PropertiesPermission read in - // security policy. - try { - AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { - public Object run() throws IOException { - addNewModule(module, axisConfig); - return null; - } - }); - } catch (PrivilegedActionException e) { - throw (AxisFault)e.getException(); - } - - calculateDefaultModuleVersion(axisConfig.getModules(), axisConfig); - axisConfig.validateSystemPredefinedPhases(); - } catch (IOException e) { - throw new DeploymentException(e); - } - } - /** - * Get the name of the module , where archive name is combination of module name + its version - * The format of the name is as follows: - * moduleName-00.0000 - * Example: "addressing-01.0001.mar" would return "addressing" - * - * @param moduleName the name of the module archive - * @return the module name parsed out of the file name - */ - public static String getModuleName(String moduleName) { - if (moduleName.endsWith("-SNAPSHOT")) { - return moduleName.substring(0, moduleName.indexOf("-SNAPSHOT")); - } - char delimiter = '-'; - int version_index = moduleName.lastIndexOf(delimiter); - if (version_index > 0) { - String versionString = getModuleVersion(moduleName); - if (versionString == null) { - return moduleName; - } else { - return moduleName.substring(0, version_index); - } - } else { - return moduleName; - } - } - - public static String getModuleVersion(String moduleName) { - if (moduleName.endsWith("-SNAPSHOT")) { - return "SNAPSHOT"; - } - char version_seperator = '-'; - int version_index = moduleName.lastIndexOf(version_seperator); - if (version_index > 0) { - String versionString = moduleName.substring(version_index + 1, moduleName.length()); - try { - Float.parseFloat(versionString); - return versionString; - } catch (NumberFormatException e) { - return null; - } - } else { - return null; - } - } - - public static String getModuleName(String moduleName, String moduleVersion) { - if (moduleVersion != null && moduleVersion.length() != 0) { - moduleName = moduleName + "-" + moduleVersion; - } - return moduleName; - } - - public static boolean isLatest(String moduleVersion, String currentDefaultVersion) { - if (AxisModule.VERSION_SNAPSHOT.equals(moduleVersion)) { - return true; - } else { - float m_version = Float.parseFloat(moduleVersion); - float m_c_vresion = Float.parseFloat(currentDefaultVersion); - return m_version > m_c_vresion; - } - } - - public static void calculateDefaultModuleVersion(HashMap modules, - AxisConfiguration axisConfig) { - Iterator allModules = modules.values().iterator(); - HashMap defaultModules = new HashMap(); - while (allModules.hasNext()) { - AxisModule axisModule = (AxisModule) allModules.next(); - String moduleName = axisModule.getName(); - String moduleNameString; - String moduleVersionString; - if (AxisModule.VERSION_SNAPSHOT.equals(axisModule.getVersion())) { - moduleNameString = axisModule.getName(); - moduleVersionString = axisModule.getVersion(); - } else { - if (axisModule.getVersion() == null) { - moduleNameString = getModuleName(moduleName); - moduleVersionString = getModuleVersion(moduleName); - if (moduleVersionString != null) { - try { - Float.valueOf(moduleVersionString); - axisModule.setVersion(moduleVersionString); - axisModule.setName(moduleName); - } catch (NumberFormatException e) { - moduleVersionString = null; - } - } - } else { - moduleNameString = axisModule.getName(); - moduleVersionString = axisModule.getVersion(); - } - } - String currentDefaultVerison = (String) defaultModules.get(moduleNameString); - if (currentDefaultVerison != null) { - // if the module version is null then , that will be ignore in this case - if (!AxisModule.VERSION_SNAPSHOT.equals(currentDefaultVerison)) { - if (moduleVersionString != null && - isLatest(moduleVersionString, currentDefaultVerison)) { - defaultModules.put(moduleNameString, moduleVersionString); - } - } - } else { - defaultModules.put(moduleNameString, moduleVersionString); - } - - } - Iterator def_mod_itr = defaultModules.keySet().iterator(); - while (def_mod_itr.hasNext()) { - String moduleName = (String) def_mod_itr.next(); - axisConfig.addDefaultModuleVersion(moduleName, (String) defaultModules.get(moduleName)); - } - } - - - private void populateModule(AxisModule module, URL moduleUrl) throws DeploymentException { - try { - ClassLoader classLoader = module.getModuleClassLoader(); - InputStream moduleStream = classLoader.getResourceAsStream("META-INF/module.xml"); - if (moduleStream == null) { - moduleStream = classLoader.getResourceAsStream("meta-inf/module.xml"); - } - if (moduleStream == null) { - throw new DeploymentException( - Messages.getMessage( - DeploymentErrorMsgs.MODULE_XML_MISSING, moduleUrl.toString())); - } - ModuleBuilder moduleBuilder = new ModuleBuilder(moduleStream, module, axisConfig); - moduleBuilder.populateModule(); - } catch (IOException e) { - throw new DeploymentException(e); - } - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java deleted file mode 100644 index eb1e1a27aa..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.ws.axis2; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Iterator; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.description.TransportInDescription; -import org.apache.axis2.engine.ListenerManager; -import org.apache.axis2.transport.TransportListener; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * A Tuscany specific Axis2 ListenerManager. Created purely as part of - * TUSCANY-3149 to unregister the ListenerManager from the runtime - * shutown hook - */ -public class TuscanyListenerManager extends ListenerManager { - private static final Log log = LogFactory.getLog(TuscanyListenerManager.class); - - private ListenerManagerShutdownThread shutdownThread = null; - - /** - * To start all the transports - */ - public synchronized void start() { - - ConfigurationContext configctx = getConfigctx(); - - // very nasty! but this is in order to get someone running who keeps - // getting perm gen errors. This will all go away when we move up to Axis2 1.5 - HashMap startedTransports = null; - - try { - Field field = ListenerManager.class.getDeclaredField("startedTransports"); - field.setAccessible(true); - startedTransports = (HashMap)field.get(this); - } catch (Exception ex){ - ex.printStackTrace(); - } - - for (Iterator transportNames = - configctx.getAxisConfiguration().getTransportsIn().values().iterator(); - transportNames.hasNext();) { - try { - TransportInDescription transportIn = (TransportInDescription) transportNames.next(); - TransportListener listener = transportIn.getReceiver(); - if (listener != null && - startedTransports.get(transportIn.getName()) == null) { - listener.init(configctx, transportIn); - listener.start(); - if (startedTransports.get(transportIn.getName()) == null) { - startedTransports.put(transportIn.getName(), listener); - } - } - } catch (Exception e) { - log.info(e.getMessage(), e); - } - } - shutdownThread = new ListenerManagerShutdownThread(this); - Runtime.getRuntime().addShutdownHook(shutdownThread); - } - - public synchronized void stop() throws AxisFault { - super.stop(); - try { - if (shutdownThread != null) { - Runtime.getRuntime().removeShutdownHook(shutdownThread); - shutdownThread = null; - } - } catch (IllegalStateException e) { - // Ignore - shutdownThread = null; - } - } - - static class ListenerManagerShutdownThread extends Thread { - ListenerManager listenerManager; - - public ListenerManagerShutdownThread(ListenerManager listenerManager) { - super(); - this.listenerManager = listenerManager; - } - - public void run() { - try { - listenerManager.stop(); - } catch (AxisFault axisFault) { - log.error(axisFault.getMessage(), axisFault); - } - } - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java index 55f1592657..fb309b7593 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2-15-runtime/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java @@ -94,10 +94,10 @@ public class TuscanyListingAgent extends ListingAgent { Definition definition = (Definition)wsld4jdefinition.getValue(); for (Object s : definition.getServices().values()) { for (Object p : ((Service)s).getPorts().values()) { - String endpointURL = Axis2ServiceProvider.getPortAddress((Port)p); + String endpointURL = Axis2EngineIntegration.getPortAddress((Port)p); String modifiedURL = setIPAddress(endpointURL, url); modifiedURL = addContextRoot(modifiedURL, serviceName); - Axis2ServiceProvider.setPortAddress((Port)p, modifiedURL); + Axis2EngineIntegration.setPortAddress((Port)p, modifiedURL); } } } @@ -218,10 +218,12 @@ public class TuscanyListingAgent extends ListingAgent { int wsdlPort = wsdlURIObj.getPort(); String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); URI requestURIObj = new URI(requestURI); - String ipAddr = HttpUtils.getIpAddress(); - int requestPort = requestURIObj.getPort(); - String newAddr = ipAddr + (requestPort != -1 ? ":" + Integer.toString(requestPort) : ""); - return wsdlURI.replace(wsdlAddr, newAddr); +// not in Axis2 1.5.1 +// String ipAddr = HttpUtils.getIpAddress(); +// int requestPort = requestURIObj.getPort(); +// String newAddr = ipAddr + (requestPort != -1 ? ":" + Integer.toString(requestPort) : ""); +// return wsdlURI.replace(wsdlAddr, newAddr); + return wsdlURI; } catch (Exception e) { // URI string not in expected format, so return the WSDL URI unmodified return wsdlURI; |