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 +++++++++++++++++++--- .../sca/binding/ws/axis2/WSDLPortTestCase.java | 54 +++++++++++++++++-- 2 files changed, 105 insertions(+), 9 deletions(-) (limited to 'sca-java-2.x/trunk/modules') 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()); } diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java index 967babeae5..5c4bee15e8 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java @@ -19,6 +19,20 @@ package org.apache.tuscany.sca.binding.ws.axis2; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + import junit.framework.TestCase; import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; @@ -31,9 +45,6 @@ public class WSDLPortTestCase extends TestCase { private Node node; private HelloWorld helloWorld; - public void testCalculator() throws Exception { - assertEquals("Hello petra", helloWorld.getGreetings("petra")); - } @Override protected void setUp() throws Exception { @@ -43,6 +54,43 @@ public class WSDLPortTestCase extends TestCase { helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); } + public void testMessageExchange() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + public void testQuestionMarkWSDL() throws Exception { + InputStream inp = new URL("http://localhost:8085/HelloWorldService/HelloWorld?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/HelloWorldService/HelloWorld?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://helloworld", + "HelloWorldService")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8085/HelloWorldService/HelloWorld", endpoint); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + @Override protected void tearDown() throws Exception { node.stop(); -- cgit v1.2.3