From fd31a1072875989d90434af4881d5020114e08d4 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 25 Feb 2009 15:32:59 +0000 Subject: TUSCANY-2867 - Pass checked exceptions as InvocationTargetExceptions. Don't rely on boolean fault flag for messages of object type. Thanks for the patch Kaushik git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@747826 13f79535-47bb-0310-9956-ffa450edef68 --- .../jms/provider/AbstractMessageProcessor.java | 7 ++++++- .../binding/jms/provider/ObjectMessageProcessor.java | 19 +++++++++++++++++++ .../WireFormatJMSBytesReferenceInterceptor.java | 11 ++++++++--- .../WireFormatJMSObjectReferenceInterceptor.java | 12 +++++++++--- .../WireFormatJMSTextReferenceInterceptor.java | 12 +++++++++--- 5 files changed, 51 insertions(+), 10 deletions(-) (limited to 'branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding') diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java index d65522e541..e2fc49834e 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java @@ -93,7 +93,12 @@ public abstract class AbstractMessageProcessor implements JMSMessageProcessor { public Object extractPayloadFromJMSMessage(Message msg) { try { if (msg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { - throw new ServiceRuntimeException("remote service exception, see nested exception", (Throwable)((ObjectMessage)msg).getObject()); + Object exc = ((ObjectMessage)msg).getObject(); + if (exc instanceof RuntimeException) { + throw new ServiceRuntimeException("remote service exception, see nested exception", (Throwable)exc); + } else { + return new InvocationTargetException((Throwable) exc); + } } } catch (JMSException e) { throw new JMSBindingException(e); diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java index 73a822a622..97d3d861f4 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.provider; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.util.logging.Logger; import javax.jms.JMSException; @@ -28,6 +29,7 @@ import javax.jms.Session; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.osoa.sca.ServiceRuntimeException; /** * MessageProcessor for sending/receiving Serializable objects with the JMSBinding. @@ -77,4 +79,21 @@ public class ObjectMessageProcessor extends AbstractMessageProcessor { } } + @Override + public Object extractPayloadFromJMSMessage(Message msg) { + try { + Object o = ((ObjectMessage)msg).getObject(); + if (o instanceof Throwable ) { + if (o instanceof RuntimeException) { + throw new ServiceRuntimeException("remote service exception, see nested exception", (RuntimeException)o); + } else { + return new InvocationTargetException((Throwable) o); + } + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + return extractPayload(msg); + } + } diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java index c1ed139a84..d08707a1ba 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime; +import java.lang.reflect.InvocationTargetException; import javax.jms.JMSException; import javax.jms.Session; @@ -98,10 +99,14 @@ public class WireFormatJMSBytesReferenceInterceptor implements Interceptor { public Message invokeResponse(Message msg) { if (msg.getBody() != null){ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); - if (response != null){ - msg.setBody(response); + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); } else { - msg.setBody(null); + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } } } diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java index 5b56de5574..6ba62d7681 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime; +import java.lang.reflect.InvocationTargetException; import javax.jms.JMSException; import javax.jms.Session; @@ -92,10 +93,15 @@ public class WireFormatJMSObjectReferenceInterceptor implements Interceptor { public Message invokeResponse(Message msg) { if (msg.getBody() != null){ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); - if (response != null){ - msg.setBody(response); + + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); } else { - msg.setBody(null); + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } } } diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java index fc797bf32d..49e745ffaa 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime; +import java.lang.reflect.InvocationTargetException; import javax.jms.JMSException; import javax.jms.Session; @@ -99,10 +100,15 @@ public class WireFormatJMSTextReferenceInterceptor implements Interceptor { public Message invokeResponse(Message msg) { if (msg.getBody() != null){ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); - if (response != null ){ - msg.setBody(response); + + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); } else { - msg.setBody(null); + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } } } -- cgit v1.2.3