Author: lresende
Date: Wed May 20 06:18:05 2009
New Revision: 776577

URL: http://svn.apache.org/viewvc?rev=776577&view=rev
Log:
Reporting fault message with exception in json representation, when jsonrpc 
operation selector interceptor can't parse json request

Modified:
    
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
    
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
    
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java?rev=776577&r1=776576&r2=776577&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java
 Wed May 20 06:18:05 2009
@@ -27,6 +27,7 @@
 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 @@
     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 @@
             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 @@
         }
 
         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 @@
         }
 
         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;
+    }
 
 }

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java?rev=776577&r1=776576&r2=776577&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java
 Wed May 20 06:18:05 2009
@@ -24,14 +24,18 @@
 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 @@
                                                    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 @@
             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);
             }
         }
         

Modified: 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java?rev=776577&r1=776576&r2=776577&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
 Wed May 20 06:18:05 2009
@@ -110,6 +110,12 @@
         
     }
     
+
+    /**
+     * Create a Fault Message with a JSON representation of the current 
exception
+     * @param throwable
+     * @return
+     */
     private Message createJSONFaultMessage(Throwable throwable) {
         Message jsonFaultMessage = messageFactory.createMessage();
         


Reply via email to