svn commit: r1024265 - in /axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws: handler/HandlerInvokerUtils.java server/JAXWSMessageReceiver.java

2010-10-19 Thread scheu
Author: scheu
Date: Tue Oct 19 15:12:52 2010
New Revision: 1024265

URL: http://svn.apache.org/viewvc?rev=1024265&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/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java

axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java?rev=1024265&r1=1024264&r2=1024265&view=diff
==
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java
 Tue Oct 19 15:12:52 2010
@@ -75,6 +75,21 @@ public class HandlerInvokerUtils {
  * context and message are transformed.
  */
 HandlerChainProcessor.convertToFaultMessage(mepMessageCtx, re, 
proto);
+
+// Set the Caused By Exception on the MessageContext so that it 
can be obtained in
+// the JAXWSMessageReceiver
+if (log.isDebugEnabled()) {
+log.debug("Runtime Exception detected.  Setting 
causedByException field to " + re);
+}
+
+if (mepMessageCtx.getRequestMessageContext() != null) {
+
mepMessageCtx.getRequestMessageContext().setCausedByException(new 
AxisFault(re.getMessage(), re));
+}
+if (mepMessageCtx.getResponseMessageContext() != null) {
+
mepMessageCtx.getResponseMessageContext().setCausedByException(new 
AxisFault(re.getMessage(), re));
+}
+
+
 // done invoking inbound handlers, be sure to set the access lock 
flag on the context to true
 mepMessageCtx.setApplicationAccessLocked(true);
 return false;

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java?rev=1024265&r1=1024264&r2=1024265&view=diff
==
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
 Tue Oct 19 15:12:52 2010
@@ -194,11 +194,22 @@ public class JAXWSMessageReceiver implem
 
 //Rather than create a new AxisFault, we should use 
the AxisFault that was
 //created at the causedBy
-if (responseMsgCtx.getCausedByException() != null)
+if (responseMsgCtx.getCausedByException() != null) {
 faultToReturn = 
responseMsgCtx.getCausedByException();
-else {
+if (log.isDebugEnabled()) {
+log.debug("Setting causedByException from 
response MessageContext");
+}
+} else if (requestMsgCtx.getCausedByException() != 
null) {
+faultToReturn = 
requestMsgCtx.getCausedByException();
+if (log.isDebugEnabled()) {
+log.debug("Setting causedByException from 
request MessageContext..which indicates an exception occured in the inbound 
handler processing");
+}
+} else {
 faultToReturn = new AxisFault("An error was 
detected during JAXWS processing",
 axisResponseMsgCtx);
+if (log.isDebugEnabled()) {
+log.debug("No causedByException detected");
+}
 }
 } else {
 //This assumes that we are on the ultimate execution thread




svn commit: r1024266 - in /axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample: AddNumbersHandlerTests.java addnumbershandler/AddNumbersProtocolHandler2.java

2010-10-19 Thread scheu
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");
+