cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: [CXF-5841] Mulitple identical policy references when using annotations. Patch from Bartosz Baranowski applied
Date Mon, 07 Jul 2014 16:29:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes f27ee049a -> 2ac108e57


[CXF-5841] Mulitple identical policy references when using annotations.
Patch from Bartosz Baranowski applied


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

Branch: refs/heads/2.7.x-fixes
Commit: 2ac108e576444cfe3cd2516e5c5497ddc341ba3a
Parents: f27ee04
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Jul 7 11:55:15 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Jul 7 12:29:02 2014 -0400

----------------------------------------------------------------------
 .../cxf/jaxws/ws/PolicyAnnotationTest.java      | 115 ++++++++++++++++++-
 .../cxf/ws/policy/PolicyAnnotationListener.java |  27 ++++-
 2 files changed, 132 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/2ac108e5/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ws/PolicyAnnotationTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ws/PolicyAnnotationTest.java
b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ws/PolicyAnnotationTest.java
index 1a90a28..d499735 100644
--- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ws/PolicyAnnotationTest.java
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ws/PolicyAnnotationTest.java
@@ -19,10 +19,12 @@
 
 package org.apache.cxf.jaxws.ws;
 
+
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import javax.jws.WebMethod;
 
 import javax.jws.WebService;
 import javax.wsdl.Definition;
@@ -30,7 +32,6 @@ import javax.wsdl.xml.WSDLWriter;
 import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Element;
-
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.annotations.Policies;
@@ -45,7 +46,6 @@ import org.apache.cxf.ws.policy.PolicyEngine;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 import org.apache.neethi.Constants;
-
 import org.junit.Assert;
 
 
@@ -123,6 +123,7 @@ public class PolicyAnnotationTest extends Assert {
             bus.shutdown(true);
         }
     }
+
     @org.junit.Test
     public void testAnnotationsInterfaceAsClass() throws Exception {
         Bus bus = BusFactory.getDefaultBus();
@@ -185,12 +186,98 @@ public class PolicyAnnotationTest extends Assert {
                          xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/"
                                               + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']",
wsdl)
                              .getLength());
+
+        } finally {
+            bus.shutdown(true);
+        }
+    }
+
+    @org.junit.Test
+    public void testAnnotationImplNoInterface() throws Exception {
+        Bus bus = BusFactory.getDefaultBus();
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+        factory.setBus(bus);
+        factory.setServiceBean(new TestImplNoInterface());
+        factory.setStart(false);
+        List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/",
+                "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/",
+                "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
+
+        LocalTransportFactory f = new LocalTransportFactory();
+        f.getUriPrefixes().add("http");
+        f.setTransportIds(tp);
+
+        Server s = factory.create();
+
+        try {
+            ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
+            Definition def = builder.build();
+            WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
+            def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
+            Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
+
+            Map<String, String> ns = new HashMap<String, String>();
+            ns.put("wsdl", WSDLConstants.NS_WSDL11);
+            ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
+            ns.put("wsp", Constants.URI_POLICY_13_NS);
+            XPathUtils xpu = new XPathUtils(ns);
             
+            // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
+            assertEquals(1,
+                    xpu.getValueList("/wsdl:definitions/wsdl:binding/"
+                        + "wsp:PolicyReference[@URI='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']",
wsdl)
+                        .getLength());
+            final EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
+                    .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
+            assertNotNull(policy);
         } finally {
             bus.shutdown(true);
         }
     }
