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 2011/08/31 20:07:09 UTC
svn commit: r1163724 - in /cxf/trunk/rt/ws/policy/src:
main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java
Author: dkulp
Date: Wed Aug 31 18:07:09 2011
New Revision: 1163724
URL: http://svn.apache.org/viewvc?rev=1163724&view=rev
Log:
[CXF-3776] Fix problems of duplicate policies in the wsdl if the service
class is set to the SEI instead of the concrete class.
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java
Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java?rev=1163724&r1=1163723&r2=1163724&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyAnnotationListener.java Wed Aug 31 18:07:09 2011
@@ -326,11 +326,13 @@ public class PolicyAnnotationListener im
Class<?> cls,
String defName) {
Element el = addPolicy(service, p, cls, defName);
- UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
- uee.setElement(el);
- uee.setRequired(true);
- uee.setElementType(DOMUtils.getElementQName(el));
- place.addExtensor(uee);
+ if (el != null) {
+ UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+ uee.setElement(el);
+ uee.setRequired(true);
+ uee.setElementType(DOMUtils.getElementQName(el));
+ place.addExtensor(uee);
+ }
}
private Element addPolicy(ServiceInfo service, Policy p, Class<?> cls, String defName) {
String uri = p.uri();
@@ -345,11 +347,7 @@ public class PolicyAnnotationListener im
service.setDescription(new DescriptionInfo());
service.getDescription().setBaseURI(cls.getResource("/").toString());
}
- UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
- uee.setElement(doc.getDocumentElement());
- uee.setRequired(true);
- uee.setElementType(DOMUtils.getElementQName(doc.getDocumentElement()));
- service.getDescription().addExtensor(uee);
+
uri = doc.getDocumentElement().getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
PolicyConstants.WSU_ID_ATTR_NAME);
if (StringUtils.isEmpty(uri)) {
@@ -360,6 +358,25 @@ public class PolicyAnnotationListener im
doc.getDocumentElement().setAttributeNodeNS(att);
}
ns = doc.getDocumentElement().getNamespaceURI();
+ Object exts[] = service.getDescription().getExtensors().get();
+ exts = exts == null ? new Object[0] : exts;
+ for (Object o : exts) {
+ if (o instanceof UnknownExtensibilityElement) {
+ UnknownExtensibilityElement uee = (UnknownExtensibilityElement)o;
+ String uri2 = uee.getElement()
+ .getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
+ PolicyConstants.WSU_ID_ATTR_NAME);
+ if (uri.equals(uri2)) {
+ return null;
+ }
+ }
+ }
+ UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+ uee.setElement(doc.getDocumentElement());
+ uee.setRequired(true);
+ uee.setElementType(DOMUtils.getElementQName(doc.getDocumentElement()));
+ service.getDescription().addExtensor(uee);
+
uri = "#" + uri;
} catch (XMLStreamException e) {
//ignore
Modified: cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java?rev=1163724&r1=1163723&r2=1163724&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java (original)
+++ cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyAnnotationTest.java Wed Aug 31 18:07:09 2011
@@ -93,7 +93,6 @@ public class PolicyAnnotationTest extend
ns.put("wsp", Constants.URI_POLICY_13_NS);
XPathUtils xpu = new XPathUtils(ns);
//org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
- check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");
check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy");
check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
@@ -107,6 +106,68 @@ public class PolicyAnnotationTest extend
"echoIntBindingOpInputPolicy");
check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
"echoIntBindingOpOutputPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");
+ } finally {
+ bus.shutdown(true);
+ }
+ }
+ @org.junit.Test
+ public void testAnnotationsInterfaceAsClass() throws Exception {
+ Bus bus = BusFactory.getDefaultBus();
+ JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+ factory.setBus(bus);
+ factory.setServiceBean(new TestImpl());
+ factory.setServiceClass(TestInterface.class);
+ 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(bus);
+ f.getUriPrefixes().add("http");
+ f.setTransportIds(tp);
+ f.setBus(bus);
+ f.register();
+
+
+ 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);
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestInterfacePortPortPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input",
+ "echoIntPortTypeOpInputPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output",
+ "echoIntPortTypeOpOutputPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/",
+ "TestInterfaceServiceSoapBindingBindingPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input",
+ "echoIntBindingOpInputPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
+ "echoIntBindingOpOutputPolicy");
+ check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestInterfaceServiceServicePolicy");
} finally {
bus.shutdown(true);
}
@@ -158,7 +219,7 @@ public class PolicyAnnotationTest extend
@Policy(uri = "annotationpolicies/TestImplPolicy.xml")
}
)
- @WebService()
+ @WebService(endpointInterface = "org.apache.cxf.ws.policy.PolicyAnnotationTest$TestInterface")
public static class TestImpl implements TestInterface {
public int echoInt(int i) {
return i;