Repository: cxf
Updated Branches:
  refs/heads/master 1592a6773 -> 10897281f


[CXF-5645]:Fix wsp:Optional isn't adhered to for WS-RM policy in WSDL


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

Branch: refs/heads/master
Commit: 10897281ffaf746b845004002d81313ed31d67ed
Parents: 1592a67
Author: Jim Ma <[email protected]>
Authored: Fri Mar 28 16:11:26 2014 +0800
Committer: Jim Ma <[email protected]>
Committed: Fri Mar 28 16:11:26 2014 +0800

----------------------------------------------------------------------
 .../apache/cxf/ws/rm/AbstractRMInterceptor.java |  11 +-
 .../apache/cxf/ws/rm/RMDeliveryInterceptor.java |   7 ++
 .../org/apache/cxf/ws/rm/RMInInterceptor.java   |   4 +-
 .../cxf/systest/ws/rm/policy/Greeting.java      |  33 ++++++
 .../systest/ws/rm/policy/GreetingService.java   |  40 +++++++
 .../apache/cxf/systest/ws/rm/policy/Server.java |  46 ++++++++
 .../ws/rm/policy/WSRMOptionalPolicyTest.java    |  58 ++++++++++
 .../cxf/systest/ws/rm/policy/greeting.wsdl      | 105 +++++++++++++++++++
 8 files changed, 301 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/AbstractRMInterceptor.java
----------------------------------------------------------------------
diff --git 
a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/AbstractRMInterceptor.java 
b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/AbstractRMInterceptor.java
index 8fb44bb..894fb95 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/AbstractRMInterceptor.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/AbstractRMInterceptor.java
@@ -118,7 +118,16 @@ public abstract class AbstractRMInterceptor<T extends 
Message> extends AbstractP
             ai.setAsserted(true);
         }
     }
-    
     protected abstract void handle(Message message) throws SequenceFault, 
