[jbossws-commits] JBossWS SVN: r16917 - in stack/cxf/trunk/modules/testsuite/cxf-tests: src/test/java/org/jboss/test/ws/jaxws/cxf and 4 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Oct 16 14:37:47 EDT 2012


Author: alessio.soldano at jboss.com
Date: 2012-10-16 14:37:47 -0400 (Tue, 16 Oct 2012)
New Revision: 16917

Added:
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpoint.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpointImpl.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderInstallerInterceptor.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderTestCase.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/META-INF/
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/META-INF/unknown-policy.xml
Modified:
   stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
Log:
Adding testcase on ignoring endpoint contract policies scenario (use of CXF IgnorablePolicyInterceptorProvider)


Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml	2012-10-16 10:41:53 UTC (rev 16916)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml	2012-10-16 18:37:47 UTC (rev 16917)
@@ -313,6 +313,21 @@
        </webinf>
     </war>
 
+    <!-- jaxws-cxf-policy -->
+    <jar destfile="${tests.output.dir}/test-libs/jaxws-cxf-policy.jar">
+      <fileset dir="${tests.output.dir}/test-classes">
+        <include name="org/jboss/test/ws/jaxws/cxf/policy/PIPEndpointImpl.class"/>
+        <include name="org/jboss/test/ws/jaxws/cxf/policy/CustomInInterceptor.class"/>
+      	<include name="org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderInstallerInterceptor.class"/>
+      </fileset>
+      <metainf dir="${tests.output.dir}/test-resources/jaxws/cxf/policy/META-INF">
+        <include name="**/*" />
+      </metainf>
+      <manifest>
+        <attribute name="Dependencies" value="org.apache.cxf.impl"/> <!-- cxf impl required due to custom interceptor using cxf-rt-ws-policy in deployment -->
+      </manifest>
+    </jar>
+
     <!-- jaxws-cxf-spring -->
     <war warfile="${tests.output.dir}/test-libs/jaxws-cxf-spring.war" needxmlfile='false'>
        <classes dir="${tests.output.dir}/test-classes">

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpoint.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpoint.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpoint.java	2012-10-16 18:37:47 UTC (rev 16917)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.policy;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+ at WebService
+public interface PIPEndpoint
+{
+   @WebMethod
+   public String echo(String input);
+   
+}

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpointImpl.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpointImpl.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PIPEndpointImpl.java	2012-10-16 18:37:47 UTC (rev 16917)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.policy;
+
+import javax.ejb.Stateless;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+import org.apache.cxf.annotations.Policy;
+import org.apache.cxf.interceptor.InInterceptors;
+
+ at WebService(name = "PIPEndpoint", targetNamespace = "http://policy.cxf.jaxws.ws.test.jboss.org/", serviceName = "PIPService")
+ at Stateless
+ at Policy(placement = Policy.Placement.BINDING, uri = "META-INF/unknown-policy.xml")
+ at InInterceptors(interceptors = {"org.jboss.test.ws.jaxws.cxf.policy.PolicyInterceptorProviderInstallerInterceptor"})
+public class PIPEndpointImpl
+{
+   @WebMethod
+   public String echo(String input)
+   {
+      return input;
+   }
+   
+}

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderInstallerInterceptor.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderInstallerInterceptor.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderInstallerInterceptor.java	2012-10-16 18:37:47 UTC (rev 16917)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.policy;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.ws.policy.IgnorablePolicyInterceptorProvider;
+import org.apache.cxf.ws.policy.PolicyInInterceptor;
+import org.apache.cxf.ws.policy.PolicyInterceptorProvider;
+import org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry;
+
+/**
+ * An interceptor that installs the IgnorablePolicyInterceptorProvider into the PolicyInterceptorProviderRegistry.
+ * That (a) makes CXF  believe it has implementation for the custom/unknown policy and (b) causes the custom/unknown
+ * policy assertion to be marked as asserted (by the IgnorableAssertionsInterceptor installed by the provider).
+ * 
+ * @author alessio.soldano at jboss.com
+ *
+ */
+public class PolicyInterceptorProviderInstallerInterceptor extends AbstractPhaseInterceptor<Message>
+{
+   private static QName customPolicyQname = new QName("http://my.custom.org/policy", "MyPolicy");
+
+   public PolicyInterceptorProviderInstallerInterceptor()
+   {
+      super(Phase.RECEIVE);
+      addBefore(PolicyInInterceptor.class.getName());
+   }
+
+   public void handleMessage(Message message) throws Fault
+   {
+      PolicyInterceptorProviderRegistry reg = message.getExchange().getBus()
+            .getExtension(PolicyInterceptorProviderRegistry.class);
+
+      Set<PolicyInterceptorProvider> set = reg.get(customPolicyQname);
+      if (set == null || set.isEmpty())
+      {
+         set = new HashSet<PolicyInterceptorProvider>();
+         set.add(new IgnorablePolicyInterceptorProvider(customPolicyQname));
+         reg.register(customPolicyQname, set);
+      }
+   }
+}

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderTestCase.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/policy/PolicyInterceptorProviderTestCase.java	2012-10-16 18:37:47 UTC (rev 16917)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.policy;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.ws.policy.IgnorablePolicyInterceptorProvider;
+import org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry;
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ * @author alessio.soldano at jboss.com
+ * @since 16-Oct-2012
+ */
+public class PolicyInterceptorProviderTestCase extends JBossWSTest
+{
+   private String endpointAddress = "http://" + getServerHost() + ":8080/jaxws-cxf-policy/PIPService/PIPEndpoint";
+
+   public static Test suite()
+   {
+      return new JBossWSCXFTestSetup(PolicyInterceptorProviderTestCase.class, "jaxws-cxf-policy.jar");
+   }
+
+   /**
+    * Verifies the policy-enabled client can be configured to ignore a given policy in the wsdl contract
+    * 
+    * @throws Exception
+    */
+   public void testUnsupportedPolicy() throws Exception
+   {
+      Bus bus = BusFactory.newInstance().createBus();
+      try
+      {
+         BusFactory.setThreadDefaultBus(bus);
+         
+         PolicyInterceptorProviderRegistry reg = bus.getExtension(PolicyInterceptorProviderRegistry.class);
+         reg.register(new IgnorablePolicyInterceptorProvider(new QName("http://my.custom.org/policy", "MyPolicy")));
+         
+         URL wsdlURL = new URL(endpointAddress + "?wsdl");
+         QName serviceName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPService");
+         Service service = Service.create(wsdlURL, serviceName);
+         QName portQName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPEndpointPort");
+         PIPEndpoint port = (PIPEndpoint)service.getPort(portQName, PIPEndpoint.class);
+
+         assertEquals("foo", port.echo("foo"));
+      }
+      finally
+      {
+         bus.shutdown(true);
+      }
+   }
+   
+   public void testUnsupportedPolicyFail() throws Exception
+   {
+      Bus bus = BusFactory.newInstance().createBus();
+      try
+      {
+         BusFactory.setThreadDefaultBus(bus);
+         
+         URL wsdlURL = new URL(endpointAddress + "?wsdl");
+         QName serviceName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPService");
+         Service service = Service.create(wsdlURL, serviceName);
+         QName portQName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPEndpointPort");
+         PIPEndpoint port = (PIPEndpoint)service.getPort(portQName, PIPEndpoint.class);
+
+         try {
+            port.echo("foo");
+         } catch (Exception e) {
+            assertTrue(e.getMessage().contains("None of the policy alternatives can be satisfied"));
+         }
+      }
+      finally
+      {
+         bus.shutdown(true);
+      }
+   }
+}

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/META-INF/unknown-policy.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/META-INF/unknown-policy.xml	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/policy/META-INF/unknown-policy.xml	2012-10-16 18:37:47 UTC (rev 16917)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy"
+	xmlns:cp="http://my.custom.org/policy">
+	<wsp:ExactlyOne>
+		<wsp:All>
+			<cp:MyPolicy/>
+		</wsp:All>
+	</wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file



More information about the jbossws-commits mailing list