You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/04/20 12:46:05 UTC

svn commit: r935864 - in /tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src: main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java

Author: slaws
Date: Tue Apr 20 10:46:05 2010
New Revision: 935864

URL: http://svn.apache.org/viewvc?rev=935864&view=rev
Log:
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.

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java
    tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java?rev=935864&r1=935863&r2=935864&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java Tue Apr 20 10:46:05 2010
@@ -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.
 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
 
     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<Source> metadata = new ArrayList<Source>();
-        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<Source> metadata = new ArrayList<Source>();
+        
+        // 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<String, Object> properties = new HashMap<String, Object>();
-        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());
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java?rev=935864&r1=935863&r2=935864&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java Tue Apr 20 10:46:05 2010
@@ -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 Te
     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 Te
         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();