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/01/19 18:03:25 UTC

[cxf] branch master updated: Adding programmatic example

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 eb190a0  Adding programmatic example
eb190a0 is described below

commit eb190a0151ba1bf78d7e0e4e4067717b41606ff7
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Jan 19 18:03:13 2018 +0000

    Adding programmatic example
---
 .../apache/cxf/systest/ws/action/ActionTest.java   | 14 ++++++
 .../org/apache/cxf/systest/ws/action/UTServer.java | 51 ++++++++++++++++++++++
 .../cxf/systest/ws/action/DoubleItAction.wsdl      |  3 ++
 .../org/apache/cxf/systest/ws/action/client.xml    | 13 ++++++
 4 files changed, 81 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 9e3be45..3c22310 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
@@ -57,6 +57,12 @@ public class ActionTest extends AbstractBusClientServerTestBase {
                 // set this to false to fork
                 launchServer(Server.class, true)
         );
+        assertTrue(
+                   "Server failed to launch",
+                   // run the server in the same process
+                   // set this to false to fork
+                   launchServer(UTServer.class, true)
+        );
     }
 
     @org.junit.AfterClass
@@ -104,6 +110,7 @@ public class ActionTest extends AbstractBusClientServerTestBase {
                 service.getPort(portQName, DoubleItPortType.class);
         updateAddressPort(port, PORT);
 
+
         // Successful call
         port.doubleIt(25);
 
@@ -119,6 +126,12 @@ public class ActionTest extends AbstractBusClientServerTestBase {
             assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
         }
 
+        // Here the Server is adding the WSS4JInInterceptor in code
+        portQName = new QName(NAMESPACE, "DoubleItUsernameTokenPort3");
+        port = service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(port, UTServer.PORT);
+
+        port.doubleIt(25);
 
         ((java.io.Closeable)port).close();
         bus.shutdown(true);
@@ -427,4 +440,5 @@ public class ActionTest extends AbstractBusClientServerTestBase {
         ((java.io.Closeable)port).close();
         bus.shutdown(true);
     }
+
 }
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/UTServer.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/UTServer.java
new file mode 100644
index 0000000..f832e5c
--- /dev/null
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/UTServer.java
@@ -0,0 +1,51 @@
+/**
+ * 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.action;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.systest.ws.common.DoubleItImpl;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
+
+/**
+ * Test adding the WSS4JInInterceptor in code.
+ */
+public class UTServer extends AbstractBusTestServerBase {
+
+    public static final String PORT = allocatePort(UTServer.class);
+
+    protected void run() {
+        Object implementor = new DoubleItImpl();
+        String address = "http://localhost:" + PORT + "/DoubleItUsernameToken3";
+        EndpointImpl jaxWsEndpoint = (EndpointImpl)Endpoint.publish(address, implementor);
+
+        Map<String, Object> properties = new HashMap<>();
+        properties.put("action", "UsernameToken");
+        properties.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.UTPasswordCallback");
+        WSS4JInInterceptor wss4jInInterceptor = new WSS4JInInterceptor(properties);
+
+        jaxWsEndpoint.getServer().getEndpoint().getInInterceptors().add(wss4jInInterceptor);
+    }
+}
diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/DoubleItAction.wsdl b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/DoubleItAction.wsdl
index ea3409e..9eb6888 100644
--- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/DoubleItAction.wsdl
+++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/DoubleItAction.wsdl
@@ -45,6 +45,9 @@
         <wsdl:port name="DoubleItUsernameTokenPort2" binding="tns:DoubleItNoSecurityBinding">
             <soap:address location="http://localhost:9001/DoubleItUsernameToken2"/>
         </wsdl:port>
+        <wsdl:port name="DoubleItUsernameTokenPort3" binding="tns:DoubleItNoSecurityBinding">
+            <soap:address location="http://localhost:9001/DoubleItUsernameToken3"/>
+        </wsdl:port>
         <wsdl:port name="DoubleItEncryptedPasswordPort" binding="tns:DoubleItNoSecurityBinding">
             <soap:address location="http://localhost:9001/DoubleItEncryptedPassword"/>
         </wsdl:port>
diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/client.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/client.xml
index cc02e28..6179b86 100644
--- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/client.xml
+++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/action/client.xml
@@ -64,6 +64,19 @@
             </bean>
         </jaxws:outInterceptors>
     </jaxws:client>
+    <jaxws:client name="{http://www.example.org/contract/DoubleIt}DoubleItUsernameTokenPort3" createdFromAPI="true">
+        <jaxws:outInterceptors>
+            <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
+                <constructor-arg>
+                    <map>
+                        <entry key="action" value="UsernameToken"/>
+                        <entry key="passwordCallbackClass" value="org.apache.cxf.systest.ws.common.UTPasswordCallback"/>
+                        <entry key="user" value="Alice"/>
+                    </map>
+                </constructor-arg>
+            </bean>
+        </jaxws:outInterceptors>
+    </jaxws:client>
     <jaxws:client name="{http://www.example.org/contract/DoubleIt}DoubleItEncryptedPasswordPort" createdFromAPI="true">
         <jaxws:outInterceptors>
             <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <co...@cxf.apache.org>'].