summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-04-30 15:26:38 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-04-30 15:26:38 +0000
commit4bd58916e3e72d14787ba292d8f970cd5ac89fc5 (patch)
tree72232a3d4f37697a912e522f799fcc6867146833
parent4ee7e0562a4b1cb0a6d91d0bb5fd8d153cb482c7 (diff)
TUSCANY-2965 - add fault handling code for wireFormat.bytesXML
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@770283 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java37
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java8
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java38
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java1
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java8
5 files changed, 70 insertions, 22 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java
index bde54a6487..5a9e82b7da 100644
--- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java
+++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java
@@ -32,13 +32,15 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
/**
* MessageProcessor for sending/receiving XML javax.jms.BytesMessage with the JMSBinding.
*/
public class XMLBytesMessageProcessor extends AbstractMessageProcessor {
- private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName());
+ private static final Logger logger = Logger.getLogger(XMLBytesMessageProcessor.class.getName());
public XMLBytesMessageProcessor(JMSBinding jmsBinding) {
super(jmsBinding);
@@ -55,6 +57,7 @@ public class XMLBytesMessageProcessor extends AbstractMessageProcessor {
long noOfBytes = ((BytesMessage)msg).getBodyLength();
byte [] bytes = new byte[(int)noOfBytes];
((BytesMessage)msg).readBytes(bytes);
+ ((BytesMessage)msg).reset();
Object os;
if (noOfBytes > 0) {
@@ -73,6 +76,15 @@ public class XMLBytesMessageProcessor extends AbstractMessageProcessor {
}
@Override
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ if (msg instanceof BytesMessage) {
+ return extractPayload(msg);
+ } else {
+ return super.extractPayloadFromJMSMessage(msg);
+ }
+ }
+
+ @Override
protected Message createJMSMessage(Session session, Object o) {
if (session == null) {
logger.fine("no response session to create message: " + String.valueOf(o));
@@ -95,5 +107,28 @@ public class XMLBytesMessageProcessor extends AbstractMessageProcessor {
throw new JMSBindingException(e);
}
}
+
+ @Override
+ public Message createFaultMessage(Session session, Throwable o) {
+
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+ if (o instanceof FaultException) {
+ try {
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(String.valueOf(((FaultException) o).getFaultInfo()).getBytes());
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ return super.createFaultMessage(session, o);
+ }
+ }
}
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java
index 2c9f1ce7e8..782f226fe6 100644
--- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java
+++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java
@@ -20,6 +20,9 @@
package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime;
import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint;
import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.provider.WireFormatProvider;
@@ -31,10 +34,12 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
public class WireFormatJMSBytesXMLProviderFactory implements WireFormatProviderFactory<WireFormatJMSBytes> {
private ExtensionPointRegistry registry;
+ private JMSResourceFactoryExtensionPoint jmsRFEP;
public WireFormatJMSBytesXMLProviderFactory(ExtensionPointRegistry registry) {
super();
this.registry = registry;
+ jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class);
}
/**
@@ -50,7 +55,8 @@ public class WireFormatJMSBytesXMLProviderFactory implements WireFormatProviderF
public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component,
RuntimeComponentService service,
Binding binding) {
- return new WireFormatJMSBytesXMLServiceProvider(registry, component, service, binding);
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)binding);
+ return new WireFormatJMSBytesXMLServiceProvider(registry, component, service, binding, jmsRF);
}
/**
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java
index 5d25be069c..cbcd848c85 100644
--- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java
+++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java
@@ -18,17 +18,20 @@
*/
package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime;
-import java.lang.reflect.InvocationTargetException;
import javax.jms.JMSException;
import javax.jms.Session;
+import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMElement;
import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
@@ -73,13 +76,7 @@ public class WireFormatJMSBytesXMLReferenceInterceptor implements Interceptor {
JMSBindingContext context = msg.getBindingContext();
Session session = context.getJmsSession();
- Object[] requestParams = msg.getBody();
- javax.jms.Message requestMsg = null;
- if (requestParams != null && requestParams.length > 0 ){
- requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, requestParams[0]);
- } else {
- requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, null);
- }
+ javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
msg.setBody(requestMsg);
@@ -93,20 +90,27 @@ public class WireFormatJMSBytesXMLReferenceInterceptor implements Interceptor {
public Message invokeResponse(Message msg) {
if (msg.getBody() != null){
- Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody());
- if (response instanceof InvocationTargetException) {
- msg.setFaultBody(((InvocationTargetException) response).getCause());
- } else {
- if (response != null){
- msg.setBody(response);
- } else {
- msg.setBody(null);
+ javax.jms.Message jmsMsg = (javax.jms.Message)msg.getBody();
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ if (response != null ){
+ msg.setBody(response);
+ try {
+ if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ FaultException e = new FaultException("remote exception", response);
+ OMElement om = (OMElement) response;
+ e.setFaultName(new QName(om.getNamespace().getNamespaceURI(), om.getLocalName()));
+ msg.setFaultBody(e);
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
}
+ } else {
+ msg.setBody(null);
}
}
return msg;
- }
+ }
public Invoker getNext() {
return next;
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java
index 3004704c39..bd04d4b24f 100644
--- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java
+++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java
@@ -23,7 +23,6 @@ import org.apache.axiom.om.OMElement;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
-import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes;
import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML;
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java
index ca0807d635..c2d81600e1 100644
--- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java
+++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java
@@ -23,6 +23,7 @@ import org.apache.axiom.om.OMElement;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes;
import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML;
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
@@ -41,17 +42,20 @@ public class WireFormatJMSBytesXMLServiceProvider implements WireFormatProvider
private RuntimeComponent component;
private RuntimeComponentService service;
private JMSBinding binding;
+ private JMSResourceFactory jmsResourceFactory;
private InterfaceContract interfaceContract;
public WireFormatJMSBytesXMLServiceProvider(ExtensionPointRegistry registry,
RuntimeComponent component,
RuntimeComponentService service,
- Binding binding) {
+ Binding binding,
+ JMSResourceFactory jmsResourceFactory) {
super();
this.registry = registry;
this.component = component;
this.service = service;
this.binding = (JMSBinding)binding;
+ this.jmsResourceFactory = jmsResourceFactory;
// configure the service based on this wire format
@@ -97,7 +101,7 @@ public class WireFormatJMSBytesXMLServiceProvider implements WireFormatProvider
*/
public Interceptor createInterceptor() {
return new WireFormatJMSBytesXMLServiceInterceptor((JMSBinding)binding,
- null,
+ jmsResourceFactory,
service.getRuntimeWire(binding));
}