You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2006/06/06 08:38:20 UTC
svn commit: r412020 - in
/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine:
ServiceFaultTest.java util/FaultThrowingService.java
Author: chinthaka
Date: Mon Jun 5 23:38:19 2006
New Revision: 412020
URL: http://svn.apache.org/viewvc?rev=412020&view=rev
Log:
The two ways of throwing custom faults are now working and added a test case. Yet to fix the other message receivers.
Modified:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java?rev=412020&r1=412019&r2=412020&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java Mon Jun 5 23:38:19 2006
@@ -62,9 +62,41 @@
+ "/axis2/services/" + serviceName.getLocalPart() + "/" + operationName.getLocalPart());
}
- public void testFaultThrownByService() {
+ /**
+ * Service throws a fault from the service impl, by just creating an AxisFault from all the fault
+ * information.
+ */
+ public void testFaultThrownByServiceUsingAxisFaultOnly() {
try {
OMElement payload = getOMElementWithText(FaultThrowingService.THROW_FAULT_AS_AXIS_FAULT);
+ Options options = new Options();
+ options.setTo(targetEPR);
+ options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setExceptionToBeThrownOnSOAPFault(false);
+
+ ConfigurationContext configContext =
+ ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
+ ServiceClient sender = new ServiceClient(configContext, null);
+ sender.setOptions(options);
+
+ String result = sender.sendReceive(payload).toString();
+
+ assertTrue(result.indexOf("test:TestFault") > -1);
+ assertTrue(result.indexOf("FaultReason</soapenv:Text>") > -1);
+ assertTrue(result.indexOf("This is a test Exception") > -1);
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Service sends out a fault, filling all the information to the message context
+ */
+ public void testFaultThrownByServiceUsingMessageContext() {
+ try {
+ OMElement payload = getOMElementWithText(FaultThrowingService.THROW_FAULT_WITH_MSG_CTXT);
Options options = new Options();
options.setTo(targetEPR);
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java?rev=412020&r1=412019&r2=412020&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java Mon Jun 5 23:38:19 2006
@@ -1,6 +1,14 @@
package org.apache.axis2.engine.util;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPFaultCode;
+import org.apache.axiom.soap.SOAPFaultReason;
+import org.apache.axiom.soap.SOAPFaultDetail;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axiom.soap.SOAPFaultText;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -29,6 +37,9 @@
public static final String THROW_FAULT_WITH_MSG_CTXT = "ThrowFaultWithMsgCtxt";
MessageContext inMessageContext;
+ private SOAPFaultCode soapFaultCode;
+ private SOAPFaultReason soapFaultReason;
+ private SOAPFaultDetail soapFaultDetail;
public void setOperationContext(OperationContext opContext) {
try {
@@ -38,15 +49,49 @@
}
}
- public OMElement echoWithFault(OMElement echoOMElement) throws AxisFault {
+ public OMElement echoWithFault(OMElement echoOMElement) throws AxisFault {
String text = echoOMElement.getText();
if (THROW_FAULT_AS_AXIS_FAULT.equalsIgnoreCase(text)) {
throw new AxisFault(new QName("http://test.org", "TestFault", "test"), "FaultReason", new Exception("This is a test Exception"));
} else if (THROW_FAULT_WITH_MSG_CTXT.equalsIgnoreCase(text)) {
+ initFaultInformation();
+ inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, soapFaultCode);
+ inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME, soapFaultReason);
+ inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, soapFaultDetail);
+ throw new AxisFault("Fake exception occurred !!");
+ } else {
+ return echoOMElement;
+ }
+ }
+ private void initFaultInformation() {
+ SOAPFactory soapFactory;
+ if (inMessageContext.isSOAP11()) {
+ soapFactory = OMAbstractFactory.getSOAP11Factory();
} else {
- return echoOMElement;
+ soapFactory = OMAbstractFactory.getSOAP12Factory();
+ }
+
+ soapFaultCode = soapFactory.createSOAPFaultCode();
+ SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
+ soapFaultValue.setText(new QName("http://test.org", "TestFault", "test"));
+
+ soapFaultReason = soapFactory.createSOAPFaultReason();
+ SOAPFaultText soapFaultText = soapFactory.createSOAPFaultText(soapFaultReason);
+ soapFaultText.setText("This is some FaultReason");
+
+ soapFaultDetail = soapFactory.createSOAPFaultDetail();
+ QName qName = new QName("http://someuri.org", "FaultException");
+ OMElement detail = soapFactory.createOMElement(qName, soapFaultDetail);
+ qName = new QName("http://someuri.org", "ExceptionMessage");
+ Throwable e = new Exception("This is a test Exception");
+ while (e != null) {
+ OMElement exception = soapFactory.createOMElement(qName, null);
+ exception.setText(e.getMessage());
+ detail.addChild(exception);
+ e = e.getCause();
}
- return null;
}
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org