From d8234862d2003940b84b0607b4b7f34e1623f8a4 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 1 Mar 2010 12:54:07 +0000 Subject: Move the ws binding provider files into the provider package. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@917502 13f79535-47bb-0310-9956-ffa450edef68 --- .../binding/ws/axis2/Axis2BaseBindingProvider.java | 62 --- .../ws/axis2/Axis2BindingProviderFactory.java | 65 --- .../binding/ws/axis2/Axis2EngineIntegration.java | 504 --------------------- .../ws/axis2/Axis2ReferenceBindingProvider.java | 341 -------------- .../ws/axis2/Axis2ServiceBindingProvider.java | 289 ------------ .../ws/axis2/Axis2ServiceInMessageReceiver.java | 62 --- .../Axis2ServiceInOutSyncMessageReceiver.java | 99 ---- .../sca/binding/ws/axis2/Axis2ServiceProvider.java | 127 ------ .../sca/binding/ws/axis2/Axis2ServiceServlet.java | 311 ------------- .../sca/binding/ws/axis2/TuscanyDispatcher.java | 104 ----- .../sca/binding/ws/axis2/TuscanyListingAgent.java | 233 ---------- .../Axis2ConfigParamPolicyProvider.java | 2 +- .../security/http/ssl/HTTPSPolicyProvider.java | 2 +- .../axis2/provider/Axis2BaseBindingProvider.java | 62 +++ .../provider/Axis2BindingProviderFactory.java | 65 +++ .../ws/axis2/provider/Axis2EngineIntegration.java | 504 +++++++++++++++++++++ .../provider/Axis2ReferenceBindingProvider.java | 340 ++++++++++++++ .../provider/Axis2ServiceBindingProvider.java | 289 ++++++++++++ .../provider/Axis2ServiceInMessageReceiver.java | 62 +++ .../Axis2ServiceInOutSyncMessageReceiver.java | 99 ++++ .../ws/axis2/provider/Axis2ServiceProvider.java | 127 ++++++ .../ws/axis2/provider/Axis2ServiceServlet.java | 311 +++++++++++++ .../ws/axis2/provider/TuscanyDispatcher.java | 104 +++++ .../ws/axis2/provider/TuscanyListingAgent.java | 233 ++++++++++ ...che.tuscany.sca.provider.BindingProviderFactory | 2 +- .../binding/ws/axis2/engine/conf/tuscany-axis2.xml | 10 +- 26 files changed, 2204 insertions(+), 2205 deletions(-) delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BaseBindingProvider.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BaseBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BaseBindingProvider.java deleted file mode 100644 index 6d0fc37ba5..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BaseBindingProvider.java +++ /dev/null @@ -1,62 +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 org.apache.axis2.context.ConfigurationContext; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.host.http.SecurityContext; -import org.apache.tuscany.sca.invocation.MessageFactory; - -public class Axis2BaseBindingProvider { - - // Tuscany extensions - protected ExtensionPointRegistry extensionPoints; - protected FactoryExtensionPoint modelFactories; - protected MessageFactory messageFactory; - - // derived policy configuration - protected boolean isSOAP12Required = false; - protected boolean isRampartRequired = false; - protected boolean isMTOMRequired = false; - protected boolean isJMSRequired = false; - - // The Axis2 configuration that the binding creates - protected ConfigurationContext configContext; - protected SecurityContext httpSecurityContext; - - public Axis2BaseBindingProvider(ExtensionPointRegistry extensionPoints) { - - this.extensionPoints = extensionPoints; - - this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - this.messageFactory = modelFactories.getFactory(MessageFactory.class); - - this.httpSecurityContext = new SecurityContext(); - } - - public ConfigurationContext getAxisConfigurationContext() { - return configContext; - } - - public SecurityContext getHttpSecurityContext() { - return httpSecurityContext; - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java deleted file mode 100644 index b9cc93691d..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java +++ /dev/null @@ -1,65 +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 javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.host.http.ServletHostHelper; -import org.apache.tuscany.sca.provider.BindingProviderFactory; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; - -/** - * Axis2BindingProviderFactory - * - * @version $Rev$ $Date$ - */ - -public class Axis2BindingProviderFactory implements BindingProviderFactory { - - public static final QName MTOM_INTENT = new QName(Constants.SCA11_TUSCANY_NS, "MTOM"); - - private ExtensionPointRegistry extensionPoints; - private ServletHost servletHost; - - public Axis2BindingProviderFactory(ExtensionPointRegistry extensionPoints) { - this.extensionPoints = extensionPoints; - this.servletHost = ServletHostHelper.getServletHost(extensionPoints); - } - - public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { - return new Axis2ReferenceBindingProvider(extensionPoints, endpointReference); - } - - public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { - return new Axis2ServiceBindingProvider(extensionPoints, endpoint, servletHost); - } - - public Class getModelType() { - return WebServiceBinding.class; - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java deleted file mode 100644 index 2c44fbdd84..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2EngineIntegration.java +++ /dev/null @@ -1,504 +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.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -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.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.addressing.AddressingConstants; -import org.apache.axis2.addressing.EndpointReference; -import org.apache.axis2.client.Options; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.ConfigurationContextFactory; -import org.apache.axis2.deployment.URLBasedAxisConfigurator; -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.WSDL11ToAxisServiceBuilder; -import org.apache.axis2.description.WSDL2Constants; -import org.apache.axis2.description.WSDLToAxisServiceBuilder; -import org.apache.axis2.engine.MessageReceiver; -import org.apache.axis2.transport.local.LocalResponder; -import org.apache.tuscany.sca.assembly.AbstractContract; - -import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.extensibility.ClassLoaderContext; -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.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.commons.schema.resolver.URIResolver; -import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; -import org.oasisopen.sca.ServiceRuntimeException; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import com.ctc.wstx.stax.WstxInputFactory; - - -public class Axis2EngineIntegration { - - //========================================================= - // most of the following is related to rewriting WSDL imports - // I'd like to move this but don't know where to yet. - - public static final String IMPORT_TAG = "import"; - public static final String INCLUDE_TAG = "include"; - - 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); - - //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 XSD_QNAME_LIST = - Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); - - //========================================================= - - /* - * Create the whole configuration context for the Axis engine - */ - public static ConfigurationContext getAxisConfigurationContext(){ - ConfigurationContext configContext = null; - // get the axis configuration context from the Tuscany axis2.xml file - // Allow privileged access to read properties. Requires PropertyPermission read in - // security policy. - try { - configContext = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public ConfigurationContext run() throws AxisFault, MalformedURLException { - // collect together the classloaders that Axis2 requireds in order to load - // pluggable items such as the Tuscany MessageReceivers and the xerces - // document builder. - ClassLoader wsBindingCL = getClass().getClassLoader(); - ClassLoader axis2CL = URLBasedAxisConfigurator.class.getClassLoader(); - ClassLoader xercesCL = DocumentBuilderFactoryImpl.class.getClassLoader(); - ClassLoader wstxCL = WstxInputFactory.class.getClassLoader(); - ClassLoader localtransportCL = LocalResponder.class.getClassLoader(); - ClassLoader oldTCCL = ClassLoaderContext.setContextClassLoader(wsBindingCL, axis2CL, xercesCL, wstxCL, localtransportCL); - - 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/")); - return ConfigurationContextFactory.createConfigurationContextFromURIs(axis2xmlURL, repositoryURL); - } else { - return null; - } - } finally { - if (oldTCCL != null) { - Thread.currentThread().setContextClassLoader(oldTCCL); - } - } - } - }); - } catch (PrivilegedActionException e) { - throw new ServiceRuntimeException(e.getException()); - } - - return configContext; - } - - //========================================================= - - /** - * Create an AxisService from the Java interface class of the SCA service interface - */ - public static AxisService createJavaAxisService(String endpointURL, - ConfigurationContext configContext, - AbstractContract contract) 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 - */ - public static AxisService createWSDLAxisService(String endpointURL, - Port port, - WebServiceBinding wsBinding) 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 - // TODO - 228 is resolved, is this still required - 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() { - 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); - - // TODO - again, do we ever have more than one endpoint - // on the service side? - 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 - */ - 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 imports = (List)i; - for (Import imp : imports) { - Definition d = getDefinition(imp.getDefinition(), serviceName); - if (d != null) { - return d; - } - } - } - return null; - } - - private static 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 static 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 static 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 static 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 static 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); - } - } - } - } - - //========================================================= - - /* - * Create the service message receivers and the service provider that will push - * messages out onto the binding wire - */ - public static void createAxisServiceProviders(AxisService axisService, - RuntimeEndpoint endpoint, - WebServiceBinding wsBinding, - ExtensionPointRegistry extensionPoints) { - for (Iterator i = axisService.getOperations(); i.hasNext();) { - AxisOperation axisOp = (AxisOperation)i.next(); - Operation op = getOperation(axisOp, wsBinding); - 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, extensionPoints); - if (op.isNonBlocking()) { - msgrec = new Axis2ServiceInMessageReceiver(serviceProvider, op); - } else { - msgrec = new Axis2ServiceInOutSyncMessageReceiver(serviceProvider, op); - } - axisOp.setMessageReceiver(msgrec); - } - } - } - - private static Operation getOperation(AxisOperation axisOp,WebServiceBinding wsBinding) { - String operationName = axisOp.getName().getLocalPart(); - Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); - for (Operation op : iface.getOperations()) { - if (op.getName().equalsIgnoreCase(operationName)) { - return op; - } - } - return null; - } - - //========================================================= - - public 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; - } - - public 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); - } - } - - /** - * This method is copied from AxisService.createClientSideAxisService to - * work around http://issues.apache.org/jira/browse/WSCOMMONS-228 - * - * @param wsdlDefinition - * @param wsdlServiceName - * @param portName - * @param options - * @return - * @throws AxisFault - */ - @Deprecated - public static AxisService createClientSideAxisService(Definition definition, - QName serviceName, - String portName, - Options options) throws AxisFault { - Definition def = getDefinition(definition, serviceName); - final WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(def, serviceName, portName); - serviceBuilder.setServerSide(false); - // [rfeng] Add a custom resolver to work around WSCOMMONS-228 - serviceBuilder.setCustomResolver(new URIResolverImpl(def)); - serviceBuilder.setBaseUri(def.getDocumentBaseURI()); - // [rfeng] - // Allow access to read properties. Requires PropertiesPermission in security policy. - AxisService axisService; - try { - axisService = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public AxisService run() throws AxisFault { - return serviceBuilder.populateService(); - } - }); - } catch ( PrivilegedActionException e ) { - throw (AxisFault) e.getException(); - } - - AxisEndpoint axisEndpoint = (AxisEndpoint)axisService.getEndpoints().get(axisService.getEndpointName()); - options.setTo(new EndpointReference(axisEndpoint.getEndpointURL())); - if (axisEndpoint != null) { - options.setSoapVersionURI((String)axisEndpoint.getBinding().getProperty(WSDL2Constants.ATTR_WSOAP_VERSION)); - } - return axisService; - } - - /** - * URI resolver implementation for XML schema - */ - public static class URIResolverImpl implements URIResolver { - private Definition definition; - - public URIResolverImpl(Definition definition) { - this.definition = definition; - } - - public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, - java.lang.String schemaLocation, - java.lang.String baseUri) { - try { - if (baseUri == null) { - baseUri = definition.getDocumentBaseURI(); - } - URL url = new URL(new URL(baseUri), schemaLocation); - return XMLDocumentHelper.getInputSource(url); - } catch (IOException e) { - return null; - } - } - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java deleted file mode 100644 index 1f3cac26a7..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java +++ /dev/null @@ -1,341 +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.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Collection; -import java.util.List; - -import javax.wsdl.Binding; -import javax.wsdl.BindingOperation; -import javax.wsdl.Definition; -import javax.wsdl.Port; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.extensions.soap.SOAPOperation; -import javax.wsdl.extensions.soap12.SOAP12Address; -import javax.xml.namespace.QName; -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.dom.DOMSource; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.axiom.soap.SOAPFactory; -import org.apache.axis2.AxisFault; -import org.apache.axis2.addressing.EndpointReferenceHelper; -import org.apache.axis2.client.Options; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.description.AxisService; -import org.apache.axis2.transport.http.HTTPConstants; -import org.apache.axis2.util.threadpool.ThreadPool; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; -import org.apache.commons.httpclient.params.HttpConnectionManagerParams; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.binding.ws.axis2.transport.TransportReferenceInterceptor; -import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingInvoker; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.InvocationChain; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Phase; -import org.apache.tuscany.sca.policy.util.PolicyHelper; -import org.apache.tuscany.sca.provider.EndpointReferenceProvider; -import org.apache.tuscany.sca.provider.PolicyProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; -import org.oasisopen.sca.ServiceRuntimeException; - -public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider implements EndpointReferenceProvider { - - // the endpoint reference configuration that's driving this binding provider - // and some convenience data retrieved from the endpoint reference - private RuntimeEndpointReference endpointReference; - private RuntimeComponent component; - private RuntimeComponentReference reference; - private WebServiceBinding wsBinding; - - // The Axis2 configuration that the binding creates - private ServiceClient serviceClient; - private AxisService axisClientSideService; - - - public Axis2ReferenceBindingProvider(ExtensionPointRegistry extensionPoints, - EndpointReference endpointReference) { - - super(extensionPoints); - - this.endpointReference = (RuntimeEndpointReference)endpointReference; - - this.wsBinding = (WebServiceBinding)endpointReference.getBinding(); - this.component = (RuntimeComponent)endpointReference.getComponent(); - this.reference = (RuntimeComponentReference)endpointReference.getReference(); - - // A WSDL document should always be present in the binding - if (wsBinding.getWSDLDocument() == null) { - throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + reference.getName()); - } - - // Set to use the Axiom data binding - InterfaceContract contract = wsBinding.getBindingInterfaceContract(); - if (contract.getInterface() != null) { - contract.getInterface().resetDataBinding(OMElement.class.getName()); - } - - isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); - - isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); - - // TODO - this is not correct as there may be other, custom, policies that - // require rampart. For example this is not going to pick up the case - // of external policy attachment - isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); - - // Apply the configuration from any other policies - - for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { - pp.configureBinding(this); - } - } - - public void start() { - configContext = Axis2EngineIntegration.getAxisConfigurationContext(); - - try { - Definition definition = wsBinding.getWSDLDocument(); - QName serviceQName = wsBinding.getService().getQName(); - Port port = wsBinding.getPort(); - if (port == null) { - // service has multiple ports, select one port to use - // TODO - it feels like there is much more to this than is - // here at the moment as need to match with the service side - // assuming that it's available - Collection ports = wsBinding.getService().getPorts().values(); - for (Port p : ports) { - // look for a SOAP 1.1 port first - if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { - port = p; - break; - } - } - if (port == null) { - // no SOAP 1.1 port available, so look for a SOAP 1.2 port - for (Port p : ports) { - if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { - port = p; - break; - } - } - } - } - - axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); - - HttpClient httpClient = (HttpClient)configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); - if (httpClient == null) { - MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); - HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); - connectionManagerParams.setDefaultMaxConnectionsPerHost(2); - connectionManagerParams.setTcpNoDelay(true); - connectionManagerParams.setStaleCheckingEnabled(true); - connectionManagerParams.setLinger(0); - connectionManager.setParams(connectionManagerParams); - httpClient = new HttpClient(connectionManager); - configContext.setThreadPool(new ThreadPool(1, 5)); - configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); - configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); - } - - serviceClient = new ServiceClient(configContext, axisClientSideService); - - } catch (AxisFault e) { - throw new RuntimeException(e); // TODO: better exception - } - } - - public void stop() { - if (serviceClient != null) { - // close all connections that we have initiated, so that the jetty server - // can be restarted without seeing ConnectExceptions - HttpClient httpClient = - (HttpClient)serviceClient.getServiceContext().getConfigurationContext() - .getProperty(HTTPConstants.CACHED_HTTP_CLIENT); - if (httpClient != null) - ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown(); - - serviceClient = null; - } - } - - public InterfaceContract getBindingInterfaceContract() { - return wsBinding.getBindingInterfaceContract(); - - } - - public boolean supportsOneWayInvocation() { - return true; - } - - public Invoker createInvoker(Operation operation) { - Options options = new Options(); - org.apache.axis2.addressing.EndpointReference epTo = getWSATOEPR(wsBinding); - if (epTo != null) { - options.setTo(epTo); - } - options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); - - String operationName = operation.getName(); - - String soapAction = getSOAPAction(operationName); - if (soapAction != null && soapAction.length() > 1) { - options.setAction(soapAction); - } - - options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds - - // Allow privileged access to read properties. Requires PropertiesPermission read in - // security policy. - SOAPFactory soapFactory = AccessController.doPrivileged(new PrivilegedAction() { - public SOAPFactory run() { - if (isSOAP12Required) - return OMAbstractFactory.getSOAP12Factory(); - else - return OMAbstractFactory.getSOAP11Factory(); - - } - }); - QName wsdlOperationQName = new QName(operationName); - if (isMTOMRequired) - { - options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); - } - - return new Axis2ReferenceBindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); - -/* - if (operation.isNonBlocking()) { - invoker = new Axis2OneWayBindingInvoker(this, wsdlOperationQName, options, soapFactory, wsBinding); - } else { - invoker = new Axis2BindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); - } - - return invoker; -*/ - } - - /* - * set up the reference binding wire with the right set of ws reference - * interceptors - */ - public void configure() { - InvocationChain bindingChain = endpointReference.getBindingInvocationChain(); - - // add transport interceptor - bindingChain.addInterceptor(Phase.REFERENCE_BINDING_TRANSPORT, - new TransportReferenceInterceptor()); - - } - - // Reference specific utility operations - - protected org.apache.axis2.addressing.EndpointReference getWSATOEPR(WebServiceBinding binding) { - org.apache.axis2.addressing.EndpointReference epr = getEPR(binding); - if (epr == null) { - epr = getPortLocationEPR(binding); - } else if (epr.getAddress() == null || epr.getAddress().length() < 1) { - org.apache.axis2.addressing.EndpointReference bindingEPR = getPortLocationEPR(binding); - if (bindingEPR != null) { - epr.setAddress(bindingEPR.getAddress()); - } - } - return epr; - } - - protected org.apache.axis2.addressing.EndpointReference getPortLocationEPR(WebServiceBinding binding) { - String ep = null; - if (binding.getPort() != null) { - List wsdlPortExtensions = binding.getPort().getExtensibilityElements(); - for (final Object extension : wsdlPortExtensions) { - if (extension instanceof SOAPAddress) { - ep = ((SOAPAddress)extension).getLocationURI(); - break; - } - if (extension instanceof SOAP12Address) { - SOAP12Address address = (SOAP12Address)extension; - ep = address.getLocationURI(); - break; - } - } - } - if(ep == null || ep.equals("")) { - ep = binding.getURI(); - } - return ep == null || "".equals(ep) ? null : new org.apache.axis2.addressing.EndpointReference(ep); - } - - protected org.apache.axis2.addressing.EndpointReference getEPR(WebServiceBinding wsBinding) { - if (wsBinding.getEndPointReference() == null) { - return null; - } - try { - - XMLStreamReader parser = - XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(wsBinding.getEndPointReference())); - StAXOMBuilder builder = new StAXOMBuilder(parser); - OMElement omElement = builder.getDocumentElement(); - org.apache.axis2.addressing.EndpointReference epr = EndpointReferenceHelper.fromOM(omElement); - return epr; - - } catch (IOException e) { - throw new RuntimeException(e); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } catch (FactoryConfigurationError e) { - throw new RuntimeException(e); - } - } - - protected String getSOAPAction(String operationName) { - Binding binding = wsBinding.getBinding(); - if (binding != null) { - for (Object o : binding.getBindingOperations()) { - BindingOperation bop = (BindingOperation)o; - if (bop.getName().equalsIgnoreCase(operationName)) { - for (Object o2 : bop.getExtensibilityElements()) { - if (o2 instanceof SOAPOperation) { - return ((SOAPOperation)o2).getSoapActionURI(); - } - } - } - } - } - return null; - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java deleted file mode 100644 index 74322706ad..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java +++ /dev/null @@ -1,289 +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.net.URI; -import java.net.URISyntaxException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.wsdl.Port; -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.context.ConfigurationContext; -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.engine.ListenerManager; -import org.apache.axis2.transport.jms.JMSListener; -import org.apache.axis2.transport.jms.JMSSender; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.policy.mtom.Axis2MTOMPolicyProvider; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.InterfaceContract; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.policy.util.PolicyHelper; -import org.apache.tuscany.sca.provider.PolicyProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -import org.oasisopen.sca.ServiceRuntimeException; - -public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implements ServiceBindingProvider { - private static final Logger logger = Logger.getLogger(Axis2ServiceBindingProvider.class.getName()); - - // Tuscany extensions - private AssemblyFactory assemblyFactory; - private ServletHost servletHost; - private RuntimeComponent component; - private RuntimeComponentService service; - - // the endpoint configuration that's driving this binding provider - // and some convenience data retrieved from the endpoint - private RuntimeEndpoint endpoint; - private WebServiceBinding wsBinding; - private Port wsdlPort; - private String endpointURI; - private InterfaceContract contract; - - // The Axis2 configuration that the binding creates - private JMSSender jmsSender; - private JMSListener jmsListener; - - public Axis2ServiceBindingProvider(ExtensionPointRegistry extensionPoints, - RuntimeEndpoint endpoint, - ServletHost servletHost ) { - super(extensionPoints); - - this.extensionPoints = extensionPoints; - this.endpoint = endpoint; - this.servletHost = servletHost; - - this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); - this.wsBinding = (WebServiceBinding)endpoint.getBinding(); - this.component = (RuntimeComponent)endpoint.getComponent(); - this.service = (RuntimeComponentService)endpoint.getService(); - - // A WSDL document should always be present in the binding - if (wsBinding.getWSDLDocument() == null) { - throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + service.getName()); - } - - // Set to use the Axiom data binding - contract = wsBinding.getBindingInterfaceContract(); - contract.getInterface().resetDataBinding(OMElement.class.getName()); - - configContext = Axis2EngineIntegration.getAxisConfigurationContext(); - - // set the root context for this instance of Axis - configContext.setContextRoot(servletHost.getContextPath()); - - // Determine the configuration from the bindings "mayProvides" intents - - isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); - - isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); - - // this is not correct as there may be other, custom, policies that - // require rampart. For example this is not going to pick up the case - // of external policy attachment - isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); - - - // Apply the configuration from any other policies - - for (PolicyProvider pp : endpoint.getPolicyProviders()) { - pp.configureBinding(this); - } - - // Update port addresses with runtime information - // We can safely assume there is only one port here because you configure - // a binding in the following ways: - // 1/ default - one port generated = host domain : host port / structural path - // 2/ uri="absolute addr" - one port generated = host domain : uri port / uri path - // 3/ uri="relative addr" - one port generated = host domain : host port / structural path / relative path - // 4/ wsdl.binding - one port generated = host domain : host port / structural path - // 5/ wsdl.port - one port generated = host domain : port port / port path - // 6/ wsa:Address - one port generated = host domain : address port / address path - // 7/ 4 + 6 - as 6 - wsdlPort = (Port)wsBinding.getService().getPorts().values().iterator().next(); - - if (wsdlPort == null){ - throw new ServiceRuntimeException("No WSDL port for ws binding of " + component.getName() + "/" + service.getName()); - } - - endpointURI = Axis2EngineIntegration.getPortAddress(wsdlPort); - - if (endpointURI.startsWith("jms:")) { - isJMSRequired = true; - } else { - if (servletHost == null) { - throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); - } - endpointURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); - } - - Axis2EngineIntegration.setPortAddress(wsdlPort, endpointURI); - - // Apply the configuration from the mayProvides intents - - if (isRampartRequired){ - // TODO - do we need to go back to configurator? - } - - if (isMTOMRequired) { - new Axis2MTOMPolicyProvider(endpoint).configureBinding(configContext); - } - - if (isJMSRequired){ - // TODO - do we need to go back to configurator? - } - } - - private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; - - public void start() { - try { - createAxisService(endpointURI, wsdlPort); - - if (endpointURI.startsWith("http://") || - endpointURI.startsWith("https://") || - endpointURI.startsWith("/")) { - Axis2ServiceServlet servlet = new Axis2ServiceServlet(); - servlet.init(configContext); - - if (httpSecurityContext.isSSLEnabled()){ - servletHost.addServletMapping(endpointURI, servlet, httpSecurityContext); - } else { - servletHost.addServletMapping(endpointURI, servlet); - } - } else if (endpointURI.startsWith("jms")) { - logger.log(Level.INFO, "Axis2 JMS URL=" + endpointURI); - - jmsListener = new JMSListener(); - jmsSender = new JMSSender(); - ListenerManager listenerManager = configContext.getListenerManager(); - TransportInDescription trsIn = - configContext.getAxisConfiguration().getTransportIn(org.apache.axis2.Constants.TRANSPORT_JMS); - - // get JMS transport parameters from the computed URL -//not in Axis2 1.5.1 -// Map 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(org.apache.axis2.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); - } - } - - public void stop() { - try { - if (jmsListener != null) { - jmsListener.stop(); - jmsListener.destroy(); - } else { - servletHost.removeServletMapping(endpointURI); - } - - if (jmsSender != null) { - jmsSender.stop(); - } - - servletHost = null; - - // get the path to the service - // [nash] Need a leading slash for WSDL imports to work with ?wsdl - URI uriPath = new URI(endpointURI); - String stringURIPath = uriPath.getPath(); - configContext.getAxisConfiguration().removeService(stringURIPath); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } catch (AxisFault e) { - throw new RuntimeException(e); - } - } - - public InterfaceContract getBindingInterfaceContract() { - return wsBinding.getBindingInterfaceContract(); - } - - public boolean supportsOneWayInvocation() { - return true; - } - - // Service specific utility operations - - private void createAxisService(String endpointURL, Port port) throws AxisFault { - AxisService axisService; - if (wsBinding.getWSDLDocument() != null) { - axisService = Axis2EngineIntegration.createWSDLAxisService(endpointURL, port, wsBinding); - } else { - axisService = Axis2EngineIntegration.createJavaAxisService(endpointURL, configContext, service); - } - - Axis2EngineIntegration.createAxisServiceProviders(axisService, endpoint, wsBinding, extensionPoints); - - configContext.getAxisConfiguration().addService(axisService); - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java deleted file mode 100644 index 795b3b256f..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java +++ /dev/null @@ -1,62 +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.InvocationTargetException; - -import org.apache.axiom.om.OMElement; -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.receivers.AbstractInMessageReceiver; -import org.apache.tuscany.sca.interfacedef.Operation; - -public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { - - protected Operation operation; - - private Axis2ServiceProvider provider; - - public Axis2ServiceInMessageReceiver(Axis2ServiceProvider provider, Operation operation) { - this.provider = provider; - this.operation = operation; - } - - public Axis2ServiceInMessageReceiver() { - } - - @Override - public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { - try { - OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); - Object[] args = new Object[] {requestOM}; - - provider.invokeTarget(operation, args, inMC); - - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof Exception) { - throw AxisFault.makeFault((Exception)t); - } - throw new RuntimeException(e); - } catch (Exception e) { - e.printStackTrace(); - throw AxisFault.makeFault(e); - } - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java deleted file mode 100644 index 2cd176aae0..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java +++ /dev/null @@ -1,99 +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.InvocationTargetException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.soap.SOAPEnvelope; -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.util.FaultException; -import org.oasisopen.sca.ServiceRuntimeException; - -public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { - private static final Logger logger = Logger.getLogger(Axis2ServiceInOutSyncMessageReceiver.class.getName()); - - protected Operation operation; - - private Axis2ServiceProvider provider; - - public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceProvider provider, Operation operation) { - this.provider = provider; - this.operation = operation; - } - - public Axis2ServiceInOutSyncMessageReceiver() { - } - - @Override - public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { - try { - OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); - Object[] args = null; - - if (requestOM != null) { - args = new Object[] {requestOM}; - } - - /* - for ( PolicyHandler policyHandler : policyHandlerList ) { - policyHandler.beforeInvoke(operation, args, inMC); - } - */ - - OMElement responseOM = (OMElement)provider.invokeTarget(operation, args, inMC); - - /* - for ( PolicyHandler policyHandler : policyHandlerList ) { - policyHandler.afterInvoke(operation, args, inMC, responseOM); - } - */ - - SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); - if (null != responseOM ) { - soapEnvelope.getBody().addChild(responseOM); - } - outMC.setEnvelope(soapEnvelope); - outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); - - } catch (InvocationTargetException e) { - Throwable t = e.getCause(); - if (t instanceof FaultException && ((FaultException)t).getFaultInfo() instanceof OMElement) { - OMElement faultDetail = (OMElement)((FaultException)t).getFaultInfo(); - inMC.setProperty(Constants.FAULT_NAME, faultDetail.getQName().getLocalPart()); - AxisFault f = new AxisFault(null, e.getMessage(), "faultNode", "faultRole", faultDetail); - throw f; - } - if (t instanceof Exception) { - throw AxisFault.makeFault((Exception)t); - } - logger.log(Level.SEVERE, e.getMessage(), t); - throw new ServiceRuntimeException(e); - } catch (Throwable e) { - logger.log(Level.SEVERE, e.getMessage(), e); - throw AxisFault.makeFault(e); - } - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java deleted file mode 100644 index 362c269b01..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java +++ /dev/null @@ -1,127 +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.InvocationTargetException; -import java.util.logging.Logger; - -import javax.annotation.Resource; -import javax.xml.namespace.QName; -import javax.xml.ws.Provider; -import javax.xml.ws.WebServiceContext; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.soap.SOAPHeader; -import org.apache.axis2.addressing.AddressingConstants; -import org.apache.axis2.context.MessageContext; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -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.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.runtime.RuntimeEndpoint; - -public class Axis2ServiceProvider implements Provider { - private static final Logger logger = Logger.getLogger(Axis2ServiceProvider.class.getName()); - - 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 RuntimeEndpoint endpoint; - private WebServiceBinding wsBinding; - private MessageFactory messageFactory; - private FactoryExtensionPoint modelFactories; - private RuntimeAssemblyFactory assemblyFactory; - - @Resource - WebServiceContext wsContext; - - public Axis2ServiceProvider(RuntimeEndpoint endpoint, - WebServiceBinding wsBinding, - ExtensionPointRegistry extensionPoints) { - this.endpoint = endpoint; - this.wsBinding = wsBinding; - this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); - } - - public OMElement invoke(OMElement arg0) { - // TODO - the interface for a JAX-WS provider. - // May make Axis2 integration cleaner - return null; - } - - public Object invokeTarget(Operation op, Object[] args, MessageContext inMC) throws InvocationTargetException { - String callbackAddress = null; - String callbackID = null; - - // create a message object and set the args as its body - Message msg = messageFactory.createMessage(); - msg.setBody(args); - msg.setOperation(op); - msg.setBindingContext(inMC); - - //FIXME: can we use the Axis2 addressing support for this? - SOAPHeader header = inMC.getEnvelope().getHeader(); - if (header != null) { - OMElement from = header.getFirstChildWithName(QNAME_WSA_FROM); - if (from != null) { - OMElement callbackAddrElement = from.getFirstChildWithName(QNAME_WSA_ADDRESS); - if (callbackAddrElement != null) { - if (endpoint.getService().getInterfaceContract().getCallbackInterface() != null) { - callbackAddress = callbackAddrElement.getText(); - } - } - } - } - - // Create a from EPR to hold the details of the callback endpoint - EndpointReference from = null; - if (callbackAddress != null ) { - from = assemblyFactory.createEndpointReference(); - Endpoint fromEndpoint = assemblyFactory.createEndpoint(); - from.setTargetEndpoint(fromEndpoint); - from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED); - msg.setFrom(from); - Endpoint callbackEndpoint = assemblyFactory.createEndpoint(); - callbackEndpoint.setURI(callbackAddress); - callbackEndpoint.setUnresolved(true); - from.setCallbackEndpoint(callbackEndpoint); - } - - Message response = endpoint.invoke(msg); - - if(response.isFault()) { - throw new InvocationTargetException((Throwable) response.getBody()); - } - return response.getBody(); - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java deleted file mode 100644 index 1909bec0f0..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java +++ /dev/null @@ -1,311 +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.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.net.MalformedURLException; -import java.net.SocketException; -import java.net.URI; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Set; -import java.util.Vector; - -import javax.servlet.GenericServlet; -import javax.servlet.RequestDispatcher; -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.addressing.EndpointReference; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.description.TransportInDescription; -import org.apache.axis2.engine.ListenerManager; -import org.apache.axis2.transport.http.AxisServlet; -import org.apache.axis2.transport.http.ListingAgent; -import org.apache.axis2.transport.http.server.HttpUtils; - -/** - * This overrides the Servlet init of the AxisServlet so Tuscany can use - * a single Axis2 ConfigurationContext instance shared between AxisServlet - * instances for each SCA service with a ws binding. - * TODO: need to review if thats really what we want to be doing - * - * @version $Rev$ $Date$ - */ -public class Axis2ServiceServlet extends AxisServlet { - - protected TuscanyListingAgent agent; - - private static final long serialVersionUID = 1L; - private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); - - private boolean initCalled = false; - -//JIRA TUSCANY-1561 Port to Axis2 1.3 - private ConfigurationContext tmpconfigContext; - - public void init(ConfigurationContext configContext) { - this.tmpconfigContext = configContext; - try { - //super.init(DUMMY_CONFIG); - init(DUMMY_CONFIG); - } catch (ServletException e) { - throw new RuntimeException(e); - } - agent = new TuscanyListingAgent(configContext); - } - - /** - * Override Axis2 Servlet method to avoid loop when init - * is called after servletConfig already initialized by - * this classes init(ConfigurationContext) method. - */ - @Override - public void init() throws ServletException { - } - - @Override - public void init(ServletConfig config) throws ServletException { - ServletContext servletContext = config.getServletContext(); - servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); - - super.init(config); - } - - /** - * We've setup the Servlet by passing in a ConfigurationContext on our init method - * override this method to just return that - */ - @Override - protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { - return this.tmpconfigContext; - } - - @Override - public ServletConfig getServletConfig() { - return DUMMY_CONFIG; - } - - @Override - public String getServletName() { - return "TuscanyAxis2Servlet"; - } - - /** - * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. - */ - private static ServletConfig createDummyServletConfig() { - ServletConfig sc = new ServletConfig() { - - public String getServletName() { - return "TuscanyAxis2DummyServlet"; - } - - public ServletContext getServletContext() { - return new ServletContext() { - - public ServletContext getContext(String uripath) { - return null; - } - - @SuppressWarnings("unused") // it's on the Servlet 2.5 API so we need it - public String getContextPath() { - return null; - } - - public int getMajorVersion() { - return 0; - } - - public int getMinorVersion() { - return 0; - } - - public String getMimeType(String file) { - return null; - } - - public Set getResourcePaths(String path) { - return Collections.emptySet(); - } - - public URL getResource(String path) throws MalformedURLException { - if("/".equals(path)) { - // HACK: To avoid NPE - return new URL("/axis2"); - } - return null; - } - - public InputStream getResourceAsStream(String path) { - return null; - } - - public RequestDispatcher getRequestDispatcher(String path) { - return null; - } - - public RequestDispatcher getNamedDispatcher(String arg0) { - return null; - } - - public Servlet getServlet(String arg0) throws ServletException { - return null; - } - - public Enumeration getServlets() { - return null; - } - - public Enumeration getServletNames() { - return null; - } - - public void log(String arg0) { - } - - public void log(Exception arg0, String arg1) { - } - - public void log(String arg0, Throwable arg1) { - } - - public String getRealPath(String arg0) { - return null; - } - - public String getServerInfo() { - return null; - } - - public String getInitParameter(String arg0) { - return null; - } - - public Enumeration getInitParameterNames() { - return null; - } - - public Object getAttribute(String arg0) { - return null; - } - - public Enumeration getAttributeNames() { - return null; - } - - public void setAttribute(String arg0, Object arg1) { - } - - public void removeAttribute(String arg0) { - } - - public String getServletContextName() { - return null; - } - }; - } - - public String getInitParameter(String arg0) { - return null; - } - - public Enumeration getInitParameterNames() { - return new Vector().elements(); - } - }; - return sc; - } - - @Override - public void destroy() { - try { - super.destroy(); - servletConfig = null; - if (tmpconfigContext.getListenerManager() != null){ - tmpconfigContext.getListenerManager().destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - /** - * Override the AxisServlet doGet to use the TuscanyListingAgent for ?wsdl - */ - @Override - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - - initContextRoot(request); - - String query = request.getQueryString(); - if ((query != null) && (query.indexOf("wsdl2") >= 0 || - query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 || - query.indexOf("policy") >= 0)) { - agent.processListService(request, response); - } else { - super.doGet(request, response); - } - } - - /** - - /** - * 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 - String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT); - if (port == null) { - port = "8080"; - } - if (ip == null) { - try { - ip = HttpUtils.getIpAddress(); - if (ip == null) { - ip = "localhost"; - } - } catch (SocketException e) { -//TUSCANY-1561 Port to Axis2 1.3 -// throw new AxisFault.(e); - throw AxisFault.makeFault(e); - } - } - - URI epURI = URI.create("http://" + ip + ":" + port + "/" + serviceName).normalize(); - - return new EndpointReference[]{new EndpointReference(epURI.toString())}; - } - */ - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java deleted file mode 100644 index 3527061a66..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java +++ /dev/null @@ -1,104 +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.net.URI; -import java.util.HashMap; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.addressing.EndpointReference; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.description.AxisService; -import org.apache.axis2.description.HandlerDescription; -import org.apache.axis2.engine.AxisConfiguration; -import org.apache.axis2.engine.RequestURIBasedDispatcher; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * A Tuscany specific Axis2 Dispatcher that enables using services - * exposed at the SCA defined service URI instead of /services/ - * - * @version $Rev$ $Date$ - */ -public class TuscanyDispatcher extends RequestURIBasedDispatcher { - - public static final String NAME = "TuscanyDispatcher"; - private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class); - private static final boolean isDebugEnabled = log.isDebugEnabled(); - - /* - * (non-Javadoc) - * - * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext) - */ - @Override - public AxisService findService(MessageContext messageContext) throws AxisFault { - EndpointReference toEPR = messageContext.getTo(); - - if (toEPR != null) { - if(isDebugEnabled){ - log.debug("Checking for Service using target endpoint address : " + toEPR.getAddress()); - } - - String path = URI.create(toEPR.getAddress()).getPath(); - - ConfigurationContext configurationContext = messageContext.getConfigurationContext(); - AxisConfiguration registry = configurationContext.getAxisConfiguration(); - - String serviceName = findAxisServiceName(registry, path); - return registry.getService(serviceName); - - } else { - if(isDebugEnabled){ - log.debug("Attempted to check for Service using null target endpoint URI"); - } - return null; - } - } - - @Override - public void initDispatcher() { - init(new HandlerDescription(NAME)); - } - - protected String findAxisServiceName(AxisConfiguration registry, String path) { - HashMap services = registry.getServices(); - if (services == null) { - return null; - } - String[] parts = path.split("/"); - String serviceName = ""; - for (int i=parts.length-1; i>=0; i--) { - serviceName = parts[i] + serviceName; - if (services.containsKey(serviceName)) { - return serviceName; - } - serviceName = "/" + serviceName; - if (services.containsKey(serviceName)) { - return serviceName; - } - } - - return null; - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java deleted file mode 100644 index fb309b7593..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java +++ /dev/null @@ -1,233 +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.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.wsdl.Definition; -import javax.wsdl.Port; -import javax.wsdl.Service; - -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.description.AxisService; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.transport.http.ListingAgent; -import org.apache.axis2.transport.http.server.HttpUtils; -import org.apache.ws.commons.schema.XmlSchema; -import org.apache.ws.commons.schema.XmlSchemaExternal; - -/** - * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work - * with the Tuscany service names which include slash ('/') characters. - * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. - * - * @version $Rev$ $Date$ - */ -public class TuscanyListingAgent extends ListingAgent { - - private static final String LIST_SINGLE_SERVICE_JSP_NAME = - "listSingleService.jsp"; - - public TuscanyListingAgent(ConfigurationContext aConfigContext) { - super(aConfigContext); - } - - /** - * This method overrides the Axis2 listing agent's computation of the - * service name. - */ - @Override - public String extractServiceName(String urlString) { - String serviceName = findAxisServiceName(urlString); - setContextRoot(urlString, serviceName); - return serviceName; - } - - /** - * Override ?xsd processing so that WSDL documents with XSD imports - * and includes work correctly. When we move to Axis2 1.4, we may - * be able to use SchemaSupplier to do this in a cleaner way. Also - * ensure that the correct IP address and port are returned by ?wsdl. - */ - @Override - public void processListService(HttpServletRequest req, - HttpServletResponse res) - throws IOException, ServletException { - - String url = req.getRequestURL().toString(); - String query = req.getQueryString(); - - // for ?wsdl requests, need to update the WSDL with correct IPaddr and port - int wsdl = query.indexOf("wsdl"); - if (wsdl >= 0) { - String serviceName = extractServiceName(url); - HashMap services = configContext.getAxisConfiguration().getServices(); - if ((services != null) && !services.isEmpty()) { - AxisService axisService = (AxisService)services.get(serviceName); - Parameter wsld4jdefinition = axisService.getParameter("wsdl4jDefinition"); - Definition definition = (Definition)wsld4jdefinition.getValue(); - for (Object s : definition.getServices().values()) { - for (Object p : ((Service)s).getPorts().values()) { - String endpointURL = Axis2EngineIntegration.getPortAddress((Port)p); - String modifiedURL = setIPAddress(endpointURL, url); - modifiedURL = addContextRoot(modifiedURL, serviceName); - Axis2EngineIntegration.setPortAddress((Port)p, modifiedURL); - } - } - } - } - - // handle ?xsd requests here - int xsd = query.indexOf("xsd"); - if (xsd >= 0) { - String serviceName = extractServiceName(url); - HashMap services = configContext.getAxisConfiguration().getServices(); - if ((services != null) && !services.isEmpty()) { - Object serviceObj = services.get(serviceName); - if (serviceObj != null) { - String xsds = req.getParameter("xsd"); - if (xsds != null && !"".equals(xsds)) { - // a schema name (perhaps with path) is present - AxisService axisService = (AxisService)serviceObj; - ArrayList schemas = axisService.getSchema(); - for (Object rootSchema : axisService.getSchema()) { - XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds); - if (schema != null) { - // found the schema - res.setContentType("text/xml"); - OutputStream out = res.getOutputStream(); - schema.write(new OutputStreamWriter(out, "UTF8")); - out.flush(); - out.close(); - return; - } - } - } - } - } - } - - // in all other cases, delegate to the Axis2 code - super.processListService(req, res); - } - - private String addContextRoot(String modifiedURL, String serviceName) { - if (!"/".equals(configContext.getContextRoot())) { - if (modifiedURL.endsWith(serviceName)) { - URI uri = URI.create(modifiedURL); - if (!uri.getPath().startsWith(configContext.getContextRoot())) { - modifiedURL = modifiedURL.substring(0, modifiedURL.length() - serviceName.length()) + configContext.getContextRoot() + serviceName; - } - } - } - return modifiedURL; - } - - private XmlSchema getSchema(XmlSchema parentSchema, String name) { - for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { - Object obj = iter.next(); - if (obj instanceof XmlSchemaExternal) { - XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; - if (extSchema.getSchemaLocation().endsWith(name)) { - return extSchema.getSchema(); - } else { - XmlSchema schema = getSchema(extSchema.getSchema(), name); - if (schema != null) { - return schema; - } - } - } - } - return null; - } - - private String findAxisServiceName(String path) { - HashMap services = configContext.getAxisConfiguration().getServices(); - if (services == null) { - return null; - } - String[] parts = path.split("/"); - String serviceName = ""; - for (int i=parts.length-1; i>=0; i--) { - serviceName = parts[i] + serviceName; - if (services.containsKey(serviceName)) { - return serviceName; - } - serviceName = "/" + serviceName; - if (services.containsKey(serviceName)) { - return serviceName; - } - } - - return null; - } - - /** - * Hack for Tuscany to get ?wsdl working with Tuscany service names - * Can go once moved up to Axis2 1.3 - */ - private void setContextRoot(String filePart, String serviceName) { - String contextRoot = configContext.getContextRoot(); - if (contextRoot != null && contextRoot.length() > 0) { - if (contextRoot.equals("/")) { - configContext.setServicePath("/"); - } else { - int i = filePart.indexOf(contextRoot) + contextRoot.length(); - int j = filePart.lastIndexOf(serviceName); - if (i>=j || (i+1 == j)) { - configContext.setServicePath("/"); - } else { - String mapping = filePart.substring(i+1, j); - configContext.setServicePath(mapping); - } - } - configContext.setContextRoot(contextRoot); - } - } - - private static String setIPAddress(String wsdlURI, String requestURI) { - try { - URI wsdlURIObj = new URI(wsdlURI); - String wsdlHost = wsdlURIObj.getHost(); - int wsdlPort = wsdlURIObj.getPort(); - String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); - URI requestURIObj = new URI(requestURI); -// 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; - } - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java index 4c7d3a480a..a77f71b734 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java @@ -22,7 +22,7 @@ package org.apache.tuscany.sca.binding.ws.axis2.policy.configuration; import org.apache.axis2.AxisFault; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.description.Parameter; -import org.apache.tuscany.sca.binding.ws.axis2.Axis2BaseBindingProvider; +import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider; import org.apache.tuscany.sca.policy.PolicySubject; import org.apache.tuscany.sca.provider.BasePolicyProvider; import org.oasisopen.sca.ServiceRuntimeException; diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java index f983a42dba..e875b7d278 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java @@ -22,7 +22,7 @@ package org.apache.tuscany.sca.binding.ws.axis2.policy.security.http.ssl; import java.security.KeyStore; import java.util.logging.Logger; -import org.apache.tuscany.sca.binding.ws.axis2.Axis2BaseBindingProvider; +import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider; import org.apache.tuscany.sca.host.http.SecurityContext; import org.apache.tuscany.sca.policy.PolicySubject; import org.apache.tuscany.sca.policy.security.http.ssl.HTTPSPolicy; diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java new file mode 100644 index 0000000000..203d05c465 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java @@ -0,0 +1,62 @@ +/* + * 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.provider; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.host.http.SecurityContext; +import org.apache.tuscany.sca.invocation.MessageFactory; + +public class Axis2BaseBindingProvider { + + // Tuscany extensions + protected ExtensionPointRegistry extensionPoints; + protected FactoryExtensionPoint modelFactories; + protected MessageFactory messageFactory; + + // derived policy configuration + protected boolean isSOAP12Required = false; + protected boolean isRampartRequired = false; + protected boolean isMTOMRequired = false; + protected boolean isJMSRequired = false; + + // The Axis2 configuration that the binding creates + protected ConfigurationContext configContext; + protected SecurityContext httpSecurityContext; + + public Axis2BaseBindingProvider(ExtensionPointRegistry extensionPoints) { + + this.extensionPoints = extensionPoints; + + this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + + this.httpSecurityContext = new SecurityContext(); + } + + public ConfigurationContext getAxisConfigurationContext() { + return configContext; + } + + public SecurityContext getHttpSecurityContext() { + return httpSecurityContext; + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java new file mode 100644 index 0000000000..a79d1ffe81 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java @@ -0,0 +1,65 @@ +/* + * 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.provider; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostHelper; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * Axis2BindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class Axis2BindingProviderFactory implements BindingProviderFactory { + + public static final QName MTOM_INTENT = new QName(Constants.SCA11_TUSCANY_NS, "MTOM"); + + private ExtensionPointRegistry extensionPoints; + private ServletHost servletHost; + + public Axis2BindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + this.servletHost = ServletHostHelper.getServletHost(extensionPoints); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { + return new Axis2ReferenceBindingProvider(extensionPoints, endpointReference); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new Axis2ServiceBindingProvider(extensionPoints, endpoint, servletHost); + } + + public Class getModelType() { + return WebServiceBinding.class; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java new file mode 100644 index 0000000000..73fc18a4a6 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java @@ -0,0 +1,504 @@ +/* + * 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.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +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.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +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.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.transport.local.LocalResponder; +import org.apache.tuscany.sca.assembly.AbstractContract; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ClassLoaderContext; +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.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.commons.schema.resolver.URIResolver; +import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; +import org.oasisopen.sca.ServiceRuntimeException; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.ctc.wstx.stax.WstxInputFactory; + + +public class Axis2EngineIntegration { + + //========================================================= + // most of the following is related to rewriting WSDL imports + // I'd like to move this but don't know where to yet. + + public static final String IMPORT_TAG = "import"; + public static final String INCLUDE_TAG = "include"; + + 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); + + //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 XSD_QNAME_LIST = + Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); + + //========================================================= + + /* + * Create the whole configuration context for the Axis engine + */ + public static ConfigurationContext getAxisConfigurationContext(){ + ConfigurationContext configContext = null; + // get the axis configuration context from the Tuscany axis2.xml file + // Allow privileged access to read properties. Requires PropertyPermission read in + // security policy. + try { + configContext = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public ConfigurationContext run() throws AxisFault, MalformedURLException { + // collect together the classloaders that Axis2 requireds in order to load + // pluggable items such as the Tuscany MessageReceivers and the xerces + // document builder. + ClassLoader wsBindingCL = getClass().getClassLoader(); + ClassLoader axis2CL = URLBasedAxisConfigurator.class.getClassLoader(); + ClassLoader xercesCL = DocumentBuilderFactoryImpl.class.getClassLoader(); + ClassLoader wstxCL = WstxInputFactory.class.getClassLoader(); + ClassLoader localtransportCL = LocalResponder.class.getClassLoader(); + ClassLoader oldTCCL = ClassLoaderContext.setContextClassLoader(wsBindingCL, axis2CL, xercesCL, wstxCL, localtransportCL); + + 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/")); + return ConfigurationContextFactory.createConfigurationContextFromURIs(axis2xmlURL, repositoryURL); + } else { + return null; + } + } finally { + if (oldTCCL != null) { + Thread.currentThread().setContextClassLoader(oldTCCL); + } + } + } + }); + } catch (PrivilegedActionException e) { + throw new ServiceRuntimeException(e.getException()); + } + + return configContext; + } + + //========================================================= + + /** + * Create an AxisService from the Java interface class of the SCA service interface + */ + public static AxisService createJavaAxisService(String endpointURL, + ConfigurationContext configContext, + AbstractContract contract) 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 + */ + public static AxisService createWSDLAxisService(String endpointURL, + Port port, + WebServiceBinding wsBinding) 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 + // TODO - 228 is resolved, is this still required + 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() { + 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); + + // TODO - again, do we ever have more than one endpoint + // on the service side? + 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 + */ + 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 imports = (List)i; + for (Import imp : imports) { + Definition d = getDefinition(imp.getDefinition(), serviceName); + if (d != null) { + return d; + } + } + } + return null; + } + + private static 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 static 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 static 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 static 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 static 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); + } + } + } + } + + //========================================================= + + /* + * Create the service message receivers and the service provider that will push + * messages out onto the binding wire + */ + public static void createAxisServiceProviders(AxisService axisService, + RuntimeEndpoint endpoint, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints) { + for (Iterator i = axisService.getOperations(); i.hasNext();) { + AxisOperation axisOp = (AxisOperation)i.next(); + Operation op = getOperation(axisOp, wsBinding); + 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, extensionPoints); + if (op.isNonBlocking()) { + msgrec = new Axis2ServiceInMessageReceiver(serviceProvider, op); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(serviceProvider, op); + } + axisOp.setMessageReceiver(msgrec); + } + } + } + + private static Operation getOperation(AxisOperation axisOp,WebServiceBinding wsBinding) { + String operationName = axisOp.getName().getLocalPart(); + Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); + for (Operation op : iface.getOperations()) { + if (op.getName().equalsIgnoreCase(operationName)) { + return op; + } + } + return null; + } + + //========================================================= + + public 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; + } + + public 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); + } + } + + /** + * This method is copied from AxisService.createClientSideAxisService to + * work around http://issues.apache.org/jira/browse/WSCOMMONS-228 + * + * @param wsdlDefinition + * @param wsdlServiceName + * @param portName + * @param options + * @return + * @throws AxisFault + */ + @Deprecated + public static AxisService createClientSideAxisService(Definition definition, + QName serviceName, + String portName, + Options options) throws AxisFault { + Definition def = getDefinition(definition, serviceName); + final WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(def, serviceName, portName); + serviceBuilder.setServerSide(false); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + serviceBuilder.setCustomResolver(new URIResolverImpl(def)); + serviceBuilder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // Allow access to read properties. Requires PropertiesPermission in security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public AxisService run() throws AxisFault { + return serviceBuilder.populateService(); + } + }); + } catch ( PrivilegedActionException e ) { + throw (AxisFault) e.getException(); + } + + AxisEndpoint axisEndpoint = (AxisEndpoint)axisService.getEndpoints().get(axisService.getEndpointName()); + options.setTo(new EndpointReference(axisEndpoint.getEndpointURL())); + if (axisEndpoint != null) { + options.setSoapVersionURI((String)axisEndpoint.getBinding().getProperty(WSDL2Constants.ATTR_WSOAP_VERSION)); + } + return axisService; + } + + /** + * URI resolver implementation for XML schema + */ + public static class URIResolverImpl implements URIResolver { + private Definition definition; + + public URIResolverImpl(Definition definition) { + this.definition = definition; + } + + public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, + java.lang.String schemaLocation, + java.lang.String baseUri) { + try { + if (baseUri == null) { + baseUri = definition.getDocumentBaseURI(); + } + URL url = new URL(new URL(baseUri), schemaLocation); + return XMLDocumentHelper.getInputSource(url); + } catch (IOException e) { + return null; + } + } + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java new file mode 100644 index 0000000000..4369953f78 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java @@ -0,0 +1,340 @@ +/* + * 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.provider; + +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collection; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.namespace.QName; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.dom.DOMSource; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.util.threadpool.ThreadPool; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.axis2.transport.TransportReferenceInterceptor; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.util.PolicyHelper; +import org.apache.tuscany.sca.provider.EndpointReferenceProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider implements EndpointReferenceProvider { + + // the endpoint reference configuration that's driving this binding provider + // and some convenience data retrieved from the endpoint reference + private RuntimeEndpointReference endpointReference; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private WebServiceBinding wsBinding; + + // The Axis2 configuration that the binding creates + private ServiceClient serviceClient; + private AxisService axisClientSideService; + + + public Axis2ReferenceBindingProvider(ExtensionPointRegistry extensionPoints, + EndpointReference endpointReference) { + + super(extensionPoints); + + this.endpointReference = (RuntimeEndpointReference)endpointReference; + + this.wsBinding = (WebServiceBinding)endpointReference.getBinding(); + this.component = (RuntimeComponent)endpointReference.getComponent(); + this.reference = (RuntimeComponentReference)endpointReference.getReference(); + + // A WSDL document should always be present in the binding + if (wsBinding.getWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + reference.getName()); + } + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract.getInterface() != null) { + contract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); + + isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + + // TODO - this is not correct as there may be other, custom, policies that + // require rampart. For example this is not going to pick up the case + // of external policy attachment + isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || + PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || + PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); + + // Apply the configuration from any other policies + + for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { + pp.configureBinding(this); + } + } + + public void start() { + configContext = Axis2EngineIntegration.getAxisConfigurationContext(); + + try { + Definition definition = wsBinding.getWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Port port = wsBinding.getPort(); + if (port == null) { + // service has multiple ports, select one port to use + // TODO - it feels like there is much more to this than is + // here at the moment as need to match with the service side + // assuming that it's available + Collection ports = wsBinding.getService().getPorts().values(); + for (Port p : ports) { + // look for a SOAP 1.1 port first + if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { + port = p; + break; + } + } + if (port == null) { + // no SOAP 1.1 port available, so look for a SOAP 1.2 port + for (Port p : ports) { + if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { + port = p; + break; + } + } + } + } + + axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); + + HttpClient httpClient = (HttpClient)configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient == null) { + MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); + connectionManagerParams.setDefaultMaxConnectionsPerHost(2); + connectionManagerParams.setTcpNoDelay(true); + connectionManagerParams.setStaleCheckingEnabled(true); + connectionManagerParams.setLinger(0); + connectionManager.setParams(connectionManagerParams); + httpClient = new HttpClient(connectionManager); + configContext.setThreadPool(new ThreadPool(1, 5)); + configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); + } + + serviceClient = new ServiceClient(configContext, axisClientSideService); + + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + } + + public void stop() { + if (serviceClient != null) { + // close all connections that we have initiated, so that the jetty server + // can be restarted without seeing ConnectExceptions + HttpClient httpClient = + (HttpClient)serviceClient.getServiceContext().getConfigurationContext() + .getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient != null) + ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown(); + + serviceClient = null; + } + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public Invoker createInvoker(Operation operation) { + Options options = new Options(); + org.apache.axis2.addressing.EndpointReference epTo = getWSATOEPR(wsBinding); + if (epTo != null) { + options.setTo(epTo); + } + options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + + String operationName = operation.getName(); + + String soapAction = getSOAPAction(operationName); + if (soapAction != null && soapAction.length() > 1) { + options.setAction(soapAction); + } + + options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + SOAPFactory soapFactory = AccessController.doPrivileged(new PrivilegedAction() { + public SOAPFactory run() { + if (isSOAP12Required) + return OMAbstractFactory.getSOAP12Factory(); + else + return OMAbstractFactory.getSOAP11Factory(); + + } + }); + QName wsdlOperationQName = new QName(operationName); + if (isMTOMRequired) + { + options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); + } + + return new Axis2ReferenceBindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); + +/* + if (operation.isNonBlocking()) { + invoker = new Axis2OneWayBindingInvoker(this, wsdlOperationQName, options, soapFactory, wsBinding); + } else { + invoker = new Axis2BindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); + } + + return invoker; +*/ + } + + /* + * set up the reference binding wire with the right set of ws reference + * interceptors + */ + public void configure() { + InvocationChain bindingChain = endpointReference.getBindingInvocationChain(); + + // add transport interceptor + bindingChain.addInterceptor(Phase.REFERENCE_BINDING_TRANSPORT, + new TransportReferenceInterceptor()); + + } + + // Reference specific utility operations + + protected org.apache.axis2.addressing.EndpointReference getWSATOEPR(WebServiceBinding binding) { + org.apache.axis2.addressing.EndpointReference epr = getEPR(binding); + if (epr == null) { + epr = getPortLocationEPR(binding); + } else if (epr.getAddress() == null || epr.getAddress().length() < 1) { + org.apache.axis2.addressing.EndpointReference bindingEPR = getPortLocationEPR(binding); + if (bindingEPR != null) { + epr.setAddress(bindingEPR.getAddress()); + } + } + return epr; + } + + protected org.apache.axis2.addressing.EndpointReference getPortLocationEPR(WebServiceBinding binding) { + String ep = null; + if (binding.getPort() != null) { + List wsdlPortExtensions = binding.getPort().getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + ep = ((SOAPAddress)extension).getLocationURI(); + break; + } + if (extension instanceof SOAP12Address) { + SOAP12Address address = (SOAP12Address)extension; + ep = address.getLocationURI(); + break; + } + } + } + if(ep == null || ep.equals("")) { + ep = binding.getURI(); + } + return ep == null || "".equals(ep) ? null : new org.apache.axis2.addressing.EndpointReference(ep); + } + + protected org.apache.axis2.addressing.EndpointReference getEPR(WebServiceBinding wsBinding) { + if (wsBinding.getEndPointReference() == null) { + return null; + } + try { + + XMLStreamReader parser = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(wsBinding.getEndPointReference())); + StAXOMBuilder builder = new StAXOMBuilder(parser); + OMElement omElement = builder.getDocumentElement(); + org.apache.axis2.addressing.EndpointReference epr = EndpointReferenceHelper.fromOM(omElement); + return epr; + + } catch (IOException e) { + throw new RuntimeException(e); + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } catch (FactoryConfigurationError e) { + throw new RuntimeException(e); + } + } + + protected String getSOAPAction(String operationName) { + Binding binding = wsBinding.getBinding(); + if (binding != null) { + for (Object o : binding.getBindingOperations()) { + BindingOperation bop = (BindingOperation)o; + if (bop.getName().equalsIgnoreCase(operationName)) { + for (Object o2 : bop.getExtensibilityElements()) { + if (o2 instanceof SOAPOperation) { + return ((SOAPOperation)o2).getSoapActionURI(); + } + } + } + } + } + return null; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java new file mode 100644 index 0000000000..f3813672c3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -0,0 +1,289 @@ +/* + * 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.provider; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Port; +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.context.ConfigurationContext; +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.engine.ListenerManager; +import org.apache.axis2.transport.jms.JMSListener; +import org.apache.axis2.transport.jms.JMSSender; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.policy.mtom.Axis2MTOMPolicyProvider; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +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.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.util.PolicyHelper; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implements ServiceBindingProvider { + private static final Logger logger = Logger.getLogger(Axis2ServiceBindingProvider.class.getName()); + + // Tuscany extensions + private AssemblyFactory assemblyFactory; + private ServletHost servletHost; + private RuntimeComponent component; + private RuntimeComponentService service; + + // the endpoint configuration that's driving this binding provider + // and some convenience data retrieved from the endpoint + private RuntimeEndpoint endpoint; + private WebServiceBinding wsBinding; + private Port wsdlPort; + private String endpointURI; + private InterfaceContract contract; + + // The Axis2 configuration that the binding creates + private JMSSender jmsSender; + private JMSListener jmsListener; + + public Axis2ServiceBindingProvider(ExtensionPointRegistry extensionPoints, + RuntimeEndpoint endpoint, + ServletHost servletHost ) { + super(extensionPoints); + + this.extensionPoints = extensionPoints; + this.endpoint = endpoint; + this.servletHost = servletHost; + + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + this.wsBinding = (WebServiceBinding)endpoint.getBinding(); + this.component = (RuntimeComponent)endpoint.getComponent(); + this.service = (RuntimeComponentService)endpoint.getService(); + + // A WSDL document should always be present in the binding + if (wsBinding.getWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + service.getName()); + } + + // Set to use the Axiom data binding + contract = wsBinding.getBindingInterfaceContract(); + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + configContext = Axis2EngineIntegration.getAxisConfigurationContext(); + + // set the root context for this instance of Axis + configContext.setContextRoot(servletHost.getContextPath()); + + // Determine the configuration from the bindings "mayProvides" intents + + isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); + + isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + + // this is not correct as there may be other, custom, policies that + // require rampart. For example this is not going to pick up the case + // of external policy attachment + isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || + PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || + PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); + + + // Apply the configuration from any other policies + + for (PolicyProvider pp : endpoint.getPolicyProviders()) { + pp.configureBinding(this); + } + + // Update port addresses with runtime information + // We can safely assume there is only one port here because you configure + // a binding in the following ways: + // 1/ default - one port generated = host domain : host port / structural path + // 2/ uri="absolute addr" - one port generated = host domain : uri port / uri path + // 3/ uri="relative addr" - one port generated = host domain : host port / structural path / relative path + // 4/ wsdl.binding - one port generated = host domain : host port / structural path + // 5/ wsdl.port - one port generated = host domain : port port / port path + // 6/ wsa:Address - one port generated = host domain : address port / address path + // 7/ 4 + 6 - as 6 + wsdlPort = (Port)wsBinding.getService().getPorts().values().iterator().next(); + + if (wsdlPort == null){ + throw new ServiceRuntimeException("No WSDL port for ws binding of " + component.getName() + "/" + service.getName()); + } + + endpointURI = Axis2EngineIntegration.getPortAddress(wsdlPort); + + if (endpointURI.startsWith("jms:")) { + isJMSRequired = true; + } else { + if (servletHost == null) { + throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); + } + endpointURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); + } + + Axis2EngineIntegration.setPortAddress(wsdlPort, endpointURI); + + // Apply the configuration from the mayProvides intents + + if (isRampartRequired){ + // TODO - do we need to go back to configurator? + } + + if (isMTOMRequired) { + new Axis2MTOMPolicyProvider(endpoint).configureBinding(configContext); + } + + if (isJMSRequired){ + // TODO - do we need to go back to configurator? + } + } + + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + + public void start() { + try { + createAxisService(endpointURI, wsdlPort); + + if (endpointURI.startsWith("http://") || + endpointURI.startsWith("https://") || + endpointURI.startsWith("/")) { + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + + if (httpSecurityContext.isSSLEnabled()){ + servletHost.addServletMapping(endpointURI, servlet, httpSecurityContext); + } else { + servletHost.addServletMapping(endpointURI, servlet); + } + } else if (endpointURI.startsWith("jms")) { + logger.log(Level.INFO, "Axis2 JMS URL=" + endpointURI); + + jmsListener = new JMSListener(); + jmsSender = new JMSSender(); + ListenerManager listenerManager = configContext.getListenerManager(); + TransportInDescription trsIn = + configContext.getAxisConfiguration().getTransportIn(org.apache.axis2.Constants.TRANSPORT_JMS); + + // get JMS transport parameters from the computed URL +//not in Axis2 1.5.1 +// Map 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(org.apache.axis2.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); + } + } + + public void stop() { + try { + if (jmsListener != null) { + jmsListener.stop(); + jmsListener.destroy(); + } else { + servletHost.removeServletMapping(endpointURI); + } + + if (jmsSender != null) { + jmsSender.stop(); + } + + servletHost = null; + + // get the path to the service + // [nash] Need a leading slash for WSDL imports to work with ?wsdl + URI uriPath = new URI(endpointURI); + String stringURIPath = uriPath.getPath(); + configContext.getAxisConfiguration().removeService(stringURIPath); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + // Service specific utility operations + + private void createAxisService(String endpointURL, Port port) throws AxisFault { + AxisService axisService; + if (wsBinding.getWSDLDocument() != null) { + axisService = Axis2EngineIntegration.createWSDLAxisService(endpointURL, port, wsBinding); + } else { + axisService = Axis2EngineIntegration.createJavaAxisService(endpointURL, configContext, service); + } + + Axis2EngineIntegration.createAxisServiceProviders(axisService, endpoint, wsBinding, extensionPoints); + + configContext.getAxisConfiguration().addService(axisService); + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..fe05824875 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java @@ -0,0 +1,62 @@ +/* + * 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.provider; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + protected Operation operation; + + private Axis2ServiceProvider provider; + + public Axis2ServiceInMessageReceiver(Axis2ServiceProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + public Axis2ServiceInMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + + provider.invokeTarget(operation, args, inMC); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new RuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..152b8f3689 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java @@ -0,0 +1,99 @@ +/* + * 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.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + private static final Logger logger = Logger.getLogger(Axis2ServiceInOutSyncMessageReceiver.class.getName()); + + protected Operation operation; + + private Axis2ServiceProvider provider; + + public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + public Axis2ServiceInOutSyncMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = null; + + if (requestOM != null) { + args = new Object[] {requestOM}; + } + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.beforeInvoke(operation, args, inMC); + } + */ + + OMElement responseOM = (OMElement)provider.invokeTarget(operation, args, inMC); + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.afterInvoke(operation, args, inMC, responseOM); + } + */ + + SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); + if (null != responseOM ) { + soapEnvelope.getBody().addChild(responseOM); + } + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof FaultException && ((FaultException)t).getFaultInfo() instanceof OMElement) { + OMElement faultDetail = (OMElement)((FaultException)t).getFaultInfo(); + inMC.setProperty(Constants.FAULT_NAME, faultDetail.getQName().getLocalPart()); + AxisFault f = new AxisFault(null, e.getMessage(), "faultNode", "faultRole", faultDetail); + throw f; + } + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + logger.log(Level.SEVERE, e.getMessage(), t); + throw new ServiceRuntimeException(e); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceProvider.java new file mode 100644 index 0000000000..1d62e88f22 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceProvider.java @@ -0,0 +1,127 @@ +/* + * 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.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; + +import javax.annotation.Resource; +import javax.xml.namespace.QName; +import javax.xml.ws.Provider; +import javax.xml.ws.WebServiceContext; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +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.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class Axis2ServiceProvider implements Provider { + private static final Logger logger = Logger.getLogger(Axis2ServiceProvider.class.getName()); + + 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 RuntimeEndpoint endpoint; + private WebServiceBinding wsBinding; + private MessageFactory messageFactory; + private FactoryExtensionPoint modelFactories; + private RuntimeAssemblyFactory assemblyFactory; + + @Resource + WebServiceContext wsContext; + + public Axis2ServiceProvider(RuntimeEndpoint endpoint, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints) { + this.endpoint = endpoint; + this.wsBinding = wsBinding; + this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + } + + public OMElement invoke(OMElement arg0) { + // TODO - the interface for a JAX-WS provider. + // May make Axis2 integration cleaner + return null; + } + + public Object invokeTarget(Operation op, Object[] args, MessageContext inMC) throws InvocationTargetException { + String callbackAddress = null; + String callbackID = null; + + // create a message object and set the args as its body + Message msg = messageFactory.createMessage(); + msg.setBody(args); + msg.setOperation(op); + msg.setBindingContext(inMC); + + //FIXME: can we use the Axis2 addressing support for this? + SOAPHeader header = inMC.getEnvelope().getHeader(); + if (header != null) { + OMElement from = header.getFirstChildWithName(QNAME_WSA_FROM); + if (from != null) { + OMElement callbackAddrElement = from.getFirstChildWithName(QNAME_WSA_ADDRESS); + if (callbackAddrElement != null) { + if (endpoint.getService().getInterfaceContract().getCallbackInterface() != null) { + callbackAddress = callbackAddrElement.getText(); + } + } + } + } + + // Create a from EPR to hold the details of the callback endpoint + EndpointReference from = null; + if (callbackAddress != null ) { + from = assemblyFactory.createEndpointReference(); + Endpoint fromEndpoint = assemblyFactory.createEndpoint(); + from.setTargetEndpoint(fromEndpoint); + from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED); + msg.setFrom(from); + Endpoint callbackEndpoint = assemblyFactory.createEndpoint(); + callbackEndpoint.setURI(callbackAddress); + callbackEndpoint.setUnresolved(true); + from.setCallbackEndpoint(callbackEndpoint); + } + + Message response = endpoint.invoke(msg); + + if(response.isFault()) { + throw new InvocationTargetException((Throwable) response.getBody()); + } + return response.getBody(); + } +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java new file mode 100644 index 0000000000..f63e5af8e6 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java @@ -0,0 +1,311 @@ +/* + * 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.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.SocketException; +import java.net.URI; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.GenericServlet; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.transport.http.AxisServlet; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.transport.http.server.HttpUtils; + +/** + * This overrides the Servlet init of the AxisServlet so Tuscany can use + * a single Axis2 ConfigurationContext instance shared between AxisServlet + * instances for each SCA service with a ws binding. + * TODO: need to review if thats really what we want to be doing + * + * @version $Rev$ $Date$ + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected TuscanyListingAgent agent; + + private static final long serialVersionUID = 1L; + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + + private boolean initCalled = false; + +//JIRA TUSCANY-1561 Port to Axis2 1.3 + private ConfigurationContext tmpconfigContext; + + public void init(ConfigurationContext configContext) { + this.tmpconfigContext = configContext; + try { + //super.init(DUMMY_CONFIG); + init(DUMMY_CONFIG); + } catch (ServletException e) { + throw new RuntimeException(e); + } + agent = new TuscanyListingAgent(configContext); + } + + /** + * Override Axis2 Servlet method to avoid loop when init + * is called after servletConfig already initialized by + * this classes init(ConfigurationContext) method. + */ + @Override + public void init() throws ServletException { + } + + @Override + public void init(ServletConfig config) throws ServletException { + ServletContext servletContext = config.getServletContext(); + servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); + + super.init(config); + } + + /** + * We've setup the Servlet by passing in a ConfigurationContext on our init method + * override this method to just return that + */ + @Override + protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { + return this.tmpconfigContext; + } + + @Override + public ServletConfig getServletConfig() { + return DUMMY_CONFIG; + } + + @Override + public String getServletName() { + return "TuscanyAxis2Servlet"; + } + + /** + * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. + */ + private static ServletConfig createDummyServletConfig() { + ServletConfig sc = new ServletConfig() { + + public String getServletName() { + return "TuscanyAxis2DummyServlet"; + } + + public ServletContext getServletContext() { + return new ServletContext() { + + public ServletContext getContext(String uripath) { + return null; + } + + @SuppressWarnings("unused") // it's on the Servlet 2.5 API so we need it + public String getContextPath() { + return null; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public String getMimeType(String file) { + return null; + } + + public Set getResourcePaths(String path) { + return Collections.emptySet(); + } + + public URL getResource(String path) throws MalformedURLException { + if("/".equals(path)) { + // HACK: To avoid NPE + return new URL("/axis2"); + } + return null; + } + + public InputStream getResourceAsStream(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String arg0) { + return null; + } + + public Servlet getServlet(String arg0) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String arg0) { + } + + public void log(Exception arg0, String arg1) { + } + + public void log(String arg0, Throwable arg1) { + } + + public String getRealPath(String arg0) { + return null; + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + public Object getAttribute(String arg0) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String arg0, Object arg1) { + } + + public void removeAttribute(String arg0) { + } + + public String getServletContextName() { + return null; + } + }; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return new Vector().elements(); + } + }; + return sc; + } + + @Override + public void destroy() { + try { + super.destroy(); + servletConfig = null; + if (tmpconfigContext.getListenerManager() != null){ + tmpconfigContext.getListenerManager().destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Override the AxisServlet doGet to use the TuscanyListingAgent for ?wsdl + */ + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + initContextRoot(request); + + String query = request.getQueryString(); + if ((query != null) && (query.indexOf("wsdl2") >= 0 || + query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 || + query.indexOf("policy") >= 0)) { + agent.processListService(request, response); + } else { + super.doGet(request, response); + } + } + + /** + + /** + * 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 + String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT); + if (port == null) { + port = "8080"; + } + if (ip == null) { + try { + ip = HttpUtils.getIpAddress(); + if (ip == null) { + ip = "localhost"; + } + } catch (SocketException e) { +//TUSCANY-1561 Port to Axis2 1.3 +// throw new AxisFault.(e); + throw AxisFault.makeFault(e); + } + } + + URI epURI = URI.create("http://" + ip + ":" + port + "/" + serviceName).normalize(); + + return new EndpointReference[]{new EndpointReference(epURI.toString())}; + } + */ + +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java new file mode 100644 index 0000000000..0a20de5067 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java @@ -0,0 +1,104 @@ +/* + * 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.provider; + +import java.net.URI; +import java.util.HashMap; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.HandlerDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.RequestURIBasedDispatcher; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A Tuscany specific Axis2 Dispatcher that enables using services + * exposed at the SCA defined service URI instead of /services/ + * + * @version $Rev$ $Date$ + */ +public class TuscanyDispatcher extends RequestURIBasedDispatcher { + + public static final String NAME = "TuscanyDispatcher"; + private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class); + private static final boolean isDebugEnabled = log.isDebugEnabled(); + + /* + * (non-Javadoc) + * + * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext) + */ + @Override + public AxisService findService(MessageContext messageContext) throws AxisFault { + EndpointReference toEPR = messageContext.getTo(); + + if (toEPR != null) { + if(isDebugEnabled){ + log.debug("Checking for Service using target endpoint address : " + toEPR.getAddress()); + } + + String path = URI.create(toEPR.getAddress()).getPath(); + + ConfigurationContext configurationContext = messageContext.getConfigurationContext(); + AxisConfiguration registry = configurationContext.getAxisConfiguration(); + + String serviceName = findAxisServiceName(registry, path); + return registry.getService(serviceName); + + } else { + if(isDebugEnabled){ + log.debug("Attempted to check for Service using null target endpoint URI"); + } + return null; + } + } + + @Override + public void initDispatcher() { + init(new HandlerDescription(NAME)); + } + + protected String findAxisServiceName(AxisConfiguration registry, String path) { + HashMap services = registry.getServices(); + if (services == null) { + return null; + } + String[] parts = path.split("/"); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java new file mode 100644 index 0000000000..fd3bd18c34 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java @@ -0,0 +1,233 @@ +/* + * 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.provider; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.transport.http.server.HttpUtils; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; + +/** + * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work + * with the Tuscany service names which include slash ('/') characters. + * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. + * + * @version $Rev$ $Date$ + */ +public class TuscanyListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public TuscanyListingAgent(ConfigurationContext aConfigContext) { + super(aConfigContext); + } + + /** + * This method overrides the Axis2 listing agent's computation of the + * service name. + */ + @Override + public String extractServiceName(String urlString) { + String serviceName = findAxisServiceName(urlString); + setContextRoot(urlString, serviceName); + return serviceName; + } + + /** + * Override ?xsd processing so that WSDL documents with XSD imports + * and includes work correctly. When we move to Axis2 1.4, we may + * be able to use SchemaSupplier to do this in a cleaner way. Also + * ensure that the correct IP address and port are returned by ?wsdl. + */ + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + String url = req.getRequestURL().toString(); + String query = req.getQueryString(); + + // for ?wsdl requests, need to update the WSDL with correct IPaddr and port + int wsdl = query.indexOf("wsdl"); + if (wsdl >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + AxisService axisService = (AxisService)services.get(serviceName); + Parameter wsld4jdefinition = axisService.getParameter("wsdl4jDefinition"); + Definition definition = (Definition)wsld4jdefinition.getValue(); + for (Object s : definition.getServices().values()) { + for (Object p : ((Service)s).getPorts().values()) { + String endpointURL = Axis2EngineIntegration.getPortAddress((Port)p); + String modifiedURL = setIPAddress(endpointURL, url); + modifiedURL = addContextRoot(modifiedURL, serviceName); + Axis2EngineIntegration.setPortAddress((Port)p, modifiedURL); + } + } + } + } + + // handle ?xsd requests here + int xsd = query.indexOf("xsd"); + if (xsd >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + String xsds = req.getParameter("xsd"); + if (xsds != null && !"".equals(xsds)) { + // a schema name (perhaps with path) is present + AxisService axisService = (AxisService)serviceObj; + ArrayList schemas = axisService.getSchema(); + for (Object rootSchema : axisService.getSchema()) { + XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds); + if (schema != null) { + // found the schema + res.setContentType("text/xml"); + OutputStream out = res.getOutputStream(); + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + return; + } + } + } + } + } + } + + // in all other cases, delegate to the Axis2 code + super.processListService(req, res); + } + + private String addContextRoot(String modifiedURL, String serviceName) { + if (!"/".equals(configContext.getContextRoot())) { + if (modifiedURL.endsWith(serviceName)) { + URI uri = URI.create(modifiedURL); + if (!uri.getPath().startsWith(configContext.getContextRoot())) { + modifiedURL = modifiedURL.substring(0, modifiedURL.length() - serviceName.length()) + configContext.getContextRoot() + serviceName; + } + } + } + return modifiedURL; + } + + private XmlSchema getSchema(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + if (extSchema.getSchemaLocation().endsWith(name)) { + return extSchema.getSchema(); + } else { + XmlSchema schema = getSchema(extSchema.getSchema(), name); + if (schema != null) { + return schema; + } + } + } + } + return null; + } + + private String findAxisServiceName(String path) { + HashMap services = configContext.getAxisConfiguration().getServices(); + if (services == null) { + return null; + } + String[] parts = path.split("/"); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + + /** + * Hack for Tuscany to get ?wsdl working with Tuscany service names + * Can go once moved up to Axis2 1.3 + */ + private void setContextRoot(String filePart, String serviceName) { + String contextRoot = configContext.getContextRoot(); + if (contextRoot != null && contextRoot.length() > 0) { + if (contextRoot.equals("/")) { + configContext.setServicePath("/"); + } else { + int i = filePart.indexOf(contextRoot) + contextRoot.length(); + int j = filePart.lastIndexOf(serviceName); + if (i>=j || (i+1 == j)) { + configContext.setServicePath("/"); + } else { + String mapping = filePart.substring(i+1, j); + configContext.setServicePath(mapping); + } + } + configContext.setContextRoot(contextRoot); + } + } + + private static String setIPAddress(String wsdlURI, String requestURI) { + try { + URI wsdlURIObj = new URI(wsdlURI); + String wsdlHost = wsdlURIObj.getHost(); + int wsdlPort = wsdlURIObj.getPort(); + String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); + URI requestURIObj = new URI(requestURI); +// 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; + } + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory index fba2858221..d7843d0acb 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -16,5 +16,5 @@ # under the License. # Implementation class for the binding extension -org.apache.tuscany.sca.binding.ws.axis2.Axis2BindingProviderFactory;model=org.apache.tuscany.sca.binding.ws.WebServiceBinding +org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BindingProviderFactory;model=org.apache.tuscany.sca.binding.ws.WebServiceBinding diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml index 36573ff879..28fb6fac45 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml @@ -114,7 +114,7 @@ + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInMessageReceiver"/> @@ -123,11 +123,11 @@ + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInOutSyncMessageReceiver"/> + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInMessageReceiver"/> @@ -136,7 +136,7 @@ + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInOutSyncMessageReceiver"/> @@ -415,7 +415,7 @@ + class="org.apache.tuscany.sca.binding.ws.axis2.provider.TuscanyDispatcher"> -- cgit v1.2.3