You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2007/12/11 07:58:35 UTC

svn commit: r603157 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/

Author: mmao
Date: Mon Dec 10 22:58:31 2007
New Revision: 603157

URL: http://svn.apache.org/viewvc?rev=603157&view=rev
Log:
CXF-1188
   WS-Addressing - Automatically enable WSAdressingFeature 
     if wsdl contains "wsaw:UsingAddressing" element


Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/AddNumberImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java?rev=603157&r1=603156&r2=603157&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java Mon Dec 10 22:58:31 2007
@@ -19,9 +19,11 @@
 
 package org.apache.cxf.jaxws.support;
 
+import java.util.Iterator;
 import java.util.List;
 
 import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.ExtensionRegistry;
 import javax.xml.ws.Binding;
 import javax.xml.ws.WebServiceFeature;
@@ -89,7 +91,6 @@
         this.implInfo = implementorInfo;
         this.wsFeatures = wf;
         this.features = af;
-        
         resolveFeatures();
         createJaxwsBinding();
         
@@ -143,11 +144,37 @@
             inFault.add(new SOAPHandlerFaultInInterceptor(jaxwsBinding));
         }
         
-        if (!isFromWsdl) {
-            buildWsdlExtensibilities(ei.getBinding());
+        if (ei != null) {
+            if (!isFromWsdl) {
+                buildWsdlExtensibilities(ei.getBinding());
+            }
+            extractWsdlExtensibilities(ei);
+        }
+    }
+    
+    private void extractWsdlExtensibilities(EndpointInfo endpoint) {
+        List<ExtensibilityElement> bindingExtensors 
+            = endpoint.getBinding().getExtensors(ExtensibilityElement.class);
+        List<ExtensibilityElement> portExtensors 
+            = endpoint.getExtensors(ExtensibilityElement.class);
+        if (hasUsingAddressing(bindingExtensors) || hasUsingAddressing(portExtensors)) {
+            addAddressingFeature(new WSAddressingFeature());
         }
     }
     
+    private boolean hasUsingAddressing(List<ExtensibilityElement> exts) {
+        boolean found = false;
+        if (exts != null) {
+            Iterator<ExtensibilityElement> extensionElements = exts.iterator();
+            while (extensionElements.hasNext() && !found) {
+                ExtensibilityElement ext = 
+                    (ExtensibilityElement)extensionElements.next();
+                found = JAXWSAConstants.WSAW_USINGADDRESSING_QNAME.equals(ext.getElementType());
+            }
+        }
+        return found;
+    }    
+
     private void buildWsdlExtensibilities(BindingInfo bindingInfo) {
         Addressing addressing = getAddressing();
         if (addressing != null) {            

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/AddNumberImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/AddNumberImpl.java?rev=603157&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/AddNumberImpl.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/AddNumberImpl.java Mon Dec 10 22:58:31 2007
@@ -0,0 +1,55 @@
+/**
+ * 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.cxf.systest.ws.addr_wsdl;
+
+import javax.jws.WebService;
+
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault_Exception;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType;
+
+
+@WebService(serviceName = "AddNumbersService",
+            targetNamespace = "http://apache.org/cxf/systest/ws/addr_feature/")
+public class AddNumberImpl implements AddNumbersPortType {
+    public int addNumbers(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
+    }
+
+    public int addNumbers2(int number1, int number2) {
+        return number1 + number2;
+    }
+
+    public int addNumbers3(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
+    }
+
+    int execute(int number1, int number2) throws AddNumbersFault_Exception {
+        if (number1 < 0 || number2 < 0) {
+            AddNumbersFault fb = new AddNumbersFault();
+            fb.setDetail("Negative numbers cant be added!");
+            fb.setMessage("Numbers: " + number1 + ", " + number2);
+
+            throw new AddNumbersFault_Exception(fb.getMessage(), fb);
+        }
+
+        return number1 + number2;
+    }
+}

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java?rev=603157&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java Mon Dec 10 22:58:31 2007
@@ -0,0 +1,62 @@
+/**
+ * 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.cxf.systest.ws.addr_wsdl;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class Server extends AbstractBusTestServerBase {
+
+    protected void run() {
+        Object implementor = new AddNumberImpl();
+        String address = "http://localhost:9094/jaxws/add";
+        
+        EndpointImpl ep = new EndpointImpl(BusFactory.getThreadDefaultBus(), 
+                                           implementor, 
+                                           null, 
+                                           getWsdl());
+
+        //EndpointImpl ep = (EndpointImpl) Endpoint.create(implementor);
+        ep.publish(address);
+    }
+    
+    private String getWsdl() {
+        try {
+            java.net.URL wsdl = getClass().getResource("/wsdl/add_numbers.wsdl");
+            return wsdl.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }    
+
+    public static void main(String[] args) {
+        try {
+            Server s = new Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java?rev=603157&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/WSAPureWsdlTest.java Mon Dec 10 22:58:31 2007
@@ -0,0 +1,99 @@
+/**
+ * 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.cxf.systest.ws.addr_wsdl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersService;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class WSAPureWsdlTest extends AbstractBusClientServerTestBase {
+
+    private final QName serviceName = new QName("http://apache.org/cxf/systest/ws/addr_feature/",
+                                                "AddNumbersService");
+
+    @Before
+    public void setUp() throws Exception {
+        createBus();
+    }
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class));
+    }
+
+    private ByteArrayOutputStream setupInLogging() {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PrintWriter writer = new PrintWriter(bos, true);
+        LoggingInInterceptor in = new LoggingInInterceptor(writer);
+        this.bus.getInInterceptors().add(in);
+        return bos;
+    }
+
+    private ByteArrayOutputStream setupOutLogging() {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PrintWriter writer = new PrintWriter(bos, true);
+
+        LoggingOutInterceptor out = new LoggingOutInterceptor(writer);
+        this.bus.getOutInterceptors().add(out);
+
+        return bos;
+    }
+
+    @Test
+    public void testBasicInvocation() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
+        AddNumbersPortType port = getPort();
+
+        ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
+                                                        "http://localhost:9094/jaxws/add");
+
+        assertEquals(3, port.addNumbers(1, 2));
+
+        String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
+        String expectedOut = base + "addNumbersRequest</Action>";
+        String expectedIn = base + "addNumbersResponse</Action>";
+
+        assertTrue(output.toString().indexOf(expectedOut) != -1);
+        assertTrue(input.toString().indexOf(expectedIn) != -1);
+    }
+
+    private AddNumbersPortType getPort() {
+        URL wsdl = getClass().getResource("/wsdl/add_numbers.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull("Service is null ", service);
+        return service.getAddNumbersPort();
+    }
+}
\ No newline at end of file