summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-1.x')
-rw-r--r--branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java31
-rw-r--r--branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java11
2 files changed, 28 insertions, 14 deletions
diff --git a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
index 6bd0298923..c93aa38613 100644
--- a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
+++ b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
@@ -19,17 +19,11 @@
package org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.provider;
-import java.util.List;
-
import org.apache.tuscany.sca.binding.http.HTTPBinding;
-import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
-import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
-import org.apache.tuscany.sca.interfacedef.DataType;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
import org.apache.tuscany.sca.runtime.RuntimeWire;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -38,16 +32,18 @@ import org.osoa.sca.ServiceRuntimeException;
import com.metaparadigm.jsonrpc.JSONRPCResult;
public class JSONRPCWireFormatInterceptor implements Interceptor {
- private Invoker next;
+ private Invoker next;
private RuntimeWire runtimeWire;
private HTTPBinding binding;
- //TODO: Pass messageFactory to create fault messages when error occur
- public JSONRPCWireFormatInterceptor(HTTPBinding binding, RuntimeWire runtimeWire) {
+ private MessageFactory messageFactory;
+
+ public JSONRPCWireFormatInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, MessageFactory messageFactory) {
this.binding = binding;
this.runtimeWire = runtimeWire;
+ this.messageFactory = messageFactory;
}
public Invoker getNext() {
@@ -92,11 +88,14 @@ public class JSONRPCWireFormatInterceptor implements Interceptor {
// They should be reported to the client JavaScript as proper
// JavaScript exceptions.
- throw new RuntimeException("Error invoking service :" + re.getMessage(), re);
+ //throw new RuntimeException("Error invoking service :" + re.getMessage(), re);
//FIXME should create a fault message and stuff the JSON Result in the body of the message
//JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
//return errorResult.toString().getBytes("UTF-8");
+
+ Throwable exception = new RuntimeException("Error invoking service :" + re.getMessage(), re);
+ return createJSONFaultMessage(re);
}
Object result = null;
@@ -117,11 +116,19 @@ public class JSONRPCWireFormatInterceptor implements Interceptor {
//exception thrown while executing the invocation
//FIXME should create a fault message and stuff the JSON Result in the body of the message
Throwable exception = (Throwable)responseMessage.getBody();
+ return createJSONFaultMessage( exception);
//JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
//return errorResult.toString().getBytes("UTF-8");
}
+ }
+
+ private Message createJSONFaultMessage(Throwable throwable) {
+ Message jsonFaultMessage = messageFactory.createMessage();
+
+ JSONRPCResult jsonFault = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, null, throwable);
+ jsonFaultMessage.setBody(jsonFault);
- return responseMessage;
+ return jsonFaultMessage;
}
}
diff --git a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
index 89c43c0510..a5d15f7f27 100644
--- a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
+++ b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
@@ -26,6 +26,7 @@ import org.apache.tuscany.sca.assembly.BindingRRB;
import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.binding.http.HTTPBinding;
import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
@@ -34,6 +35,7 @@ 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.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.MessageFactory;
import org.apache.tuscany.sca.invocation.Phase;
import org.apache.tuscany.sca.provider.WireFormatProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -43,6 +45,8 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
* @version $Rev$ $Date$
*/
public class JSONRPCWireFormatServiceProvider implements WireFormatProvider {
+ private MessageFactory messageFactory;
+
private RuntimeComponent component;
private RuntimeComponentService service;
private InterfaceContract serviceContract;
@@ -53,7 +57,10 @@ public class JSONRPCWireFormatServiceProvider implements WireFormatProvider {
RuntimeComponentService service,
Binding binding) {
- super();
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ messageFactory = modelFactories.getFactory(MessageFactory.class);
+
this.component = component;
this.service = service;
this.serviceContract = service.getInterfaceContract();
@@ -76,7 +83,7 @@ public class JSONRPCWireFormatServiceProvider implements WireFormatProvider {
BindingRRB rrbBinding = (BindingRRB) binding;
WireFormat wireFormat = rrbBinding.getRequestWireFormat();
if(wireFormat != null && wireFormat instanceof JSONRPCWireFormat) {
- return new JSONRPCWireFormatInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding));
+ return new JSONRPCWireFormatInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding), messageFactory);
}
}