cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1343731 - in /cxf/trunk/systests/ws-security/src/test: java/org/apache/cxf/systest/ws/fault/FaultTest.java resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl resources/org/apache/cxf/systest/ws/fault/server/server.xml
Date Tue, 29 May 2012 14:09:58 GMT
Author: coheigea
Date: Tue May 29 14:09:58 2012
New Revision: 1343731

URL: http://svn.apache.org/viewvc?rev=1343731&view=rev
Log:
Added a FaultTest using the client Dispatch API

Modified:
    cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
    cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl
    cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml

Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java?rev=1343731&r1=1343730&r2=1343731&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
(original)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/fault/FaultTest.java
Tue May 29 14:09:58 2012
@@ -22,14 +22,24 @@ package org.apache.cxf.systest.ws.fault;
 import java.net.URL;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.jaxws.DispatchImpl;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
 import org.apache.cxf.systest.ws.fault.server.Server;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.ws.security.WSConstants;
 import org.example.contract.doubleit.DoubleItPortType;
 import org.junit.BeforeClass;
 
@@ -126,5 +136,57 @@ public class FaultTest extends AbstractB
         bus.shutdown(true);
     }
     
+    @org.junit.Test
+    public void testSoap12Dispatch() throws Exception {
+        
+        URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl");
+        Service service = Service.create(wsdl, SERVICE_QNAME);
+        QName portQName = new QName(NAMESPACE, "DoubleItSoap12DispatchPort");
+
+        Dispatch<DOMSource> dispatch = 
+            service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD);
+        
+        // Creating a DOMSource Object for the request
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document requestDoc = db.newDocument();
+        Element root = requestDoc.createElementNS("http://www.example.org/schema/DoubleIt",
"ns2:DoubleIt");
+        root.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:ns2", "http://www.example.org/schema/DoubleIt");
+        Element number = requestDoc.createElementNS(null, "numberToDouble");
+        number.setTextContent("25");
+        root.appendChild(number);
+        requestDoc.appendChild(root);
+        DOMSource request = new DOMSource(requestDoc);
+
+        // Add WS-Security configuration
+        Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
+        client.getRequestContext().put(
+            "ws-security.callback-handler",
+            "org.apache.cxf.systest.ws.wssec10.client.KeystorePasswordCallback"
+        );
+        client.getRequestContext().put(
+            "ws-security.encryption.properties", 
+            "org/apache/cxf/systest/ws/wssec10/client/bob.properties"
+        );
+        client.getRequestContext().put("ws-security.encryption.username", "bob");
+
+        updateAddressPort(dispatch, PORT);
+        
+        // Make a successful request
+        client.getRequestContext().put("ws-security.username", "alice");
+        DOMSource response = dispatch.invoke(request);
+        assertNotNull(response);
+        
+        // Now make an invocation using another username
+        client.getRequestContext().put("ws-security.username", "bob");
+        client.getRequestContext().put("ws-security.password", "password");
+        try {
+            dispatch.invoke(request);
+            fail("Expected failure on bob");
+        } catch (Exception ex) {
+            assertTrue(ex.getMessage().contains("This is a fault"));
+        }
+    }
+    
     
 }

Modified: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl?rev=1343731&r1=1343730&r2=1343731&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl
(original)
+++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl
Tue May 29 14:09:58 2012
@@ -73,6 +73,26 @@
         </wsdl:operation>
     </wsdl:binding>
     
+    <wsdl:binding name="DoubleItSoap12DispatchBinding" type="tns:DoubleItPortType">
+        <wsp:PolicyReference URI="#DoubleItPlaintextPolicy" />
+        <soap12:binding style="document"
+            transport="http://schemas.xmlsoap.org/soap/http" />
+        <wsdl:operation name="DoubleIt">
+            <soap12:operation soapAction="" style="document"/>
+            <wsdl:input>
+                <soap12:body use="literal" />
+            </wsdl:input>
+            <wsdl:output>
+                <soap12:body use="literal" />
+                <wsp:PolicyReference URI="#DoubleItBinding_DoubleIt_Output_Policy"/>
+            </wsdl:output>
+            <wsdl:fault name="DoubleItFault">
+                <wsp:PolicyReference URI="#DoubleItBinding_DoubleIt_Output_Policy"/>
+                <soap12:fault use="literal" name="DoubleItFault" />
+            </wsdl:fault>
+        </wsdl:operation>
+    </wsdl:binding>
+    
     <wsdl:service name="DoubleItService">
         <wsdl:port name="DoubleItSoap11Port" binding="tns:DoubleItSoap11Binding">
             <soap:address location="http://localhost:9009/DoubleItSoap11" />
@@ -80,6 +100,9 @@
         <wsdl:port name="DoubleItSoap12Port" binding="tns:DoubleItSoap12Binding">
             <soap12:address location="http://localhost:9009/DoubleItSoap12" />
         </wsdl:port>
+        <wsdl:port name="DoubleItSoap12DispatchPort" binding="tns:DoubleItSoap12DispatchBinding">
+            <soap12:address location="http://localhost:9009/DoubleItSoap12Dispatch" />
+        </wsdl:port>
     </wsdl:service>
 
     <wsp:Policy wsu:Id="DoubleItPlaintextPolicy">

Modified: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml?rev=1343731&r1=1343730&r2=1343731&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml
(original)
+++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/fault/server/server.xml
Tue May 29 14:09:58 2012
@@ -79,4 +79,22 @@
      
     </jaxws:endpoint> 
     
+    <jaxws:endpoint 
+       id="Soap12Dispatch"
+       address="http://localhost:${testutil.ports.Server}/DoubleItSoap12Dispatch" 
+       serviceName="s:DoubleItService"
+       endpointName="s:DoubleItSoap12DispatchPort"
+       xmlns:s="http://www.example.org/contract/DoubleIt"
+       implementor="org.apache.cxf.systest.ws.fault.DoubleItPortTypeImpl"
+       wsdlLocation="org/apache/cxf/systest/ws/fault/DoubleItFault.wsdl">
+        
+       <jaxws:properties>
+           <entry key="ws-security.callback-handler" 
+                  value="org.apache.cxf.systest.ws.wssec10.client.KeystorePasswordCallback"/>
+           <entry key="ws-security.signature.properties" 
+                  value="org/apache/cxf/systest/ws/wssec10/client/bob.properties"/> 
+       </jaxws:properties> 
+     
+    </jaxws:endpoint> 
+    
 </beans>



Mime
View raw message