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 ng...@apache.org on 2006/11/02 20:17:36 UTC
svn commit: r470481 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/client/proxy/
src/org/apache/axis2/jaxws/core/controller/
src/org/apache/axis2/jaxws/message/ src/org/apache/axis2/jaxws/messag...
Author: ngallardo
Date: Thu Nov 2 11:17:35 2006
New Revision: 470481
URL: http://svn.apache.org/viewvc?view=rev&rev=470481
Log:
AXIS2-1534 \n Mike's patch for improving client side fault handling.
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/ExceptionFactory.java Thu Nov 2 11:17:35 2006
@@ -214,8 +214,14 @@
if (t != null) {
rootCause = getRootCause(t);
}
- WebServiceException e = new WebServiceException(message, t);
- if (log.isDebugEnabled()) {
+
+ WebServiceException e;
+ if (rootCause != null)
+ e = new WebServiceException(rootCause.getMessage(), rootCause);
+ else
+ e = new WebServiceException(message, t);
+
+ if (log.isDebugEnabled()) {
log.debug("Create Exception:", e);
}
return e;
@@ -310,7 +316,7 @@
if (cause == null) {
cause = t.getCause();
}
- return null;
+ return cause;
}
/**
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Thu Nov 2 11:17:35 2006
@@ -317,7 +317,11 @@
}
throw (Throwable)object;
+ } else if (responseMsg.getLocalException() != null) {
+ // use the factory, it'll throw the right thing:
+ throw ExceptionFactory.makeWebServiceException(responseMsg.getLocalException());
}
+
Object object = methodMarshaller.demarshalResponse(responseMsg, args);
if (log.isDebugEnabled()) {
log.debug("Message Converted to response Object");
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Thu Nov 2 11:17:35 2006
@@ -113,16 +113,16 @@
MessageContext response = null;
+ AxisFault faultexception = null; // don't let the keyword "fault" confuse you. This is an exception class.
try {
execute(opClient, true, axisRequestMsgCtx);
} catch(AxisFault af) {
- //throw ExceptionFactory.makeWebServiceException(af);
- // TODO MIKE revisit?
- // do nothing here. The exception we get is from the endpoint,
- // and will be sitting on the message context. We need to save it
- // to process it through jaxws
- System.out.println("Swallowed Exception =" + af);
- af.printStackTrace(System.out);
+ // save the fault in case it didn't come from the endpoint, and thus
+ // there would be no message on the MessageContext
+ faultexception = af;
+ if (log.isDebugEnabled()) {
+ log.debug("AxisFault received from client: " + af.getMessage());
+ }
}
try {
@@ -130,6 +130,19 @@
axisResponseMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
response = new MessageContext(axisResponseMsgCtx);
+ /*
+ * If the Message object is still null, then it's possible that a
+ * local AxisFault was thrown and we need to save it for later throwing
+ * We do not want to create a message and go through the whole handler or
+ * XMLFault processing because it's unnecessary.
+ */
+ if (response.getMessage() == null && faultexception != null) {
+ MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message message = factory.create(request.getMessage().getProtocol());
+ message.setLocalException(faultexception);
+ response.setMessage(message);
+ }
+
// This assumes that we are on the ultimate execution thread
ThreadContextMigratorUtil.performMigrationToThread(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID, axisResponseMsgCtx);
} catch (Exception e) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java Thu Nov 2 11:17:35 2006
@@ -80,5 +80,22 @@
public boolean isMTOMEnabled();
public void setMTOMEnabled(boolean b);
+
+ /**
+ * The local exception is the Throwable object held on the Message
+ * from a problem that occurred due to something other than the
+ * server. In other words, no message ever travelled across the wire.
+ * @return the Throwable object or null
+ */
+ public Throwable getLocalException();
+
+ /**
+ * The local exception is the Throwable object held on the Message
+ * from a problem that occurred due to something other than the
+ * server. In other words, no message ever travelled across the wire.
+ * @param t
+ * @see Throwable
+ */
+ public void setLocalException(Throwable t);
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java Thu Nov 2 11:17:35 2006
@@ -63,7 +63,8 @@
XMLPart xmlPart = null; // the representation of the xmlpart
List<Attachment> attachments = new ArrayList<Attachment>(); // non-xml parts
boolean mtomEnabled;
-
+ Throwable localException = null;
+
// Constants
private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
@@ -353,5 +354,14 @@
public String getXMLPartContentType() {
return xmlPart.getXMLPartContentType();
}
+
+ public Throwable getLocalException() {
+ return localException;
+ }
+
+ public void setLocalException(Throwable t) {
+ localException = t;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java?view=diff&rev=470481&r1=470480&r2=470481
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java Thu Nov 2 11:17:35 2006
@@ -3,7 +3,10 @@
*/
package org.apache.axis2.jaxws.sample;
+import java.net.UnknownHostException;
+
import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceException;
import junit.framework.TestCase;
@@ -40,4 +43,39 @@
assertEquals("bean custom message", exception.getFaultInfo().getMessage());
}
+
+ public void testFaultyWebService_badEndpoint(){
+
+ String host = "this.is.a.bad.endpoint.terrible.in.fact";
+ String badEndpoint = "http://" + host;
+
+ WebServiceException exception = null;
+
+ try{
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+ FaultyWebServiceService service = new FaultyWebServiceService();
+ FaultyWebServicePortType proxy = service.getFaultyWebServicePort();
+ BindingProvider p = (BindingProvider)proxy;
+ p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,badEndpoint);
+
+ // the invoke will throw an exception, if the test is performed right
+ int total = proxy.faultyWebService(10);
+
+ }catch(FaultyWebServiceFault_Exception e) {
+ // shouldn't get this exception
+ fail(e.toString());
+ }catch(WebServiceException e) {
+ exception = e;
+ }catch(Exception e) {
+ fail("This testcase should only produce a WebServiceException. We got: " + e.toString());
+ }
+
+ System.out.println("----------------------------------");
+
+ assertNotNull(exception);
+ assertTrue(exception.getCause() instanceof UnknownHostException);
+ assertEquals(exception.getMessage(), host);
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org