diff options
Diffstat (limited to 'branches')
3 files changed, 49 insertions, 15 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java index eb85453bbb..245eade7ad 100644 --- a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java @@ -20,9 +20,11 @@ package org.apache.tuscany.sca.binding.jsonrpc.provider; import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProvider; @@ -37,11 +39,15 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService; */ public class JSONRPCBindingProviderFactory implements BindingProviderFactory<JSONRPCBinding> { + private MessageFactory messageFactory; private ServletHost servletHost; public JSONRPCBindingProviderFactory(ExtensionPointRegistry extensionPoints) { ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); this.servletHost = servletHosts.getServletHosts().get(0); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, @@ -54,7 +60,7 @@ public class JSONRPCBindingProviderFactory implements BindingProviderFactory<JSO public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, JSONRPCBinding binding) { - return new JSONRPCServiceBindingProvider(component, service, binding, servletHost); + return new JSONRPCServiceBindingProvider(component, service, binding, messageFactory, servletHost); } public Class<JSONRPCBinding> getModelType() { diff --git a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java index 8d9f8193e9..909bd7bc19 100644 --- a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java +++ b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java @@ -32,6 +32,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.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -48,6 +49,8 @@ public class JSONRPCServiceBindingProvider implements ServiceBindingProvider { // the same for clients using either the ajax or jsonrpc binding private static final String SCA_DOMAIN_SCRIPT = "/SCADomain/scaDomain.js"; + private MessageFactory messageFactory; + private RuntimeComponent component; private RuntimeComponentService service; private InterfaceContract serviceContract; @@ -59,10 +62,12 @@ public class JSONRPCServiceBindingProvider implements ServiceBindingProvider { public JSONRPCServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, JSONRPCBinding binding, + MessageFactory messageFactory, ServletHost servletHost) { this.component = component; this.service = service; this.binding = binding; + this.messageFactory = messageFactory; this.servletHost = servletHost; //clone the service contract to avoid databinding issues @@ -95,7 +100,7 @@ public class JSONRPCServiceBindingProvider implements ServiceBindingProvider { // Create and register a Servlet for this service JSONRPCServiceServlet serviceServlet = - new JSONRPCServiceServlet(binding, service, serviceContract, serviceInterface, proxy); + new JSONRPCServiceServlet(messageFactory, binding, service, serviceContract, serviceInterface, proxy); String mapping = binding.getURI(); if (!mapping.endsWith("/")) { mapping += "/"; diff --git a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java index c0d0415f91..85bae9085d 100644 --- a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java +++ b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java @@ -35,6 +35,8 @@ import javax.servlet.http.HttpSession; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeWire; import org.json.JSONArray; @@ -55,6 +57,8 @@ import com.metaparadigm.jsonrpc.JSONRPCServlet; public class JSONRPCServiceServlet extends JSONRPCServlet { private static final long serialVersionUID = 1L; + transient MessageFactory messageFactory; + transient Binding binding; transient String serviceName; transient Object serviceInstance; @@ -62,12 +66,14 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { transient InterfaceContract serviceContract; transient Class<?> serviceInterface; - public JSONRPCServiceServlet(Binding binding, + public JSONRPCServiceServlet(MessageFactory messageFactory, + Binding binding, RuntimeComponentService componentService, InterfaceContract serviceContract, Class<?> serviceInterface, Object serviceInstance) { - this.binding = binding; + this.messageFactory = messageFactory; + this.binding = binding; this.serviceName = binding.getName(); this.componentService = componentService; this.serviceContract = serviceContract; @@ -234,21 +240,38 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { Object result = null; try { - JSONObject jsonResponse = new JSONObject(); - result = wire.invoke(jsonOperation, args); + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + requestMessage.setOperation(jsonOperation); + + //store http request as a parameter to the message + requestMessage.getHeaders().add(request); + + requestMessage.setBody(args); - try { - jsonResponse.put("result", result); - jsonResponse.putOpt("id", id); - //get response to send to client - return jsonResponse.toString().getBytes("UTF-8"); - } catch (Exception e) { - throw new ServiceRuntimeException("Unable to create JSON response", e); + //result = wire.invoke(jsonOperation, args); + Message responseMessage = wire.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage); + + if (responseMessage.isFault()) { + throw new RuntimeException((Throwable)responseMessage.getBody()); + } else { + try { + result = responseMessage.getBody(); + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("result", result); + jsonResponse.putOpt("id", id); + //get response to send to client + return jsonResponse.toString().getBytes("UTF-8"); + } catch (Exception e) { + throw new ServiceRuntimeException("Unable to create JSON response", e); + } } - } catch (InvocationTargetException e) { + + + }/* catch (InvocationTargetException e) { JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() ); return errorResult.toString().getBytes("UTF-8"); - } catch(RuntimeException e) { + }*/ catch(RuntimeException e) { JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause()); return errorResult.toString().getBytes("UTF-8"); } |