cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jp...@apache.org
Subject svn commit: r1437361 - in /cxf/trunk: rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/ systests/ws-securit...
Date Wed, 23 Jan 2013 12:17:25 GMT
Author: jpell
Date: Wed Jan 23 12:17:25 2013
New Revision: 1437361

URL: http://svn.apache.org/viewvc?rev=1437361&view=rev
Log:
CXF-4774 cache w3c Element in PolicyAttachment so can be serialised in wsdl

Modified:
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
    cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/JavaFirstPolicyServiceTest.java
    cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/policy/server/javafirstserver.xml

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
(original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
Wed Jan 23 12:17:25 2013
@@ -47,10 +47,7 @@ import java.util.Collection;
 
 import javax.wsdl.extensions.UnknownExtensibilityElement;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.XMLStreamException;
 
-import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -60,7 +57,6 @@ import org.apache.cxf.service.model.Bind
 import org.apache.cxf.service.model.DescriptionInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.service.model.Extensible;
-import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 import org.apache.cxf.ws.policy.attachment.external.PolicyAttachment;
 import org.apache.neethi.Constants;
 import org.apache.neethi.Policy;
@@ -99,7 +95,7 @@ public class ServiceModelPolicyUpdater {
 
             // Add wsp:Policy to top-level wsdl:definitions
             if (policyUsed) {
-                addPolicy(pa.getPolicy());
+                addPolicy(pa);
             }
         }
     }
@@ -118,35 +114,20 @@ public class ServiceModelPolicyUpdater {
         ext.addExtensor(uee);
     }
 
