You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/08/14 09:26:05 UTC

[cxf] branch master updated: Adding WS-Security test using JaxWsServerFactoryBean.

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new f6b0cb1  Adding WS-Security test using JaxWsServerFactoryBean.
f6b0cb1 is described below

commit f6b0cb1519f173e7cd393d435d35c67cb3ccab1a
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Aug 14 10:25:39 2018 +0100

    Adding WS-Security test using JaxWsServerFactoryBean.
---
 .../apache/cxf/systest/ws/action/ActionTest.java   | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
index 97496f7..7ce84f0 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
@@ -39,7 +39,9 @@ import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.jaxws.DispatchImpl;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.systest.ws.common.DoubleItImpl;
 import org.apache.cxf.systest.ws.common.KeystorePasswordCallback;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
 import org.apache.cxf.systest.ws.ut.SecurityHeaderCacheInterceptor;
@@ -61,6 +63,7 @@ import org.junit.BeforeClass;
  */
 public class ActionTest extends AbstractBusClientServerTestBase {
     public static final String PORT = allocatePort(Server.class);
+    public static final String PORT2 = allocatePort(Server.class, 2);
 
     private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
     private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
@@ -277,6 +280,50 @@ public class ActionTest extends AbstractBusClientServerTestBase {
         bus.shutdown(true);
     }
 
+    // Here the client is using "Actions", where the server is using an AsymmetricBinding policy,
+    // and we are building the service in code using JaxWsServerFactoryBean instead of Spring
+    @org.junit.Test
+    public void testAsymmetricActionToPolicyServerFactory() throws Exception {
+
+        JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
+        URL serviceWSDL = ActionTest.class.getResource("DoubleItActionPolicy.wsdl");
+        svrFactory.setWsdlLocation(serviceWSDL.toString());
+        String address = "http://localhost:" + PORT2 + "/DoubleItAsymmetric";
+        svrFactory.setAddress(address);
+        svrFactory.setServiceBean(new DoubleItImpl());
+        QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");
+        svrFactory.setEndpointName(portQName);
+
+        Map<String, Object> props = new HashMap<>();
+        props.put("security.callback-handler", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
+        props.put("security.signature.properties", "bob.properties");
+        props.put("security.encryption.properties", "alice.properties");
+        props.put("security.encryption.username", "alice");
+        svrFactory.setProperties(props);
+
+        org.apache.cxf.endpoint.Server server = svrFactory.create();
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = ActionTest.class.getResource("client.xml");
+
+        Bus bus = bf.createBus(busFile.toString());
+        BusFactory.setDefaultBus(bus);
+        BusFactory.setThreadDefaultBus(bus);
+
+        URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
+        Service service = Service.create(wsdl, SERVICE_QNAME);
+        DoubleItPortType port =
+                service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(port, PORT2);
+
+        // Successful call
+        assertEquals(50, port.doubleIt(25));
+
+        ((java.io.Closeable)port).close();
+        server.destroy();
+        bus.shutdown(true);
+    }
+
     // Here the client is using "Actions", where the server is using an AsymmetricBinding policy
     @org.junit.Test
     public void testAsymmetricEncryptBeforeSigningActionToPolicy() throws Exception {