Author: scheu
Date: Tue Oct 19 15:13:25 2010
New Revision: 1024266
URL: http://svn.apache.org/viewvc?rev=1024266&view=rev
Log:
AXIS2-4857
Contributor:Rich Scheuerle
Summary:
The "caused by exception" is now captured and set during inbound handler
processing.
Validation tests are added to verify the new code.
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java?rev=1024266&r1=1024265&r2=1024266&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
Tue Oct 19 15:13:25 2010
@@ -63,6 +63,7 @@ import org.apache.axis2.jaxws.sample.add
import
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerFault_Exception;
import
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerPortType;
import
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerService;
+import
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersProtocolHandler2;
import org.test.addnumbershandler.AddNumbersHandlerResponse;
public class AddNumbersHandlerTests extends AbstractTestCase {
@@ -236,6 +237,8 @@ public class AddNumbersHandlerTests exte
}
+
+
/**
* Client app sends MAXVALUE, MAXVALUE as params to add.
* No client-side handlers are configured for this scenario.
@@ -279,6 +282,7 @@ public class AddNumbersHandlerTests exte
if (t == null) {
fail("Expected AddNumbersHandlerFault_Exception to be thrown");
}
+
if (t instanceof SOAPFaultException) {
expectedException = (SOAPFaultException) t;
} else {
@@ -312,7 +316,7 @@ public class AddNumbersHandlerTests exte
+ "AddNumbersProtocolHandler CLOSE\n"
+ "AddNumbersProtocolHandler PRE_DESTROY\n";
- assertEquals(expected_calls, log);
+ assertTrue("Expected : " + expected_calls + " but received " + log,
expected_calls.equals(log));
// The outbound service handler adds the stack trace to the
// message. Make sure the stack trace contains the
AddNumbersHandlerPortTypeImpl
@@ -330,6 +334,66 @@ public class AddNumbersHandlerTests exte
}
+ /**
+ * Client app sends MAXVALUE, MAXVALUE as params to add.
+ * No client-side handlers are configured for this scenario.
+ * The endpoint method (addNumbersHandler) will detect the possible
overflow and
+ * throw an unchecked exception, NullPointerException.
+ *
+ * The server-side AddNumbersProtocolHandler will
+ * access the thrown exception using the "jaxws.webmethod.exception"
+ * property and add the stack trace string to fault string.
+ *
+ * The client should receive a SOAPFaultException that has a stack
+ * trace as part of the message.
+ * This test verifies the following:
+ *
+ * 1) Proper exception/fault processing when handlers are installed.
+ * 2) Access to the special "jaxws.webmethod.exception"
+ * 3) Proper exception call flow when an unchecked exception is thrown.
+ */
+ public void testAddNumbersHandler_WithHandlerException() throws Exception {
+
+ TestLogger.logger.debug("----------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ AddNumbersHandlerService service = new AddNumbersHandlerService();
+ AddNumbersHandlerPortType proxy = service.getAddNumbersHandlerPort();
+
+ BindingProvider p = (BindingProvider)proxy;
+ p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
axisEndpoint);
+ SOAPFaultException expectedException = null;
+ Throwable t = null;
+ try {
+ // Trigger protocol 2 to throw an exception
+ AddNumbersProtocolHandler2.throwException = true;
+ proxy.addNumbersHandler(-1000, Integer.MIN_VALUE);
+
+ } catch (Throwable e) {
+ // An exception is expected
+ t = e;
+
+ } finally {
+ AddNumbersProtocolHandler2.throwException = false;
+ }
+
+ // Make sure the proper exception is thrown
+ if (t == null) {
+ fail("Expected AddNumbersHandlerFault_Exception to be thrown");
+ }
+
+ if (t instanceof SOAPFaultException) {
+ expectedException = (SOAPFaultException) t;
+ String fault = ((SOAPFaultException)t).getFault().toString();
+ assertTrue("Expected SOAPFaultException to be thrown with
AddNumbersProtocolHandler2 exception " + fault,
+ fault.contains("AddNumbersProtocolHandler2"));
+ } else {
+ fail("Expected SOAPFaultException to be thrown, " +
+ "but the exception is: " + t);
+ }
+
+ }
+
public void testAddNumbersHandlerDispatch() {
try {
QName serviceName =
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java?rev=1024266&r1=1024265&r2=1024266&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
Tue Oct 19 15:13:25 2010
@@ -25,10 +25,14 @@ import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
+import org.apache.axis2.jaxws.utility.JavaUtils;
+
public class AddNumbersProtocolHandler2 implements
javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
HandlerTracker tracker = new
HandlerTracker(AddNumbersProtocolHandler2.class.getSimpleName());
+ public static boolean throwException = false;
+
public void close(MessageContext messagecontext) {
tracker.close();
}
@@ -47,6 +51,11 @@ public class AddNumbersProtocolHandler2
public boolean handleMessage(SOAPMessageContext messagecontext) {
Boolean outbound = (Boolean)
messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
tracker.handleMessage(outbound);
+
+ if (!outbound && throwException) {
+ RuntimeException e = new NullPointerException();
+ throw e;
+ }
return true;
}