Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 26919 invoked from network); 6 Apr 2006 08:31:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Apr 2006 08:31:42 -0000 Received: (qmail 3147 invoked by uid 500); 6 Apr 2006 08:31:37 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 3058 invoked by uid 500); 6 Apr 2006 08:31:37 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 3047 invoked by uid 500); 6 Apr 2006 08:31:37 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 3044 invoked by uid 99); 6 Apr 2006 08:31:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Apr 2006 01:31:37 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 06 Apr 2006 01:31:35 -0700 Received: (qmail 26398 invoked by uid 65534); 6 Apr 2006 08:31:14 -0000 Message-ID: <20060406083114.26339.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r391933 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/ core/src/org/apache/axis2/description/ integration/test/org/apache/axis2/engine/ integration/test/org/apache/axis2/rpc/ Date: Thu, 06 Apr 2006 08:30:51 -0000 To: axis2-cvs@ws.apache.org From: chinthaka@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: chinthaka Date: Thu Apr 6 01:30:48 2006 New Revision: 391933 URL: http://svn.apache.org/viewcvs?rev=391933&view=rev Log: Fixed FaultHandling in client side so that now you will get fault information as SOAPFault* from the AxisFault. Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java?rev=391933&r1=391932&r2=391933&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java (original) +++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java Thu Apr 6 01:30:48 2006 @@ -25,6 +25,7 @@ import org.apache.axiom.soap.SOAPFaultReason; import org.apache.axiom.soap.SOAPFaultRole; import org.apache.axiom.soap.SOAPHeader; +import org.apache.axiom.soap.SOAPConstants; import javax.xml.namespace.QName; import java.lang.reflect.InvocationTargetException; @@ -55,14 +56,14 @@ * a SOAP1.1 fault is created, spurious information can be discarded. * Mapping *
- *                                         SOAP1.2              SOAP1.1
- *                                         node                 faultactor
- *                                         reason(0).text       faultstring
- *                                         faultcode.value      faultcode
- *                                         faultcode.subcode    (discarded)
- *                                         detail               detail
- *                                         role                 (discarded)
- *                                         
+ * SOAP1.2 SOAP1.1 + * node faultactor + * reason(0).text faultstring + * faultcode.value faultcode + * faultcode.subcode (discarded) + * detail detail + * role (discarded) + * */ public class AxisFault extends RemoteException { @@ -80,6 +81,10 @@ private OMElement detail; private Map faultElements; + + private String message; + private Throwable cause; + /** * SOAP1.2: URI of faulting node. Null for unknown. *

@@ -129,10 +134,10 @@ * @param soapFaultReason * @param soapFaultNode * @param soapFaultRole - * @param soap */ public AxisFault(SOAPFaultCode soapFaultCode, SOAPFaultReason soapFaultReason, SOAPFaultNode soapFaultNode, SOAPFaultRole soapFaultRole, SOAPFaultDetail soapFaultDetail) { + if (faultElements == null) { // assuming that most of the times fault code, fault string and fault details are set faultElements = new HashMap(3); @@ -143,6 +148,18 @@ setToElementsListIfNotNull(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME, soapFaultRole); setToElementsListIfNotNull(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, soapFaultDetail); + if (soapFaultReason != null) { + message = soapFaultReason.getFirstSOAPText().getText(); + } + + if (soapFaultDetail != null) { + OMElement exceptionElement = soapFaultDetail.getFirstChildWithName( + new QName(SOAPConstants.SOAP_FAULT_DETAIL_EXCEPTION_ENTRY)); + if (exceptionElement != null && exceptionElement.getText() != null) { + cause = new Exception(exceptionElement.getText()); + } + } + } private void setToElementsListIfNotNull(String soapFaultElementName, OMElement soapFaultElement) { @@ -311,6 +328,46 @@ } /** + * @return SOAPFaultCode if, user has set a {@link SOAPFaultCode} element when constructing the + * {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason, org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail) AxisFault} + */ + public SOAPFaultCode getFaultCodeElement() { + return (SOAPFaultCode) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME) : null); + } + + /** + * @return SOAPFaultCode if, user has set a {@link SOAPFaultReason} element when constructing the + * {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason, org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail) AxisFault} + */ + public SOAPFaultReason getFaultReasonElement() { + return (SOAPFaultReason) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME) : null); + } + + /** + * @return SOAPFaultCode if, user has set a {@link SOAPFaultNode} element when constructing the + * {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason, org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail) AxisFault} + */ + public SOAPFaultNode getFaultNodeElement() { + return (SOAPFaultNode) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME) : null); + } + + /** + * @return SOAPFaultCode if, user has set a {@link SOAPFaultRole} element when constructing the + * {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason, org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail) AxisFault} + */ + public SOAPFaultRole getFaultRoleElement() { + return (SOAPFaultRole) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME) : null); + } + + /** + * @return SOAPFaultCode if, user has set a {@link SOAPFaultDetail} element when constructing the + * {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason, org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail) AxisFault} + */ + public SOAPFaultDetail getFaultDetailElement() { + return (SOAPFaultDetail) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME) : null); + } + + /** * Get the faulting node uri. * SOAP1.2 * @@ -357,6 +414,14 @@ return faultRole; } + public String getMessage() { + return message != null ? message : super.getMessage(); + } + + public Throwable getCause() { + return cause != null ? cause : super.getCause(); + } + class FaultReason { /** @@ -403,4 +468,5 @@ this.text = text; } } + } Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java?rev=391933&r1=391932&r2=391933&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java (original) +++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java Thu Apr 6 01:30:48 2006 @@ -223,7 +223,7 @@ EndpointReference toEPR = (options.getTo() != null) ? options .getTo() : mc.getTo(); transportOut = ClientUtils.inferOutTransport(cc - .getAxisConfiguration(), toEPR ,mc); + .getAxisConfiguration(), toEPR, mc); } mc.setTransportOut(transportOut); @@ -266,30 +266,15 @@ // Send the SOAP Message and receive a response MessageContext response = send(mc); // check for a fault and return the result - SOAPEnvelope resenvelope = response.getEnvelope(); - if (resenvelope.getBody().hasFault()) { - SOAPFault soapFault = resenvelope.getBody().getFault(); - Exception ex = soapFault.getException(); + SOAPEnvelope resEnvelope = response.getEnvelope(); + if (resEnvelope.getBody().hasFault()) { + SOAPFault soapFault = resEnvelope.getBody().getFault(); if (options.isExceptionToBeThrownOnSOAPFault()) { // does the SOAPFault has a detail element for Excpetion - if (ex != null) { - throw new AxisFault(ex); - } else { - // if detail element not present create a new - // Exception from the detail - String message = ""; - message = (message + "Code =" + soapFault.getCode() == null) ? "" - : (soapFault.getCode().getValue() == null) ? "" - : soapFault.getCode().getValue() - .getText(); - message = (message + "Reason =" - + soapFault.getReason() == null) ? "" - : (soapFault.getReason().getFirstSOAPText() == null) ? "" - : soapFault.getReason() - .getFirstSOAPText().getText(); - throw new AxisFault(message); - } + throw new AxisFault(soapFault.getCode(), soapFault.getReason(), + soapFault.getNode(), soapFault.getRole(), soapFault.getDetail()); + } } completed = true; Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java?rev=391933&r1=391932&r2=391933&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java (original) +++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java Thu Apr 6 01:30:48 2006 @@ -41,6 +41,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.util.ArrayList; +import java.util.Map; public class FaultHandlingTest extends TestCase implements TestConstants { @@ -104,7 +105,6 @@ } - public void testRefParamsWithFaultTo() throws AxisFault, XMLStreamException { SOAPEnvelope soapEnvelope = getSOAPEnvelopeWithRefParamsInFaultTo(); SOAPEnvelope resposeEnvelope = getResponse(soapEnvelope); @@ -162,6 +162,30 @@ protected void tearDown() throws Exception { UtilServer.stop(); + } + + public void testExceptionInformationExtractionFromAxisFault() { + try { + ConfigurationContext configContext = + ConfigurationContextFactory.createConfigurationContextFromFileSystem("target/test-resources/integrationRepo", null); + ServiceClient sender = new ServiceClient(configContext, null); + + OMElement payload = getOMElement(FaultHandler.ERR_HANDLING_WITH_AXIS_FAULT); + + // test with SOAP 1.2 + Options options = new Options(); + options.setTo(targetEPR); + options.setTransportInProtocol(Constants.TRANSPORT_HTTP); + options.setExceptionToBeThrownOnSOAPFault(true); + options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); + sender.setOptions(options); + + sender.sendReceive(payload).toString(); + } catch (AxisFault axisFault) { + assertTrue(axisFault.getFaultCodeElement().toString().indexOf(FaultHandler.M_FAULT_EXCEPTION) > -1); + assertTrue(axisFault.getFaultDetailElement().toString().indexOf(FaultHandler.DETAIL_MORE_INFO) > -1); + assertTrue(axisFault.getFaultReasonElement().toString().indexOf(FaultHandler.FAULT_REASON) > -1); + } } } Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java?rev=391933&r1=391932&r2=391933&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java (original) +++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java Thu Apr 6 01:30:48 2006 @@ -295,7 +295,7 @@ fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference :2"); } catch (AxisFault axisFault) { - String val = axisFault.getMessage(); + String val = axisFault.getFaultDetailElement().toString(); int index = val.indexOf("org.apache.axis2.AxisFault: Invalid reference :2"); if (index < 0) { fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference :2");