cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/2] cxf git commit: Update to cxf frontend to create/use special Proxy interfaces that implement Closeable, BindingProvider, Client to work very nicely with Java7.
Date Thu, 09 Apr 2015 20:25:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5a2aa10e3 -> d88cd9e42


Update to cxf frontend to create/use special Proxy interfaces that implement Closeable, BindingProvider,
Client to work very nicely with Java7.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1c7a34e3
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1c7a34e3
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1c7a34e3

Branch: refs/heads/master
Commit: 1c7a34e313062edff246c2c1943d43b71b0f8aa7
Parents: 5a2aa10
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Apr 9 15:51:15 2015 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu Apr 9 15:51:15 2015 -0400

----------------------------------------------------------------------
 .../ws/addr_fromwsdl/WSAFromWSDLTest.java       | 92 ++++++++++----------
 .../tools/wsdlto/core/AbstractGenerator.java    |  6 ++
 .../jaxws/generators/ServiceGenerator.java      | 12 ++-
 .../wsdlto/frontend/jaxws/template/service.vm   | 19 ++++
 4 files changed, 84 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1c7a34e3/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
index f0994a6..3c8fbcd 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
@@ -31,6 +31,7 @@ import org.apache.cxf.systest.ws.AbstractWSATestBase;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault_Exception;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersService;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersService.AddNumbersPortTypeProxy;
 import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.addressing.AttributedURIType;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
@@ -137,67 +138,70 @@ public class WSAFromWSDLTest extends AbstractWSATestBase {
         ByteArrayOutputStream input = setupInLogging();
         ByteArrayOutputStream output = setupOutLogging();
 
-        AddNumbersPortType port = getPort();
+        try (AddNumbersPortTypeProxy port = getPort()) {
 
-        try {
-            port.addNumbers3(-1, 2);
-        } catch (AddNumbersFault_Exception ex) {
-            assert true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            assert false;
+            try {
+                port.addNumbers3(-1, 2);
+            } catch (AddNumbersFault_Exception ex) {
+                assert true;
+            } catch (Exception e) {
+                e.printStackTrace();
+                assert false;
+            }
+    
+            String expectedOut = "3in";
+            String expectedIn = "3fault";
+    
+            assertTrue(output.toString().indexOf(expectedOut) != -1);
+            assertTrue(input.toString().indexOf(expectedIn) != -1);
         }
-
-        String expectedOut = "3in";
-        String expectedIn = "3fault";
-
-        assertTrue(output.toString().indexOf(expectedOut) != -1);
-        assertTrue(input.toString().indexOf(expectedIn) != -1);
     }
     
     @Test
     public void testAnonToNonAnon() throws Exception {
-        AddNumbersPortType port = getPort();
-        ((BindingProvider)port).getRequestContext()
-            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
-                 "http://localhost:" + PORT + "/jaxws/addNonAnon");
-        try {
-            port.addNumbers3(-1, 2);
-        } catch (SOAPFaultException e) {
-            assertTrue(e.getFault().getFaultCode().contains("OnlyNonAnonymousAddressSupported"));
+        try (AddNumbersPortTypeProxy port = getPort()) {
+            port.getRequestContext()
+                .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                     "http://localhost:" + PORT + "/jaxws/addNonAnon");
+            try {
+                port.addNumbers3(-1, 2);
+            } catch (SOAPFaultException e) {
+                assertTrue(e.getFault().getFaultCode().contains("OnlyNonAnonymousAddressSupported"));
+            }
         }
     } 
     @Test
     public void testNonAnonToAnon() throws Exception {
-        AddNumbersPortType port = getPort();
-        ((BindingProvider)port).getRequestContext()
-            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
-                 "http://localhost:" + PORT + "/jaxws/addAnon");
-        
-        AddressingProperties maps = new AddressingProperties();
-        EndpointReferenceType ref = new EndpointReferenceType();
-        AttributedURIType add = new AttributedURIType();
-        add.setValue("http://localhost:" + INVALID_PORT + "/not/a/real/url");
-        ref.setAddress(add);
-        maps.setReplyTo(ref);
-        maps.setFaultTo(ref);
-
-        ((BindingProvider)port).getRequestContext()
-            .put("javax.xml.ws.addressing.context", maps);
-
-        try {
-            port.addNumbers3(-1, 2);
-        } catch (SOAPFaultException e) {
-            assertTrue(e.getFault().getFaultCode().contains("OnlyAnonymousAddressSupported"));
+        try (AddNumbersPortTypeProxy port = getPort()) {
+            port.getRequestContext()
+                .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                     "http://localhost:" + PORT + "/jaxws/addAnon");
+            
+            AddressingProperties maps = new AddressingProperties();
+            EndpointReferenceType ref = new EndpointReferenceType();
+            AttributedURIType add = new AttributedURIType();
+            add.setValue("http://localhost:" + INVALID_PORT + "/not/a/real/url");
+            ref.setAddress(add);
+            maps.setReplyTo(ref);
+            maps.setFaultTo(ref);
+    
+            port.getRequestContext()
+                .put("javax.xml.ws.addressing.context", maps);
+    
+            try {
+                port.addNumbers3(-1, 2);
+            } catch (SOAPFaultException e) {
+                assertTrue(e.getFault().getFaultCode().contains("OnlyAnonymousAddressSupported"));
+            }
         }
     }