-    private void addPolicy(Policy p) {
-        try {
-            W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
-            p.serialize(writer);
-            Element policyEl = writer.getDocument().getDocumentElement();
-            
-            // FIXME - overwrite the Id to include the namespace prefix, for some reason
neethi does not do this!
-            Attr idAttr = policyEl.getAttributeNode(Constants.ATTR_ID);
-            if (null != idAttr) {
-                idAttr.setPrefix(Constants.ATTR_WSU);
-            }
-            
-            // Remove xmlns:xmlns attribute which Xerces chokes on
-            policyEl.removeAttribute("xmlns:xmlns");
+    private void addPolicy(PolicyAttachment pa) {
+        // TODO - do I need to defensively copy this?
+        Element policyEl = pa.getElement();
 
-            UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
-            uee.setElementType(new QName(p.getNamespace(), Constants.ELEM_POLICY));
-            uee.setElement(policyEl);
-
-            if (ei.getService().getDescription() == null) {
-                DescriptionInfo description = new DescriptionInfo();
-                description.setName(ei.getService().getName());
-                ei.getService().setDescription(description);
-            }
-            ei.getService().getDescription().addExtensor(uee);
-        } catch (XMLStreamException ex) {
-            throw new RuntimeException("Could not serialize policy", ex);
-        } catch (ParserConfigurationException e) {
-            throw new RuntimeException("Could not serialize policy", e);
+        UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+        uee.setRequired(true);
+        uee.setElementType(DOMUtils.getElementQName(policyEl));
+        uee.setElement(policyEl);
+
+        if (ei.getService().getDescription() == null) {
+            DescriptionInfo description = new DescriptionInfo();
+            description.setName(ei.getService().getName());
+            ei.getService().setDescription(description);
         }
+        ei.getService().getDescription().addExtensor(uee);
     }
 }

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java Wed
Jan 23 12:17:25 2013
@@ -121,6 +121,10 @@ public class WSPolicyFeature extends Abs
         pe.setServerEndpointPolicy(ei, ep.updatePolicy(p));
 
         // Add policy to the service model (and consequently to the WSDL)
+        // FIXME - ideally this should probably be moved up to where the policies are applied
to the
+        // endpoint, rather than this late.  As a consequence of its location, you have to
declare a
+        // ws policy feature on every endpoint in order to get any policy attachments into
the
+        // wsdl.  Alternatively add to the WSDLServiceBuilder somehow.
         ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei);
         for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) {
             if (pp instanceof ExternalAttachmentProvider) {

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
(original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
Wed Jan 23 12:17:25 2013
@@ -167,6 +167,7 @@ public class ExternalAttachmentProvider 
                 if (Node.ELEMENT_NODE != nd.getNodeType()) {
                     continue;
                 }
+                
                 QName qn = new QName(nd.getNamespaceURI(), nd.getLocalName());
                 if (Constants.isAppliesToElem(qn)) {
                     Collection<DomainExpression> des = readDomainExpressions((Element)nd);
@@ -181,6 +182,10 @@ public class ExternalAttachmentProvider 
                         p = p.merge(attachment.getPolicy());
                     }
                     attachment.setPolicy(p);
+                    
+                    // cache the element so it can be used when generating the wsdl
+                    attachment.setElement((Element) nd);
+
                 } else if (Constants.isPolicyRef(qn)) {
                     PolicyReference ref = builder.getPolicyReference(nd);
                     if (null != ref) {   

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
(original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
Wed Jan 23 12:17:25 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.ws.policy.attachment.external;
 
 import java.util.Collection;
+import org.w3c.dom.Element;
 
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingMessageInfo;
@@ -28,13 +29,11 @@ import org.apache.cxf.service.model.Endp
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.neethi.Policy;
 
-/**
- * 
- */
+
 public class PolicyAttachment {
-    
     private Collection<DomainExpression> domainExpressions;
     private Policy policy;
+    private Element element;
     
     public Collection<DomainExpression> getDomainExpressions() {
         return domainExpressions;
@@ -51,7 +50,15 @@ public class PolicyAttachment {
     public void setPolicy(Policy p) {
         policy = p;
     }
-    
+
+    public Element getElement() {
+        return element;
+    }
+
+    public void setElement(Element element) {
+        this.element = element;
+    }
+
     public boolean appliesTo(ServiceInfo si) {
         for (DomainExpression de : domainExpressions) {
             if (de.appliesTo(si)) {

Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/JavaFirstPolicyServiceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/JavaFirstPolicyServiceTest.java?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/JavaFirstPolicyServiceTest.java
(original)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/JavaFirstPolicyServiceTest.java
Wed Jan 23 12:17:25 2013
@@ -61,7 +61,14 @@ public class JavaFirstPolicyServiceTest 
     @org.junit.Test
     public void testJavaFirstAttachmentWsdl() throws Exception {
         Document doc = loadWsdl("JavaFirstAttachmentPolicyService");
+        testJavaFirstAttachmentWsdl(doc);
+        
+        // verify that the policy attachment not being defensively copied is working ok still!
+        Document doc2 = loadWsdl("JavaFirstAttachmentPolicyService2");
+        testJavaFirstAttachmentWsdl(doc2);
+    }
 
+    private void testJavaFirstAttachmentWsdl(Document doc) throws Exception {
         Element binding = DOMUtils.getFirstChildWithName(doc.getDocumentElement(), WSDL_NAMESPACE,
"binding");
         assertNotNull(binding);
         
@@ -94,8 +101,14 @@ public class JavaFirstPolicyServiceTest 
         assertEquals(1, policyMessages.size());
         
         assertEquals("UsernameToken", getPolicyId(policyMessages.get(0)));
+        
+        Element exactlyOne = DOMUtils.getFirstChildWithName(policyMessages.get(0), "", "ExactlyOne");
+        assertNull(exactlyOne);
+        
+        exactlyOne = DOMUtils.getFirstChildWithName(policyMessages.get(0), Constants.URI_POLICY_13_NS,
"ExactlyOne");
+        assertNotNull(exactlyOne);
     }
-    
+
     @org.junit.Test
     public void testJavaFirstWsdl() throws Exception {
         Document doc = loadWsdl("JavaFirstPolicyService");
@@ -123,6 +136,7 @@ public class JavaFirstPolicyServiceTest 
         
         List<Element> policyMessages = DOMUtils.getChildrenWithName(doc.getDocumentElement(),

                                                                     Constants.URI_POLICY_NS,
"Policy");
+        
         assertEquals(2, policyMessages.size());
         
         // validate that both the internal and external policies are included
@@ -135,7 +149,8 @@ public class JavaFirstPolicyServiceTest 
                                                          + "/" + serviceName + "?wsdl");
         InputStream is = connection.getInputStream();
         String wsdlContents = IOUtils.toString(is);
-
+        
+        //System.out.println(wsdlContents);
         return DOMUtils.readXml(new StringReader(wsdlContents));
     }
     

Modified: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/policy/server/javafirstserver.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/policy/server/javafirstserver.xml?rev=1437361&r1=1437360&r2=1437361&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/policy/server/javafirstserver.xml
(original)
+++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/policy/server/javafirstserver.xml
Wed Jan 23 12:17:25 2013
@@ -56,6 +56,9 @@
     <bean id="org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyService"
         class="org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyServiceImpl" />
     
+    <bean id="org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyService2"
+        class="org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyServiceImpl" />
+        
     <jaxws:endpoint 
        id="JavaFirstPolicyService"
        address="http://localhost:${testutil.ports.JavaFirstPolicyServer.2}/JavaFirstPolicyService"

@@ -70,6 +73,21 @@
     <jaxws:endpoint 
        id="JavaFirstAttachmentPolicyService"
        address="http://localhost:${testutil.ports.JavaFirstPolicyServer.2}/JavaFirstAttachmentPolicyService"

+       implementor="#org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyService2">
+        
+       <jaxws:properties>
+          <entry key="ws-security.callback-handler"
+                value="org.apache.cxf.systest.ws.wssec10.client.UTPasswordCallback" />
+       </jaxws:properties>
+       
+       <jaxws:features>
+			<p:policies />
+	   </jaxws:features>
+    </jaxws:endpoint> 
+    
+     <jaxws:endpoint 
+       id="JavaFirstAttachmentPolicyService2"
+       address="http://localhost:${testutil.ports.JavaFirstPolicyServer.2}/JavaFirstAttachmentPolicyService2"

        implementor="#org.apache.cxf.systest.ws.policy.JavaFirstAttachmentPolicyService">
         
        <jaxws:properties>



Mime
View raw message