summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/modules
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-06-09 14:07:58 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-06-09 14:07:58 +0000
commitc50f998af7de3fcf7517238e933b0aeadd85ef1b (patch)
tree5d39910d3471b54bd553a0968945f869500c09d9 /sca-java-2.x/contrib/modules
parente45e9a67838dd78afca4a3ccb381d98996df51d5 (diff)
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
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2Dispatcher.java (renamed from sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/TuscanyDispatcher.java)2
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ListingAgent.java232
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/Axis2ServiceServlet.java268
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/axis2/JAXWSServiceBindingProvider.java169
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite2
-rw-r--r--sca-java-2.x/contrib/modules/binding-ws-runtime-jaxws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl2
6 files changed, 652 insertions, 23 deletions
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/Axis2Dispatcher.java
index 48e335db20..4dda3c45b4 100644
--- 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/Axis2Dispatcher.java
@@ -39,7 +39,7 @@ import org.apache.commons.logging.LogFactory;
*
* @version $Rev: 917502 $ $Date: 2010-03-01 12:54:07 +0000 (Mon, 01 Mar 2010) $
*/
-public class TuscanyDispatcher extends RequestURIBasedDispatcher {
+public class Axis2Dispatcher extends RequestURIBasedDispatcher {
public static final String NAME = "TuscanyDispatcher";
private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class);
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<String, DescriptionBuilderComposite> 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<ServiceDescription> 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/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 @@
<implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/>
<reference name="helloWorldWS">
<!--binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/-->
- <binding.ws uri="http://localhost:8085/services/HelloWorldService/HelloWorld"/>
+ <binding.ws uri="http://localhost:8085/HelloWorldService"/>
</reference>
</component>
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 @@
<wsdl:service name="HelloWorldService">
<wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort">
- <wsdlsoap:address location="http://localhost:8085/HelloWorldService/HelloWorld"/>
+ <wsdlsoap:address location="http://localhost:8085/HelloWorldService"/>
</wsdl:port>
</wsdl:service>