summaryrefslogtreecommitdiffstats
path: root/branches
diff options
context:
space:
mode:
Diffstat (limited to 'branches')
-rw-r--r--branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java38
-rw-r--r--branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java10
-rw-r--r--branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java6
3 files changed, 37 insertions, 17 deletions
diff --git a/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java b/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
index fb7c009aac..0d760ce6b8 100644
--- a/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
+++ b/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
@@ -27,6 +27,7 @@ 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.JSONObject;
@@ -38,11 +39,12 @@ public class JSONRPCOperationSelectorInterceptor implements Interceptor {
private RuntimeWire runtimeWire;
private HTTPBinding binding;
- //TODO: Pass messageFactory to create fault messages when error occur
- public JSONRPCOperationSelectorInterceptor(HTTPBinding binding, RuntimeWire runtimeWire) {
+ private MessageFactory messageFactory;
+
+ public JSONRPCOperationSelectorInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, MessageFactory messageFactory) {
this.binding = binding;
this.runtimeWire = runtimeWire;
-
+ this.messageFactory = messageFactory;
}
public Invoker getNext() {
@@ -63,14 +65,7 @@ public class JSONRPCOperationSelectorInterceptor implements Interceptor {
jsonReq = new JSONObject(data.toString());
method = jsonReq.getString("method");
} catch (Exception e) {
- //FIXME Exceptions are not handled correctly here
- // They should be reported to the client JavaScript as proper
- // JavaScript exceptions.
- throw new RuntimeException("Unable to parse request", e);
-
- //FIXME should create a fault message and stuff the JSON Result in the body of the message
- //JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, e);
- //return errorResult;
+ Throwable exception = new RuntimeException("Unable to parse request", e);
}
Operation jsonOperation = findOperation(method);
@@ -92,9 +87,6 @@ public class JSONRPCOperationSelectorInterceptor implements Interceptor {
}
List<Operation> operations = runtimeWire.getTarget().getInterfaceContract().getInterface().getOperations();
- //serviceContract.getInterface().getOperations();
- //componentService.getBindingProvider(binding).getBindingInterfaceContract().getInterface().getOperations();
-
Operation result = null;
for (Operation o : operations) {
@@ -105,6 +97,22 @@ public class JSONRPCOperationSelectorInterceptor implements Interceptor {
}
return result;
- }
+ }
+
+
+
+ /**
+ * Create a Fault Message with a JSON representation of the current exception
+ * @param throwable
+ * @return
+ */
+ private Message createJSONFaultMessage(Throwable throwable) {
+ Message jsonFaultMessage = messageFactory.createMessage();
+
+ JSONRPCResult jsonFault = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, null, throwable);
+ jsonFaultMessage.setBody(jsonFault);
+
+ return jsonFaultMessage;
+ }
}
diff --git a/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java b/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
index d3591fe5f3..a44e36b160 100644
--- a/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
+++ b/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
@@ -24,14 +24,18 @@ import org.apache.tuscany.sca.assembly.BindingRRB;
import org.apache.tuscany.sca.assembly.OperationSelector;
import org.apache.tuscany.sca.binding.http.HTTPBinding;
import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
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.OperationSelectorProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
public class JSONRPCOperationSelectorServiceProvider implements OperationSelectorProvider {
+ private MessageFactory messageFactory;
+
private RuntimeComponent component;
private RuntimeComponentService service;
private Binding binding;
@@ -40,7 +44,9 @@ public class JSONRPCOperationSelectorServiceProvider implements OperationSelecto
RuntimeComponent component,
RuntimeComponentService service,
Binding binding) {
- super();
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ messageFactory = modelFactories.getFactory(MessageFactory.class);
+
this.component = component;
this.service = service;
this.binding = binding;
@@ -51,7 +57,7 @@ public class JSONRPCOperationSelectorServiceProvider implements OperationSelecto
BindingRRB rrbBinding = (BindingRRB) binding;
OperationSelector operationSelector = rrbBinding.getOperationSelector();
if(operationSelector != null && operationSelector instanceof JSONRPCOperationSelector) {
- return new JSONRPCOperationSelectorInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding));
+ return new JSONRPCOperationSelectorInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding), messageFactory);
}
}
diff --git a/branches/sca-java-1.x/modules/binding-http-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-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
index 85f5f1e27f..6369892361 100644
--- a/branches/sca-java-1.x/modules/binding-http-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-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
@@ -110,6 +110,12 @@ public class JSONRPCWireFormatInterceptor implements Interceptor {
}
+
+ /**
+ * Create a Fault Message with a JSON representation of the current exception
+ * @param throwable
+ * @return
+ */
private Message createJSONFaultMessage(Throwable throwable) {
Message jsonFaultMessage = messageFactory.createMessage();