-    private AddNumbersPortType getPort()throws Exception {
+    private AddNumbersPortTypeProxy getPort()throws Exception {
         URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
         assertNotNull("WSDL is null", wsdl);
 
         AddNumbersService service = new AddNumbersService(wsdl, serviceName);
         assertNotNull("Service is null ", service);
-        AddNumbersPortType port = service.getAddNumbersPort(new AddressingFeature());
+        AddNumbersPortTypeProxy port = service.getAddNumbersPort(new AddressingFeature());
         updateAddressPort(port, PORT);
         return port;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1c7a34e3/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
index e9e2ea9..0c1950d 100644
--- a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
+++ b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
@@ -117,6 +117,12 @@ public abstract class AbstractGenerator implements FrontEndGenerator
{
         setAttributes("fullversion", Version.getCompleteVersionString());
         setAttributes("name", Version.getName());
         setAttributes("mark-generated", env.optionSet(ToolConstants.CFG_MARK_GENERATED));
+        if (env.optionSet(ToolConstants.CFG_FRONTEND)) {
+            setAttributes("frontend", env.get(ToolConstants.CFG_FRONTEND));
+        }
+        if (env.optionSet(ToolConstants.CFG_DATABINDING)) {
+            setAttributes("databinding", env.get(ToolConstants.CFG_DATABINDING));
+        }
     }
 
     protected void clearAttributes() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/1c7a34e3/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/ServiceGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/ServiceGenerator.java
b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/ServiceGenerator.java
index 1715d4c..44345c7 100644
--- a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/ServiceGenerator.java
+++ b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/ServiceGenerator.java
@@ -21,12 +21,16 @@ package org.apache.cxf.tools.wsdlto.frontend.jaxws.generators;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import javax.jws.HandlerChain;
 import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
 
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.tools.common.ToolConstants;
@@ -106,11 +110,17 @@ public class ServiceGenerator extends AbstractJAXWSGenerator {
                     
                 }
     
+                Set<String> portNames = new HashSet<>();
                 for (JavaPort port : js.getPorts()) {
                     if (!port.getPackageName().equals(js.getPackageName())
                         && !port.getInterfaceClass().equals(js.getName())) {
                         js.addImport(port.getFullClassName());
                     }
+                    portNames.add(port.getInterfaceClass());
+                }
+                if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
+                    js.addImport(BindingProvider.class.getName());
+                    js.addImport(Client.class.getName());
                 }
     
                 String url = (String)env.get(ToolConstants.CFG_WSDLURL);
@@ -136,7 +146,7 @@ public class ServiceGenerator extends AbstractJAXWSGenerator {
                     useGetResource = true;
                 }
                 
-                
+                setAttributes("cxfPortClassnames", portNames.toArray(new String[portNames.size()]));
                 setAttributes("service", js);
                 setAttributes("wsdlLocation", location);
                 setAttributes("useGetResource", useGetResource);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1c7a34e3/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
----------------------------------------------------------------------
diff --git a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
index 2363a64..e22e7cb 100644
--- a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
+++ b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
@@ -199,11 +199,30 @@ public class ${service.Name} extends ${serviceSuperclass} {
     }    
 #end
 
+#if ($frontend == "cxf")
+#foreach ($portClassName in $cxfPortClassnames)
+    /**
+     * Proxy interface the extends ${portClassName} to also provide useful methods
+     * without having to cast to the appropriate interface. 
+     */
+#if ($mark-generated == "true")
+    @Generated(value = "org.apache.cxf.tools.wsdlto.WSDLToJava", date = "$currentdate")
+#end
+    public interface ${portClassName}Proxy extends ${portClassName}, AutoCloseable, BindingProvider,
Client {
+    }
+#end
+#end
+
 #foreach ($port in $service.Ports)
 #set($portClassName = ${port.InterfaceClass})
 #if ($portClassName == ${service.Name}) 
 #set($portClassName = ${port.fullClassName})
 #end
+
+#if ($frontend == "cxf")
+#set($portClassName = "${portClassName}Proxy")
+#end
+
     /**
 #if ($port.javaDoc != "")
 $port.javaDoc


Mime
View raw message