diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-20 06:22:42 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-20 06:22:42 +0000 |
commit | 016d91d73396d778f544123efbd7ff81426a4e36 (patch) | |
tree | 9ea852189d8f48c5ef739a21cb41feff1f68d867 /branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java | |
parent | dfb810d7af4c69bf5f1fc023b5efd1e68f4e1a15 (diff) |
Properly handle SMD requests in JSON-RPC wire format/operation selector
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776580 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java')
-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.java | 44 |
1 files changed, 42 insertions, 2 deletions
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 8b128d3135..b314f69fcb 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 @@ -20,6 +20,9 @@ package org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.provider; import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingContext; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -42,12 +45,16 @@ public class JSONRPCWireFormatInterceptor implements Interceptor { private RuntimeWire runtimeWire; private HTTPBinding binding; + private InterfaceContract serviceContract; + private MessageFactory messageFactory; - public JSONRPCWireFormatInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, MessageFactory messageFactory) { + public JSONRPCWireFormatInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, InterfaceContract serviceContract, MessageFactory messageFactory) { this.binding = binding; this.runtimeWire = runtimeWire; + this.serviceContract = serviceContract; + this.messageFactory = messageFactory; } @@ -61,6 +68,25 @@ public class JSONRPCWireFormatInterceptor implements Interceptor { } public Message invoke(Message msg) { + HTTPBindingContext bindingContext = msg.getBindingContext(); + Message returnMessage = null; + + if ("smd".equals(bindingContext.getHttpRequest().getQueryString())) { + returnMessage = handleSMDInvocation(msg); + } else { + returnMessage = handleJSONRPCInvocation(msg); + } + + return returnMessage; + + } + + /** + * Handle regular JSON-RPC Invocation + * @param msg + * @return + */ + private Message handleJSONRPCInvocation (Message msg) { JSONObject jsonReq = (JSONObject) msg.getBody(); String method = null; Object[] args = null; @@ -112,9 +138,23 @@ public class JSONRPCWireFormatInterceptor implements Interceptor { Throwable exception = (Throwable)responseMessage.getBody(); return createJSONFaultMessage(exception); } - } + /** + * handles requests for the SMD descriptor for a service + */ + private Message handleSMDInvocation(Message msg) { + HTTPBindingContext bindingContext = msg.getBindingContext(); + + String serviceUrl = bindingContext.getHttpRequest().getRequestURL().toString(); + JavaInterface interfaze = (JavaInterface) serviceContract.getInterface(); + String smd = JavaToSmd.interfaceToSmd(interfaze.getJavaClass(), serviceUrl); + + Message smdResponseMessage = messageFactory.createMessage(); + smdResponseMessage.setBody(smd); + + return smdResponseMessage; + } /** * Create a Fault Message with a JSON representation of the current exception |