From f01464e7c3ed67e24b2a828aeb13388a9770eca9 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 20 Apr 2010 10:46:05 +0000 Subject: Add ?wsdl generation and a simple WSDL test. The Tuscany WS model seems a bit unpredictable in terms of when certain properties will and won't be set. Need to tidy it up. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@935864 13f79535-47bb-0310-9956-ffa450edef68 --- .../ws/jaxws/ri/JAXWSServiceBindingProvider.java | 60 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java') diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java index f86176d0c6..2f9ff10cac 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java @@ -18,11 +18,19 @@ */ package org.apache.tuscany.sca.binding.ws.jaxws.ri; +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.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; import javax.xml.ws.Endpoint; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceProvider; @@ -37,6 +45,7 @@ import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.w3c.dom.Node; @WebServiceProvider @ServiceMode(Mode.MESSAGE) @@ -65,16 +74,55 @@ public class JAXWSServiceBindingProvider implements ServiceBindingProvider { public void start() { jaxwsBindingProvider.start(); + + // create the JAXWS endpoint based on the provider wsEndpoint = Endpoint.create(SOAPBinding.SOAP11HTTP_BINDING, jaxwsBindingProvider); - -/* TODO - set up WSDL for Provider - List metadata = new ArrayList(); - wsEndpoint.setMetadata(metadata); + + // 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(); + //set up WSDL for Provider + List metadata = new ArrayList(); + + // WSDL DOM seems to be null here so went with writing out + // string version of WSDL and reading it back in again + //Node node = wsBinding.getWSDLDefinition().getDefinition().getDocumentationElement(); + //Source source = new DOMSource(node); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + try { + WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(wsBinding.getWSDLDefinition().getDefinition(), outStream); + } catch (Exception ex){ + ex.printStackTrace(); + } + + //System.out.println(outStream.toString()); + ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); + Source source = new StreamSource(inStream); + source.setSystemId(targetNamespace); + + metadata.add(source); + Map properties = new HashMap(); - wsEndpoint.setProperties(properties); -*/ + + QName portName = new QName(targetNamespace, + wsBinding.getPort().getName()); + properties.put(Endpoint.WSDL_PORT, portName); + + QName serviceName = new QName(targetNamespace, + wsBinding.getService().getQName().getLocalPart()); + properties.put(Endpoint.WSDL_SERVICE, serviceName); + wsEndpoint.setMetadata(metadata); + wsEndpoint.setProperties(properties); + + // Start up the endpoint wsEndpoint.publish(wsBinding.getURI()); } -- cgit v1.2.3