cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r599254 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/ systests/src/test/java/org/apac...
Date Thu, 29 Nov 2007 03:41:33 GMT
Author: mmao
Date: Wed Nov 28 19:41:28 2007
New Revision: 599254

URL: http://svn.apache.org/viewvc?rev=599254&view=rev
Log:
CXF-1191 
 * WS-A action support faultAction for both implicit and explicit action


Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
    incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/AddNumberImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/AddNumberImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java
    incubator/cxf/trunk/systests/src/test/resources/wsdl/add_numbers.wsdl

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
Wed Nov 28 19:41:28 2007
@@ -222,4 +222,15 @@
         chars[0] = Character.toUpperCase(chars[0]);
         return new String(chars);
     }
+    
+    public static String uncapitalize(String str) {
+        int strLen = str.length();
+        if (str == null || strLen == 0) {
+            return str;
+        }
+        return new StringBuffer(strLen)
+            .append(Character.toLowerCase(str.charAt(0)))
+            .append(str.substring(1))
+            .toString();
+    }    
 }

Modified: incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
(original)
+++ incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
Wed Nov 28 19:41:28 2007
@@ -30,15 +30,19 @@
 import java.util.logging.Logger;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.xml.namespace.QName;
+import javax.xml.ws.WebFault;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.FaultMode;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.OperationInfo;
 import org.apache.cxf.transport.Conduit;
@@ -415,12 +419,49 @@
         return null;
     }
 
