From c50f998af7de3fcf7517238e933b0aeadd85ef1b Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 9 Jun 2010 14:07:58 +0000 Subject: Add some code to install the JAXWS provider into Axis and copy the code from the old binding to integrate the Axis2 runtime with our servler container. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@953017 13f79535-47bb-0310-9956-ffa450edef68 --- .../binding/ws/jaxws/axis2/Axis2Dispatcher.java | 104 ++++++++ .../binding/ws/jaxws/axis2/Axis2ListingAgent.java | 232 ++++++++++++++++++ .../ws/jaxws/axis2/Axis2ServiceServlet.java | 268 +++++++++++++++++++++ .../jaxws/axis2/JAXWSServiceBindingProvider.java | 169 +++++++++++-- .../binding/ws/jaxws/axis2/TuscanyDispatcher.java | 104 -------- .../binding/ws/axis2/wsdlport/helloworld.composite | 2 +- .../sca/binding/ws/axis2/wsdlport/helloworld.wsdl | 2 +- 7 files changed, 755 insertions(+), 126 deletions(-) create mode 100644 sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2Dispatcher.java create mode 100644 sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ListingAgent.java create mode 100644 sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ServiceServlet.java delete mode 100644 sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/TuscanyDispatcher.java (limited to 'sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src') diff --git a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2Dispatcher.java b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2Dispatcher.java new file mode 100644 index 0000000000..4dda3c45b4 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2Dispatcher.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.jaxws.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: 917502 $ $Date: 2010-03-01 12:54:07 +0000 (Mon, 01 Mar 2010) $ + */ +public class Axis2Dispatcher 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/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ListingAgent.java b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ListingAgent.java new file mode 100644 index 0000000000..8ea0865cc4 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ListingAgent.java @@ -0,0 +1,232 @@ +/* + * 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.jaxws.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.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: 938419 $ $Date: 2010-04-27 13:28:09 +0100 (Tue, 27 Apr 2010) $ + */ +public class Axis2ListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public Axis2ListingAgent(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/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ServiceServlet.java b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ServiceServlet.java new file mode 100644 index 0000000000..a270c39960 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ServiceServlet.java @@ -0,0 +1,268 @@ +/* + * 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.jaxws.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +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.context.ConfigurationContext; +import org.apache.axis2.transport.http.AxisServlet; + +/** + * 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: 938419 $ $Date: 2010-04-27 13:28:09 +0100 (Tue, 27 Apr 2010) $ + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected Axis2ListingAgent 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 Axis2ListingAgent(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); + } + } + + +} diff --git a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/JAXWSServiceBindingProvider.java b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/JAXWSServiceBindingProvider.java index c32c5964c9..e5f297c9fc 100644 --- a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/JAXWSServiceBindingProvider.java +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/JAXWSServiceBindingProvider.java @@ -18,77 +18,201 @@ */ package org.apache.tuscany.sca.binding.ws.jaxws.axis2; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLWriter; -import javax.xml.namespace.QName; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; +import javax.wsdl.Port; +import javax.xml.ws.Binding; import javax.xml.ws.Endpoint; -import javax.xml.ws.ServiceMode; -import javax.xml.ws.WebServiceProvider; -import javax.xml.ws.Service.Mode; -import org.apache.axis2.jaxws.server.endpoint.EndpointImpl; +import org.apache.axiom.om.OMElement; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.jaxws.binding.BindingUtils; +import org.apache.axis2.jaxws.description.DescriptionFactory; +import org.apache.axis2.jaxws.description.EndpointDescription; +import org.apache.axis2.jaxws.description.ServiceDescription; +import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite; +import org.apache.axis2.jaxws.description.builder.WebServiceProviderAnnot; +import org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter; +import org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; import org.apache.tuscany.sca.binding.ws.jaxws.JAXWSBindingProvider; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.SecurityContext; 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.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.apache.tuscany.sca.runtime.RuntimeProperties; +import org.oasisopen.sca.ServiceRuntimeException; public class JAXWSServiceBindingProvider implements ServiceBindingProvider { + // Tuscany extensions + private ExtensionPointRegistry extensionPoints; + private ServletHost servletHost; + + // Tuscany WS service data + private RuntimeComponent component; + private RuntimeComponentService service; private RuntimeEndpoint endpoint; + private InterfaceContract contract; private WebServiceBinding wsBinding; + private Port wsdlPort; + private String endpointURI; + private String deployedURI; + protected SecurityContext httpSecurityContext; + // JAXWS fields private JAXWSBindingProvider jaxwsBindingProvider; - private Endpoint wsEndpoint; + + // Axis2 fields + private ConfigurationContext configContext; public JAXWSServiceBindingProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint, ServletHost servletHost) { + this.extensionPoints = extensionPoints; + this.endpoint = endpoint; + this.wsBinding = (WebServiceBinding)endpoint.getBinding(); + this.component = (RuntimeComponent)endpoint.getComponent(); + this.contract = wsBinding.getBindingInterfaceContract(); + this.service = (RuntimeComponentService)endpoint.getService(); + this.servletHost = servletHost; + + // TODO + this.httpSecurityContext = new SecurityContext(); + + // Set to use the Axiom data binding + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + // 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()); + } + + // 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:")) { + deployedURI = endpointURI; + //isJMSRequired = true; + } else { + if (servletHost == null) { + throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); + } + deployedURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); + } + + wsBinding.setURI(deployedURI); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + + // TODO === String defaultPort = "8085"; RuntimeProperties ps = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(RuntimeProperties.class); String pp = ps.getProperties().getProperty(this.getClass().getName() + ".defaultPort"); if (pp != null) { defaultPort = ps.getProperties().getProperty(this.getClass().getName() + ".defaultPort"); } - - this.endpoint = endpoint; - this.wsBinding = (WebServiceBinding)endpoint.getBinding(); + // ======== jaxwsBindingProvider = new JAXWSBindingProvider(endpoint, servletHost, modelFactories, dataBindings, defaultPort); + + // get the Axis configuration context + configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); + configContext.setContextRoot(servletHost.getContextPath()); } + + public void start() { + // experiment in how to install a JAXWS provider into Axis2 programatically + try { + // create the service description + JavaClassToDBCConverter converter = new JavaClassToDBCConverter(jaxwsBindingProvider.getClass()); + HashMap dbcMap = converter.produceDBC(); + // Set the details of the service we are going to expose through this provider + // TODO - There is something odd in the way that service name is calculated in + // some circumstances + // sometimes getServiceName() returns null + // sometimes getService().getQName returns a QName namespace that doesn't match the WSDL + // sometimes getNamespace() returns null + // So here we delve directly into the WSDL4J model as the Tuscany model isn't up to date + String targetNamespace = wsBinding.getWSDLDefinition().getDefinition().getTargetNamespace(); + WebServiceProviderAnnot webServiceProviderAnnot = WebServiceProviderAnnot.createWebServiceAnnotImpl(); + webServiceProviderAnnot.setTargetNamespace(targetNamespace); + webServiceProviderAnnot.setServiceName(wsBinding.getService().getQName().getLocalPart()); + webServiceProviderAnnot.setPortName(wsBinding.getPort().getName()); + + // adjust the service description to match the service we're actually exposing + DescriptionBuilderComposite dbc = dbcMap.values().iterator().next(); + dbc.setWebServiceProviderAnnot(webServiceProviderAnnot); + dbc.setWsdlDefinition(wsBinding.getWSDLDefinition().getDefinition()); + List serviceDescList = DescriptionFactoryImpl.createServiceDescriptionFromDBCMap(dbcMap, configContext); + ServiceDescription sd = null; + if (serviceDescList != null && serviceDescList.size() > 0) { + sd = serviceDescList.get(0); + } + + // get the first endpoint + EndpointDescription endpointDesc = sd.getEndpointDescriptions_AsCollection().iterator().next(); + //Binding binding = BindingUtils.createBinding(endpointDesc); + + // Add the service into the configuration context + AxisService axisService = endpointDesc.getAxisService(); + axisService.setName(endpointURI); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + deployedURI); + axisService.setClientSide(false); + configContext.getAxisConfiguration().addService(axisService); + + // fire up the Axis servlet + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + servletHost.addServletMapping(deployedURI, servlet); + + } catch (Exception ex){ + ex.printStackTrace(); + } + } +/* public void start() { - // experiment in how to install a JAXWS provider into Axis programmitcally starting + // experiment in how to install a JAXWS provider into Axis programatically starting // with just using the JAXWS API. This is unlikely to be sufficient as we have to // install policy etc but it's a start // create the JAXWS endpoint based on the provider //wsEndpoint = Endpoint.create(SOAPBinding.SOAP11HTTP_BINDING, jaxwsBindingProvider); - wsEndpoint = new EndpointImpl(jaxwsBindingProvider); + //wsEndpoint = new EndpointImpl(jaxwsBindingProvider); + wsEndpoint = Endpoint.create(jaxwsBindingProvider); // TODO - There is something odd in the way that service name is calculated in // some circumstances @@ -137,9 +261,14 @@ public class JAXWSServiceBindingProvider implements ServiceBindingProvider { // Start up the endpoint wsEndpoint.publish(wsBinding.getURI()); + System.out.println("isPublished: " + wsEndpoint.isPublished()); + System.out.println("getProperties: " + wsEndpoint.getProperties()); + System.out.println("getMetadata: " + wsEndpoint.getMetadata()); + System.out.println("getEndpointReference: " + wsEndpoint.getEndpointReference()); + jaxwsBindingProvider.start(); - } +*/ public void stop() { jaxwsBindingProvider.stop(); diff --git a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/TuscanyDispatcher.java b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/TuscanyDispatcher.java deleted file mode 100644 index 48e335db20..0000000000 --- a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/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.jaxws.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: 917502 $ $Date: 2010-03-01 12:54:07 +0000 (Mon, 01 Mar 2010) $ - */ -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/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite index bd9c4c8d08..1078adc814 100644 --- a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite @@ -26,7 +26,7 @@ - + diff --git a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl index 8e90573bc7..3051cf7cfb 100644 --- a/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl +++ b/sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl @@ -73,7 +73,7 @@ - + -- cgit v1.2.3