You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/07/07 18:19:34 UTC
git commit: [CXF-5841] Mulitple identical policy references when
using annotations. Patch from Bartosz Baranowski applied
Repository: cxf
Updated Branches:
refs/heads/master fcb2f15aa -> c1617b0a1
[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/c1617b0a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c1617b0a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c1617b0a
Branch: refs/heads/master
Commit: c1617b0a193a63f7fc16b573d331b8028d48ba77
Parents: fcb2f15
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Jul 7 11:55:15 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jul 7 11:59:31 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/c1617b0a/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 c24b41d..5566ded 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.wsdl.WSDLConstants;
import org.apache.cxf.wsdl.WSDLManager;
import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
import org.apache.neethi.Constants;
-
import org.junit.Assert;
@@ -120,6 +120,7 @@ public class PolicyAnnotationTest extends Assert {
bus.shutdown(true);
}
}
+
@org.junit.Test
public void testAnnotationsInterfaceAsClass() throws Exception {
Bus bus = BusFactory.getDefaultBus();
@@ -180,12 +181,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 + "']",
@@ -197,7 +284,6 @@ public class PolicyAnnotationTest extends Assert {
xpu.isExist(path + "/wsp:PolicyReference[@URI='#" + uri + "']",
wsdl,
XPathConstants.NODE));
-
}
@Policies({
@@ -238,4 +324,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/c1617b0a/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 d2256f1..b35295e 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("#")) {