+    private boolean isSameFault(final FaultInfo faultInfo, String faultName) {
+        String faultInfoName = faultInfo.getName().getLocalPart();
+        return faultInfoName.equals(faultName) 
+            || faultInfoName.equals(StringUtils.uncapitalize(faultName));
+    }
+
+    private String getActionBaseUri(final OperationInfo operation) {
+        String interfaceName = operation.getInterface().getName().getLocalPart();
+        return addPath(operation.getName().getNamespaceURI(), interfaceName);
+    }
+
+    private String getActionFromFaultMessage(final OperationInfo operation, final String
faultName) {
+        if (operation.getFaults() != null) {
+            for (FaultInfo faultInfo : operation.getFaults()) {
+                if (isSameFault(faultInfo, faultName)) {
+                    if (faultInfo.getExtensionAttributes() != null) {
+                        QName faultAction = (QName)faultInfo.getExtensionAttribute(WSAW_ACTION_QNAME);
+                        return faultAction.getLocalPart();
+                    }
+                    return addPath(addPath(getActionBaseUri(operation), "Fault"), 
+                                   faultInfo.getName().getLocalPart());
+                }
+            }
+        }
+        return null;
+    }
+
+    private String getFaultNameFromMessage(final Message message) {
+        Exception e = message.getContent(Exception.class);
+        if (e instanceof Fault) {
+            WebFault t = e.getCause().getClass().getAnnotation(WebFault.class);
+            if (t != null) {
+                return t.name();
+            }
+        }
+        return null;    
+    }
+
     protected String getActionUri(Message message) {
         OperationInfo op = message.getExchange().get(OperationInfo.class);
-        String interfaceName = op.getInterface().getName().getLocalPart();
 
         String actionUri = null;
-        String opNamespace = addPath(op.getName().getNamespaceURI(), interfaceName);
+        String opNamespace = getActionBaseUri(op);
         
         if (ContextUtils.isRequestor(message)) {
             String explicitAction = getActionFromInputMessage(op);
@@ -431,6 +472,9 @@
             } else {
                 actionUri = addPath(opNamespace, op.getInputName());
             }
+        } else if (ContextUtils.isFault(message)) {
+            String faultName = getFaultNameFromMessage(message);
+            actionUri = getActionFromFaultMessage(op, faultName);
         } else {
             String explicitAction = getActionFromOutputMessage(op);
             if (explicitAction != null) {

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/AddNumberImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/AddNumberImpl.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/AddNumberImpl.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/AddNumberImpl.java
Wed Nov 28 19:41:28 2007
@@ -27,15 +27,28 @@
 @Addressing
 @WebService
 public class AddNumberImpl implements AddNumbersPortType {
-    public int addNumbers(int number1, int number2) {
-        return number1 + number2;
+    public int addNumbers(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
     }
 
     public int addNumbers2(int number1, int number2) {
         return number1 + number2;
     }
 
-    public int addNumbers3(int number1, int number2) {
+    public int addNumbers3(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
+    }
+
+
+    int execute(int number1, int number2) throws AddNumbersFault_Exception {
+        if (number1 < 0 || number2 < 0) {
+            AddNumbersFault fb = new AddNumbersFault();
+            fb.setDetail("Negative numbers cant be added!");
+            fb.setMessage("Numbers: " + number1 + ", " + number2);
+
+            throw new AddNumbersFault_Exception(fb.getMessage(), fb);
+        }
+
         return number1 + number2;
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/AddNumberImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/AddNumberImpl.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/AddNumberImpl.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/AddNumberImpl.java
Wed Nov 28 19:41:28 2007
@@ -21,6 +21,9 @@
 
 import javax.jws.WebService;
 import javax.xml.ws.soap.Addressing;
+
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault_Exception;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType;
 
 // Jax-WS 2.1 WS-Addressing FromWsdl
@@ -29,15 +32,27 @@
 @WebService(serviceName = "AddNumbersService",
             targetNamespace = "http://apache.org/cxf/systest/ws/addr_feature/")
 public class AddNumberImpl implements AddNumbersPortType {
-    public int addNumbers(int number1, int number2) {
-        return number1 + number2;
+    public int addNumbers(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
     }
 
     public int addNumbers2(int number1, int number2) {
         return number1 + number2;
     }
 
-    public int addNumbers3(int number1, int number2) {
+    public int addNumbers3(int number1, int number2) throws AddNumbersFault_Exception {
+        return execute(number1, number2);
+    }
+
+    int execute(int number1, int number2) throws AddNumbersFault_Exception {
+        if (number1 < 0 || number2 < 0) {
+            AddNumbersFault fb = new AddNumbersFault();
+            fb.setDetail("Negative numbers cant be added!");
+            fb.setMessage("Numbers: " + number1 + ", " + number2);
+
+            throw new AddNumbersFault_Exception(fb.getMessage(), fb);
+        }
+
         return number1 + number2;
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_fromwsdl/WSAFromWSDLTest.java
Wed Nov 28 19:41:28 2007
@@ -27,6 +27,7 @@
 
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.systest.ws.addr_feature.AddNumbersFault_Exception;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType;
 import org.apache.cxf.systest.ws.addr_feature.AddNumbersService;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -81,7 +82,7 @@
 
         String expectedOut = BASE_URI + "addNumbersRequest";
         String expectedIn = BASE_URI + "addNumbersResponse";
-
+        
         assertTrue(output.toString().indexOf(expectedOut) != -1);
         assertTrue(input.toString().indexOf(expectedIn) != -1);
     }
@@ -114,6 +115,53 @@
 
         String expectedOut = "3in";
         String expectedIn = "3out";
+
+        assertTrue(output.toString().indexOf(expectedOut) != -1);
+        assertTrue(input.toString().indexOf(expectedIn) != -1);
+    }
+
+
+    @Test
+    public void testAddNumbersFault() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
+        AddNumbersPortType port = getPort();
+
+        try {
+            port.addNumbers(-1, 2);
+        } catch (AddNumbersFault_Exception ex) {
+            assert true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            assert false;
+        }
+
+        String expectedOut = BASE_URI + "addNumbersRequest";
+        String expectedIn = BASE_URI + "Fault/addNumbersFault";
+
+        assertTrue(output.toString().indexOf(expectedOut) != -1);
+        assertTrue(input.toString().indexOf(expectedIn) != -1);
+    }
+
+    @Test
+    public void testAddNumbersFault3() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
+        AddNumbersPortType port = getPort();
+
+        try {
+            port.addNumbers3(-1, 2);
+        } catch (AddNumbersFault_Exception ex) {
+            assert true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            assert false;
+        }
+
+        String expectedOut = "3in";
+        String expectedIn = "3fault";
 
         assertTrue(output.toString().indexOf(expectedOut) != -1);
         assertTrue(input.toString().indexOf(expectedIn) != -1);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java
Wed Nov 28 19:41:28 2007
@@ -163,7 +163,7 @@
             RMConstants.getCreateSequenceResponseAction(),
             GREETME_RESPONSE_ACTION,
             PINGME_RESPONSE_ACTION,
-            PINGME_RESPONSE_ACTION
+            null
         };
         mf.verifyActions(expectedActions, false);
         mf.verifyMessageNumbers(new String[] {null, "1", "2", "3"}, false);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java
Wed Nov 28 19:41:28 2007
@@ -169,7 +169,7 @@
             RMConstants.getCreateSequenceResponseAction(),
             GREETME_RESPONSE_ACTION,
             PINGME_RESPONSE_ACTION,
-            PINGME_RESPONSE_ACTION
+            null
         };
         mf.verifyActions(expectedActions, false);
         mf.verifyMessageNumbers(new String[] {null, "1", "2", "3"}, false);

Modified: incubator/cxf/trunk/systests/src/test/resources/wsdl/add_numbers.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/wsdl/add_numbers.wsdl?rev=599254&r1=599253&r2=599254&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/resources/wsdl/add_numbers.wsdl (original)
+++ incubator/cxf/trunk/systests/src/test/resources/wsdl/add_numbers.wsdl Wed Nov 28 19:41:28
2007
@@ -82,7 +82,7 @@
 	<operation name="addNumbers">
 	    <input message="tns:addNumbers"/>
 	    <output message="tns:addNumbersResponse"/>
-	    <!-- <fault name="addNumbersFault" message="tns:addNumbersFault"/> -->
+	    <fault name="addNumbersFault" message="tns:addNumbersFault"/>
 	</operation>
 	<operation name="addNumbers2">
 	    <input message="tns:addNumbers2" name="add2In"/>
@@ -92,7 +92,7 @@
 	<operation name="addNumbers3">
 	    <input message="tns:addNumbers3" wsaw:Action="3in"/>
 	    <output message="tns:addNumbers3Response" wsaw:Action="3out"/>
-<!-- 	    <fault name="addNumbersFault" message="tns:addNumbersFault" wsaw:Action="3fault"/>
-->
+	    <fault name="addNumbersFault" message="tns:addNumbersFault" wsaw:Action="3fault"/>
 	</operation>
     </portType>
     <binding name="AddNumbersBinding" type="tns:AddNumbersPortType">
@@ -106,11 +106,9 @@
 	    <output>
 		<soap:body use="literal" />
 	    </output>
-	    <!--
 	    <fault name="addNumbersFault">
 		<soap:fault name="addNumbersFault" use="literal" />
 	    </fault>
-	    -->
 	</operation>
 	<operation name="addNumbers2">
 	    <soap:operation soapAction="" />
@@ -132,9 +130,9 @@
 	    <output>
 		<soap:body use="literal" />
 	    </output>
-<!-- 	    <fault name="addNumbersFault"> -->
-<!-- 		<soap:fault name="addNumbersFault" use="literal" /> -->
-<!-- 	    </fault> -->
+	    <fault name="addNumbersFault">
+		<soap:fault name="addNumbersFault" use="literal" />
+	    </fault>
 	</operation>
     </binding>
     <service name="AddNumbersService">



Mime
View raw message