cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r784183 - in /cxf/trunk: distribution/src/main/appended-resources/META-INF/ rt/ws/policy/src/main/appended-resources/ rt/ws/policy/src/main/appended-resources/META-INF/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt/ws/policy/src/m...
Date Fri, 12 Jun 2009 16:29:32 GMT
Author: dkulp
Date: Fri Jun 12 16:29:32 2009
New Revision: 784183

URL: http://svn.apache.org/viewvc?rev=784183&view=rev
Log:
[CXF-2281] WS-PolicyAttachment support for Java First services
Patch from Dominic Harries applied (with some modifications)
>From University of Southampton IT Innovation Centre

Added:
    cxf/trunk/rt/ws/policy/src/main/appended-resources/
    cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/
    cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE   (with props)
    cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
  (with props)
Modified:
    cxf/trunk/distribution/src/main/appended-resources/META-INF/NOTICE
    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

Modified: cxf/trunk/distribution/src/main/appended-resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/appended-resources/META-INF/NOTICE?rev=784183&r1=784182&r2=784183&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/appended-resources/META-INF/NOTICE (original)
+++ cxf/trunk/distribution/src/main/appended-resources/META-INF/NOTICE Fri Jun 12 16:29:32
2009
@@ -24,6 +24,8 @@
 This Product also includes software developed by David Heinemeier Hansson.
 (http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb)
 
+This product includes software Copyright University of Southampton IT Innovation Centre,
2009 
+(http://www.it-innovation.soton.ac.uk). 
 
 This product also includes MTOSI wsdl and schemas developed by the
 TeleManagement Forum (http://www.tmforum.org/browse.aspx). The original

Added: cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE?rev=784183&view=auto
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE (added)
+++ cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE Fri Jun 12 16:29:32
2009
@@ -0,0 +1,6 @@
+
+This product includes software Copyright University of Southampton IT Innovation Centre,
2009 
+(http://www.it-innovation.soton.ac.uk). 
+
+ 
+

Propchange: cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/ws/policy/src/main/appended-resources/META-INF/NOTICE
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=784183&view=auto
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
(added)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
Fri Jun 12 16:29:32 2009
@@ -0,0 +1,127 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/////////////////////////////////////////////////////////////////////////
+//
+// Copyright University of Southampton IT Innovation Centre, 2009
+//
+// Copyright in this library belongs to the University of Southampton
+// University Road, Highfield, Southampton, UK, SO17 1BJ
+//
+// This software may not be used, sold, licensed, transferred, copied
+// or reproduced in whole or in part in any manner or form or in or
+// on any media by any person other than in accordance with the terms
+// of the License Agreement supplied with the software, or otherwise
+// without the prior written consent of the copyright owners.
+//
+// This software is distributed WITHOUT ANY WARRANTY, without even the
+// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE, except where stated in the License Agreement supplied with
+// the software.
+//
+//  Created By :            Dominic Harries
+//  Created Date :          2009-03-31
+//  Created for Project :   BEinGRID
+//
+/////////////////////////////////////////////////////////////////////////
+
+
+package org.apache.cxf.ws.policy;
+
+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.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.service.model.BindingOperationInfo;
+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;
+
+public class ServiceModelPolicyUpdater {
+    private EndpointInfo ei;
+
+    public ServiceModelPolicyUpdater(EndpointInfo ei) {
+        this.ei = ei;
+    }
+
+    public void addPolicyAttachments(Collection<PolicyAttachment> attachments) {
+        for (PolicyAttachment pa : attachments) {
+            boolean policyUsed = false;
+            String policyId = pa.getPolicy().getId();
+
+            // Add wsp:PolicyReference to wsdl:binding/wsdl:operation
+            for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
+                if (pa.appliesTo(boi)) {
+                    addPolicyRef(boi, policyId);
+                    // Add it to wsdl:portType/wsdl:operation too
+                    addPolicyRef(ei.getInterface().getOperation(boi.getName()), policyId);
+                    policyUsed = true;
+                }
+            }
+
+            // Add wsp:Policy to top-level wsdl:definitions
+            if (policyUsed) {
+                addPolicy(pa.getPolicy());
+            }
+        }
+    }
+
+    private void addPolicyRef(Extensible ext, String policyId) {
+        Document doc = DOMUtils.createDocument();
+        Element el = doc.createElementNS(Constants.URI_POLICY_NS, Constants.ELEM_POLICY_REF);
+        el.setPrefix(Constants.ATTR_WSP);
+        el.setAttribute(Constants.ATTR_URI, "#" + policyId);
+
+        UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+        uee.setElementType(new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY_REF));
+        uee.setElement(el);
+        uee.setRequired(true);
+
+        ext.addExtensor(uee);
+    }
+
+    private void addPolicy(Policy p) {
+        try {
+            W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
+            p.serialize(writer);
+            Element policyEl = writer.getDocument().getDocumentElement();
+
+            // Remove xmlns:xmlns attribute which Xerces chokes on
+            policyEl.removeAttribute("xmlns:xmlns");
+
+            UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+            uee.setElementType(new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY));
+            uee.setElement(policyEl);
+
+            ei.getService().addExtensor(uee);
+        } catch (XMLStreamException ex) {
+            throw new RuntimeException("Could not serialize policy", ex);
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException("Could not serialize policy", e);
+        }
+    }
+}

Propchange: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServiceModelPolicyUpdater.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=784183&r1=784182&r2=784183&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 Fri
Jun 12 16:29:32 2009
@@ -33,6 +33,7 @@
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider;
 import org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver;
 import org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver;
 import org.apache.neethi.Policy;
@@ -123,6 +124,14 @@
         EndpointInfo ei = endpoint.getEndpointInfo();
         EndpointPolicy ep = pe.getServerEndpointPolicy(ei, null);
         pe.setServerEndpointPolicy(ei, ep.updatePolicy(p));
+
+        // Add policy to the service model (and consequently to the WSDL)
+        ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei);
+        for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) {
+            if (pp instanceof ExternalAttachmentProvider) {
+                pu.addPolicyAttachments(((ExternalAttachmentProvider) pp).getAttachments());
+            }
+        }
     }
 
     private Policy initializeEndpointPolicy(Endpoint endpoint, Bus bus) {

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=784183&r1=784182&r2=784183&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
Fri Jun 12 16:29:32 2009
@@ -247,7 +247,7 @@
         attachments = a;    
     }
     
-    Collection<PolicyAttachment> getAttachments() {
+    public Collection<PolicyAttachment> getAttachments() {
         return attachments;
     }
     



Mime
View raw message