summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java17
-rw-r--r--sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ServiceInvoker.java15
-rw-r--r--sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java3
-rw-r--r--sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/TestServiceImpl.java2
4 files changed, 30 insertions, 7 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java
index c96616d132..cb01e8c34c 100644
--- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java
+++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java
@@ -24,11 +24,14 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask;
+import javax.xml.namespace.QName;
+
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.endpoint.hazelcast.HazelcastEndpointRegistry;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.invocation.MessageFactory;
@@ -87,9 +90,19 @@ public class ReferenceInvoker implements Invoker {
}
private Message getResponseNode(String responseXML) throws IOException, SAXException {
- Document responseDOM = domHelper.load(responseXML);
Message msg = messageFactory.createMessage();
- msg.setBody(responseDOM);
+ if (responseXML.startsWith("DECLAREDEXCEPTION:")) {
+ Document responseDOM = domHelper.load(responseXML.substring(18));
+ FaultException e = new FaultException("remote exception", responseDOM);
+ Node node = ((Node)responseDOM).getFirstChild();
+ e.setFaultName(new QName(node.getNamespaceURI(), node.getLocalName()));
+ msg.setFaultBody(e);
+ } else if (responseXML.startsWith("EXCEPTION:")) {
+ throw new ServiceRuntimeException("Remote exception:" + responseXML.substring(10));
+ } else {
+ Document responseDOM = domHelper.load(responseXML);
+ msg.setBody(responseDOM);
+ }
return msg;
}
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ServiceInvoker.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ServiceInvoker.java
index 14acf7ecb5..30b23ac268 100644
--- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ServiceInvoker.java
+++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ServiceInvoker.java
@@ -21,12 +21,14 @@ package org.apache.tuscany.sca.binding.hazelcast;
import java.io.IOException;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Callable;
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
import org.oasisopen.sca.ServiceRuntimeException;
import org.w3c.dom.Document;
@@ -52,8 +54,17 @@ public class ServiceInvoker implements Callable<String>, Serializable {
Operation operation = getRequestOperation(endpoint);
DOMHelper domHelper = DOMHelper.getInstance(endpoint.getCompositeContext().getExtensionPointRegistry());
Object[] args = getRequestArgs(domHelper);
- Object response = endpoint.invoke(operation, args);
- String responseXML = getResponseXML(domHelper, response);
+ String responseXML;
+ try {
+ Object response = endpoint.invoke(operation, args);
+ responseXML = getResponseXML(domHelper, response);
+ } catch (Exception e) {
+ if (e instanceof InvocationTargetException && ((InvocationTargetException)e).getTargetException() instanceof FaultException) {
+ responseXML = "DECLAREDEXCEPTION:" + getResponseXML(domHelper, ((FaultException)((InvocationTargetException)e).getTargetException()).getFaultInfo());
+ } else {
+ responseXML = "EXCEPTION: " + e.getClass() + ":" + e.getMessage();
+ }
+ }
return responseXML;
}
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java
index 5b20c99a00..6a3fff0757 100644
--- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java
@@ -89,8 +89,7 @@ public class HazelcastBindingTestCase {
service.testExceptions("runtime");
fail();
} catch (ServiceRuntimeException e) {
- // TODO test what the exception should be
-// assertEquals("runtime", e.getMessage());
+ assertEquals("org.oasisopen.sca.ServiceRuntimeException: Remote exception: class java.lang.RuntimeException:runtime", e.getMessage());
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/TestServiceImpl.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/TestServiceImpl.java
index 3042d25ada..6c9a5d71bf 100644
--- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/TestServiceImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/TestServiceImpl.java
@@ -35,7 +35,7 @@ public class TestServiceImpl implements TestService {
public String testExceptions(String s) throws BadStringException {
if (s.equals("runtime")) {
- throw new RuntimeException();
+ throw new RuntimeException("runtime");
}
throw new BadStringException(s);
}