-    
+
+    @org.junit.Test
+    public void testAnnotationImplNoInterfacePolicies() throws Exception {
+        Bus bus = BusFactory.getDefaultBus();
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+        factory.setBus(bus);
+        factory.setServiceBean(new TestImplWithPoliciesNoInterface());
+        factory.setStart(false);
+        List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/",
+                "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/",
+                "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
+
+        LocalTransportFactory f = new LocalTransportFactory();
+        f.getUriPrefixes().add("http");
+        f.setTransportIds(tp);
+
+        Server s = factory.create();
+
+        try {
+            ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
+            Definition def = builder.build();
+            WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
+            def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
+            Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
+
+            Map<String, String> ns = new HashMap<String, String>();
+            ns.put("wsdl", WSDLConstants.NS_WSDL11);
+            ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
+            ns.put("wsp", Constants.URI_POLICY_13_NS);
+            XPathUtils xpu = new XPathUtils(ns);
+            
+            // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
+            assertEquals(1,
+                    xpu.getValueList("/wsdl:definitions/wsdl:binding/"
+                    + "wsp:PolicyReference[@URI='#TestImplWithPoliciesNoInterfaceServiceSoapBindingBindingPolicy']",
+                            wsdl).getLength());
+            final EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
+                    .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
+            assertNotNull(policy);
+        } finally {
+            bus.shutdown(true);
+        }
+    }
+
     private void check(XPathUtils xpu, Element wsdl, String path, String uri) {
         assertTrue(uri + " not found",
                    xpu.isExist("/wsdl:definitions/wsp:Policy[@wsu:Id='" + uri + "']",
@@ -202,7 +289,6 @@ public class PolicyAnnotationTest extends Assert {
                xpu.isExist(path + "/wsp:PolicyReference[@URI='#" + uri + "']",
                           wsdl,
                           XPathConstants.NODE));
-        
     }
     
     @Policies({
@@ -243,4 +329,25 @@ public class PolicyAnnotationTest extends Assert {
             return i;
         }
     }
+
+    @WebService()
+    @Policy(placement = Policy.Placement.BINDING, uri = "annotationpolicies/TestImplPolicy.xml")
+    public static class TestImplNoInterface {
+        @WebMethod
+        public int echoInt(int i) {
+            return i;
+        }
+    }
+
+    @WebService()
+    @Policies({
+        @Policy(placement = Policy.Placement.BINDING, uri = "annotationpolicies/TestImplPolicy.xml")
+     }
+    )
+    public static class TestImplWithPoliciesNoInterface {
+        @WebMethod
+        public int echoInt(int i) {
+            return i;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/2ac108e5/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
----------------------------------------------------------------------
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
index 561bcc9..8ee9a4c 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
@@ -90,7 +90,7 @@ public class PolicyAnnotationListener implements FactoryBeanListener {
             Endpoint ep = (Endpoint)args[1];
             if (ep.getEndpointInfo().getInterface() != null) {
                 addPolicies(factory, ep, cls);
-                
+            
                 // this will allow us to support annotations in Implementations, but only
for
                 // class level annotations.  Method level annotations are not currently supported
                 // for implementations.  The call has been moved here so that the ServiceInfo
@@ -362,7 +362,7 @@ public class PolicyAnnotationListener implements FactoryBeanListener {
                            Class<?> cls,
                            String defName) {
         Element el = addPolicy(service, p, cls, defName);
-        if (el != null) {
+        if (el != null && !isExistsPolicyReference(place.getExtensors().get(), getPolicyRefURI(el)))
{
             UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
             uee.setElement(el);
             uee.setRequired(true);
@@ -394,7 +394,7 @@ public class PolicyAnnotationListener implements FactoryBeanListener {
 
             // if not already added to service add it, otherwise ignore 
             // and just create the policy reference.
-            if (!isExistsPolicy(service, uri)) {
+            if (!isExistsPolicy(service.getDescription().getExtensors().get(), uri)) {
                 UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
                 uee.setElement(element);
                 uee.setRequired(true);
@@ -417,9 +417,10 @@ public class PolicyAnnotationListener implements FactoryBeanListener
{
         return element.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
                                      PolicyConstants.WSU_ID_ATTR_NAME);
     }
-    
-    private boolean isExistsPolicy(ServiceInfo service, String uri) {
-        Object exts[] = service.getDescription().getExtensors().get();
+    private String getPolicyRefURI(Element element) {
+        return element.getAttributeNS(null, "URI");
+    }
+    private boolean isExistsPolicy(Object exts[], String uri) {
         exts = exts == null ? new Object[0] : exts;
         for (Object o : exts) {
             if (o instanceof UnknownExtensibilityElement) {
@@ -432,6 +433,20 @@ public class PolicyAnnotationListener implements FactoryBeanListener
{
         }
         return false;
     }
+    
+    private boolean isExistsPolicyReference(Object exts[], String uri) {
+        exts = exts == null ? new Object[0] : exts;
+        for (Object o : exts) {
+            if (o instanceof UnknownExtensibilityElement) {
+                UnknownExtensibilityElement uee = (UnknownExtensibilityElement)o;
+                String uri2 = getPolicyRefURI(uee.getElement());
+                if (uri.equals(uri2)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 
     private Element loadPolicy(String uri, String defName) {
         if (!uri.startsWith("#")) {


Mime
View raw message