You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2008/04/03 20:36:37 UTC

svn commit: r644436 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/message/XMLFaultCode.java test/org/apache/axis2/jaxws/misc/XMLFaultTest.java

Author: scheu
Date: Thu Apr  3 11:36:36 2008
New Revision: 644436

URL: http://svn.apache.org/viewvc?rev=644436&view=rev
Log:
AXIS2-3701
Contributor:Rich Scheuerle
Found by: Wendy Raschke
Support "Custom Fault Codes" for SOAP 1.1 Faults.
Also added a verification unit test.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/XMLFaultTest.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java?rev=644436&r1=644435&r2=644436&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java Thu Apr  3 11:36:36 2008
@@ -35,8 +35,11 @@
     RECEIVER,               // SOAP 1.2 Receiver              SOAP 1.1  Server
     MUSTUNDERSTAND,         // SOAP 1.2 MustUnderstand        SOAP 1.1  MustUnderstand
     DATAENCODINGUNKNOWN,    // SOAP 1.2 DataEncodingUnknown   SOAP 1.1  Server
-    VERSIONMISMATCH;       // SOAP 1.2 VersionMismatch       SOAP 1.1  VersionMismatch
+    VERSIONMISMATCH,        // SOAP 1.2 VersionMismatch       SOAP 1.1  VersionMismatch
+    CUSTOM_SOAP11_ONLY;     // SOAP 1.2 Receiver              SOAP 1.1  "custom qname"
 
+    private QName customQName = null;  // Set only for CUSTOM case
+    
     // Utility Methods
 
     /**
@@ -46,10 +49,20 @@
      * @return
      */
     public QName toQName(String namespace) {
-        String localPart = null;
-        if (namespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
-            // SOAP 1.2
-            switch (this) {
+        if (this == CUSTOM_SOAP11_ONLY) {
+            // If this is a CUSTOM code, then respect it for SOAP 1.1 only.
+            if (namespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+                // For SOAP 1.2, convert to RECEIVER
+                return new QName(namespace, "Receiver");
+            } else {
+                return this.customQName;
+            }
+        } else {
+            // This is a specification defined qname
+            String localPart = null;
+            if (namespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+                // SOAP 1.2
+                switch (this) {
                 case SENDER:
                     localPart = "Sender";
                     break;
@@ -65,11 +78,11 @@
                 case VERSIONMISMATCH:
                     localPart = "VersionMismatch";
                     break;
-            }
+                }
 
-        } else {
-            // Assume SOAP 1.1
-            switch (this) {
+            } else {
+                // Assume SOAP 1.1
+                switch (this) {
                 case SENDER:
                     localPart = "Client";
                     break;
@@ -85,9 +98,10 @@
                 case VERSIONMISMATCH:
                     localPart = "VersionMismatch";
                     break;
+                }
             }
+            return new QName(namespace, localPart);
         }
-        return new QName(namespace, localPart);
     }
 
     /**
@@ -103,7 +117,7 @@
         }
         String namespace = qName.getNamespaceURI();
         String localPart = qName.getLocalPart();
-        XMLFaultCode xmlFaultCode = RECEIVER;
+        XMLFaultCode xmlFaultCode = null;
         // Due to problems in the OM, sometimes that qname is not retrieved correctly.
         // So use the localName to find the XMLFaultCode
         if (localPart.equalsIgnoreCase("Sender")) {          // SOAP 1.2
@@ -120,35 +134,11 @@
             xmlFaultCode = DATAENCODINGUNKNOWN;
         } else if (localPart.equalsIgnoreCase("VersionMismatch")) { // Both
             xmlFaultCode = VERSIONMISMATCH;
-        }
-        /*
-         * TODO: Due to problems in the OM, sometimes that qname is not retrieved correctly.
-        if (namespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
-            // SOAP 1.2
-            if (localPart.equals("Sender")) {
-                xmlFaultCode = SENDER;
-            } else if (localPart.equals("Receiver")) {
-                xmlFaultCode = RECEIVER;
-            } else if (localPart.equals("MustUnderstand")) {
-                xmlFaultCode = MUSTUNDERSTAND;
-            } else if (localPart.equals("DataEncodingUnknown")) {
-                xmlFaultCode = DATAENCODINGUNKNOWN;
-            } else if (localPart.equals("VersionMismatch")) {
-                xmlFaultCode = VERSIONMISMATCH;
-            }
         } else {
-            // SOAP 1.1
-            if (localPart.equals("Client")) {
-                xmlFaultCode = SENDER;
-            } else if (localPart.equals("Server")) {
-                xmlFaultCode = RECEIVER;
-            } else if (localPart.equals("MustUnderstand")) {
-                xmlFaultCode = MUSTUNDERSTAND;
-            } else if (localPart.equals("VersionMismatch")) {
-                xmlFaultCode = VERSIONMISMATCH;
-            }
+            xmlFaultCode = CUSTOM_SOAP11_ONLY;
+            xmlFaultCode.customQName = qName;
         }
-        */
+        
         return xmlFaultCode;
     }
 }

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/XMLFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/XMLFaultTest.java?rev=644436&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/XMLFaultTest.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/XMLFaultTest.java Thu Apr  3 11:36:36 2008
@@ -0,0 +1,94 @@
+/*
+ * 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.axis2.jaxws.misc;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.message.XMLFault;
+import org.apache.axis2.jaxws.message.XMLFaultCode;
+import org.apache.axis2.jaxws.message.XMLFaultReason;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
+import org.apache.axis2.jaxws.utility.JavaUtils;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
+
+/**
+ * Tests XMLFault logic
+ */
+public class XMLFaultTest extends TestCase {
+
+    private static final QName CUSTOM = new QName("http://mySample", "CustomCode", "pre");
+    
+    /**
+     * Test Custom FaultQName for SOAP 1.1
+     * @throws Exception
+     */
+    public void testCustomFault11() throws Exception {
+        MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
+        SOAPMessage sm = mf.createMessage();
+        SOAPBody body = sm.getSOAPBody();
+        SOAPFault fault = body.addFault(CUSTOM, "Custom Fault");
+        
+        XMLFault xmlFault = XMLFaultUtils.createXMLFault(fault);
+        
+        assertTrue(xmlFault != null);
+        
+        XMLFaultReason reason = xmlFault.getReason();
+        assertTrue(reason != null);
+        assertTrue(reason.getText().equals("Custom Fault"));
+        
+        XMLFaultCode code = xmlFault.getCode();
+        assertTrue(code != null);
+        
+        QName codeQName = code.toQName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE);
+        assertTrue("Expected QName = " + CUSTOM + " but received = " + codeQName, codeQName.equals(CUSTOM));
+                        
+    }
+    
+    /**
+     * Test Custom FaultQName for SOAP 1.2
+     * @throws Exception
+     */
+    public void testCustomFault12() throws Exception {
+        MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+        SOAPMessage sm = mf.createMessage();
+        SOAPBody body = sm.getSOAPBody();
+        
+        try {
+            SOAPFault fault = body.addFault(CUSTOM, "Custom Fault");
+            fail("Expected Failure, custom fault codes are not supported with SOAP 1.2");
+        } catch (SOAPException e) {
+            // Expected...
+        } catch (Throwable t) {
+            fail("Expected different failure, received: " + t);
+        }
+
+    }
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org