RMException;
+    protected boolean isRMPolicyEnabled(Message msg) {
+        AssertionInfoMap assertionMap = msg.get(AssertionInfoMap.class);
+        if (assertionMap == null) {
+            return false;
+        }
+        if (!RMPolicyUtilities.collectRMAssertions(assertionMap).isEmpty()) {
+            return true;
+        }
+        return false;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMDeliveryInterceptor.java
----------------------------------------------------------------------
diff --git 
a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMDeliveryInterceptor.java 
b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMDeliveryInterceptor.java
index e3f7245..262e066 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMDeliveryInterceptor.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMDeliveryInterceptor.java
@@ -26,6 +26,8 @@ import org.apache.cxf.interceptor.OutgoingChainInterceptor;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.ws.addressing.AddressingProperties;
+import org.apache.cxf.ws.addressing.ContextUtils;
 
 /**
  * Interceptor used for InOrder delivery of messages to the destination. This 
works with
@@ -44,6 +46,11 @@ public class RMDeliveryInterceptor extends 
AbstractRMInterceptor<Message> {
     // Interceptor interface 
     
     public void handle(Message message) throws SequenceFault, RMException {
+        final AddressingProperties maps = ContextUtils.retrieveMAPs(message, 
false, false, false);
+        //if wsrmp:RMAssertion and addressing is optional
+        if (maps == null && isRMPolicyEnabled(message)) {
+            return;
+        }
         LOG.entering(getClass().getName(), "handleMessage");
         Destination dest = getManager().getDestination(message);
         final boolean robust =

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java 
b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
index 27ae927..4d44acb 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
@@ -89,12 +89,12 @@ public class RMInInterceptor extends 
AbstractRMInterceptor<Message> {
         LOG.fine("isServerSide: " + isServer);
 
         RMProperties rmps = RMContextUtils.retrieveRMProperties(message, 
false);
-        
         // message addressing properties may be null, e.g. in case of a 
runtime fault 
         // on the server side
         final AddressingProperties maps = ContextUtils.retrieveMAPs(message, 
false, false, false);
         if (null == maps) {
-            if (isServer) {
+            //if wsrmp:RMAssertion and addressing is optional
+            if (isServer && !isRMPolicyEnabled(message)) {
                 org.apache.cxf.common.i18n.Message msg = new 
org.apache.cxf.common.i18n.Message(
                     "WSA_REQUIRED_EXC", LOG);
                 LOG.log(Level.INFO, msg.toString());

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Greeting.java
----------------------------------------------------------------------
diff --git 
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Greeting.java
 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Greeting.java
new file mode 100644
index 0000000..9b15262
--- /dev/null
+++ 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Greeting.java
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.systest.ws.rm.policy;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://ws.samples.apache.org/";, serviceName = 
"GreetingService", 
+            portName = "GreetingServicePort")
+public interface Greeting {
+    @WebMethod
+    String hello(@WebParam(name = "name") String name);
+
+    @WebMethod
+    String goodbye(@WebParam(name = "name") String name);
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/GreetingService.java
----------------------------------------------------------------------
diff --git 
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/GreetingService.java
 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/GreetingService.java
new file mode 100644
index 0000000..8a51dd1
--- /dev/null
+++ 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/GreetingService.java
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.systest.ws.rm.policy;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://ws.samples.apache.org/";, 
+            serviceName = "GreetingService", portName = "GreetingServicePort", 
+            wsdlLocation = 
"classpath:/org/apache/cxf/systest/ws/rm/policy/greeting.wsdl")
+public class GreetingService implements Greeting {
+
+    @WebMethod
+    public String hello(@WebParam(name = "name") String name) {
+        return String.format("Hello, %s!", name);
+    }
+
+    @WebMethod
+    public String goodbye(@WebParam(name = "name") String name) {
+        return String.format("Goodbye, %s!", name);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Server.java
----------------------------------------------------------------------
diff --git 
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Server.java 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Server.java
new file mode 100644
index 0000000..26c6296
--- /dev/null
+++ 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/Server.java
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.systest.ws.rm.policy;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class Server extends AbstractBusTestServerBase {
+    public static final String PORT = allocatePort(Server.class);
+    private static final String ADDRESS = "http://localhost:"; + PORT + 
"/GreetingServer";
+
+    protected void run() {
+        GreetingService implementor = new GreetingService();
+        Endpoint.publish(ADDRESS, implementor);
+    }
+
+    public static void main(String[] args) {
+        try {
+            Server s = new Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/WSRMOptionalPolicyTest.java
----------------------------------------------------------------------
diff --git 
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/WSRMOptionalPolicyTest.java
 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/WSRMOptionalPolicyTest.java
new file mode 100644
index 0000000..848a551
--- /dev/null
+++ 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/WSRMOptionalPolicyTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.systest.ws.rm.policy;
+
+import java.net.URL;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class WSRMOptionalPolicyTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = Server.PORT;
+    private static final URL WSDL = 
GreetingService.class.getResource("greeting.wsdl");
+    private static final QName SERVICE = new 
QName("http://ws.samples.apache.org/";, "GreetingService");
+    private static final String ENDPOINT = "http://localhost:"; + PORT + 
"/GreetingServer";
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", 
launchServer(Server.class, true));
+    }
+
+    @Test
+    public void testBasicConnection() throws Exception {
+        Greeting service = createService();
+        assertTrue("Hello, cxf!".equals(service.hello("cxf")));
+        assertTrue("Goodbye, cxf!".equals(service.goodbye("cxf")));
+    }
+
+    private static Greeting createService() {
+        Greeting service = Service.create(WSDL, 
SERVICE).getPort(Greeting.class);
+        Map<String, Object> context = 
((BindingProvider)service).getRequestContext();
+        context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT);
+        return service;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/10897281/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/greeting.wsdl
----------------------------------------------------------------------
diff --git 
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/greeting.wsdl
 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/greeting.wsdl
new file mode 100644
index 0000000..439e208
--- /dev/null
+++ 
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/policy/greeting.wsdl
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<wsdl:definitions name="GreetingService" 
targetNamespace="http://ws.samples.apache.org/"; 
xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap/http";
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; 
xmlns:tns="http://ws.samples.apache.org/"; 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+    <wsdl:types>
+        <xs:schema elementFormDefault="unqualified" 
targetNamespace="http://ws.samples.apache.org/"; version="1.0"
+            xmlns:tns="http://ws.samples.apache.org/"; 
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+            <xs:element name="hello" type="tns:hello" />
+            <xs:element name="helloResponse" type="tns:helloResponse" />
+            <xs:element name="goodbye" type="tns:goodbye" />
+            <xs:element name="goodbyeResponse" type="tns:goodbyeResponse" />
+            <xs:complexType name="hello">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="name" type="xs:string" />
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="helloResponse">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="return" type="xs:string" />
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="goodbye">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="name" type="xs:string" />
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="goodbyeResponse">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="return" type="xs:string" />
+                </xs:sequence>
+            </xs:complexType>
+        </xs:schema>
+    </wsdl:types>
+    <wsdl:message name="hello">
+        <wsdl:part element="tns:hello" name="parameters" />
+    </wsdl:message>
+    <wsdl:message name="helloResponse">
+        <wsdl:part element="tns:helloResponse" name="parameters" />
+    </wsdl:message>
+    <wsdl:message name="goodbye">
+        <wsdl:part element="tns:goodbye" name="parameters" />
+    </wsdl:message>
+    <wsdl:message name="goodbyeResponse">
+        <wsdl:part element="tns:goodbyeResponse" name="parameters" />
+    </wsdl:message>
+    <wsdl:portType name="GreetingService">
+        <wsdl:operation name="hello">
+            <wsdl:input message="tns:hello" name="hello" />
+            <wsdl:output message="tns:helloResponse" name="helloResponse" />
+        </wsdl:operation>
+        <wsdl:operation name="goodbye">
+            <wsdl:input message="tns:goodbye" name="goodbye" />
+            <wsdl:output message="tns:goodbyeResponse" name="goodbyeResponse" 
/>
+        </wsdl:operation>
+    </wsdl:portType>
+    <wsdl:binding name="GreetingServiceSoapBinding" type="tns:GreetingService">
+        <wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy";>
+            <wsam:Addressing 
xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata"; wsp:Optional="true" 
/>
+            <wsrmp:RMAssertion 
xmlns:wsrmp="http://schemas.xmlsoap.org/ws/2005/02/rm/policy";
+                wsp:Optional="true" />
+        </wsp:Policy>
+        <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"; />
+        <wsdl:operation name="hello">
+            <soap:operation soapAction="" style="document" />
+            <wsdl:input name="hello">
+                <soap:body use="literal" />
+            </wsdl:input>
+            <wsdl:output name="helloResponse">
+                <soap:body use="literal" />
+            </wsdl:output>
+        </wsdl:operation>
+        <wsdl:operation name="goodbye">
+            <soap:operation soapAction="" style="document" />
+            <wsdl:input name="goodbye">
+                <soap:body use="literal" />
+            </wsdl:input>
+            <wsdl:output name="goodbyeResponse">
+                <soap:body use="literal" />
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="GreetingService">
+        <wsdl:port binding="tns:GreetingServiceSoapBinding" 
name="GreetingServicePort">
+            <soap:address location="http://localhost:8080/sample/greeting"; />
+        </wsdl:port>
+    </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file

Reply via email to