diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src')
4 files changed, 149 insertions, 431 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java index 3de6e57dda..9691910893 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java @@ -19,20 +19,49 @@ package org.apache.tuscany.sca.binding.jsonrpc.provider; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; + +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentProducer; +import org.apache.http.entity.EntityTemplate; import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.databinding.json.JSONDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.DataExchangeSemantics; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; -import org.json.JSONArray; +import org.codehaus.jackson.map.AnnotationIntrospector; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.deser.CustomDeserializerFactory; +import org.codehaus.jackson.map.deser.StdDeserializerProvider; +import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; +import org.codehaus.jackson.map.ser.CustomSerializerFactory; +import org.codehaus.jackson.map.type.TypeFactory; +import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; +import org.codehaus.jackson.xc.XmlAdapterJsonDeserializer; +import org.codehaus.jackson.xc.XmlAdapterJsonSerializer; +import org.json.JSONException; import org.json.JSONObject; +import org.oasisopen.sca.ServiceRuntimeException; /** * Invoker for the JSONRPC Binding @@ -43,14 +72,14 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { private EndpointReference endpointReference; private Operation operation; private String uri; - + private ObjectMapper mapper; private HttpClient httpClient; public JSONRPCBindingInvoker(EndpointReference endpointReference, Operation operation, HttpClient httpClient) { this.endpointReference = endpointReference; this.operation = operation; this.uri = endpointReference.getBinding().getURI(); - + this.mapper = createObjectMapper(null); this.httpClient = httpClient; } @@ -60,36 +89,41 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { try { String requestId = "1"; post = new HttpPost(uri); - + HttpEntity entity = null; + Object[] args = msg.getBody(); final String db = msg.getOperation().getWrapper().getDataBinding(); - String req; + if (!db.equals(JSONDataBinding.NAME)) { - JSONObject jsonRequest = null; - ; - Object[] args = null; - try { - // Extract the method - jsonRequest = new JSONObject(); - jsonRequest.putOpt("method", "Service" + "." + msg.getOperation().getName()); - - // Extract the arguments - args = msg.getBody(); - JSONArray array = new JSONArray(); - for (int i = 0; i < args.length; i++) { - array.put(args[i]); - } - jsonRequest.putOpt("params", array); - jsonRequest.put("id", requestId); + // Construct a map to hold JSON-RPC request + final Map<String, Object> jsonRequest = new HashMap<String, Object>(); + jsonRequest.put("method", "Service" + "." + msg.getOperation().getName()); - } catch (Exception e) { - throw new RuntimeException("Unable to parse JSON parameter", e); + List<Object> params = null; + // Extract the arguments + args = msg.getBody(); + + if (args != null) { + params = Arrays.asList(args); + } else { + params = Collections.emptyList(); } - req = jsonRequest.toString(); + + jsonRequest.put("params", params); + jsonRequest.put("id", requestId); + + // Create content producer so that we can stream the json result out + ContentProducer cp = new ContentProducer() { + public void writeTo(OutputStream outstream) throws IOException { + mapper.writeValue(outstream, jsonRequest); + } + }; + entity = new EntityTemplate(cp); } else { - req = (String)((Object[])msg.getBody())[0]; + // Single string argument + entity = new StringEntity((String)args[0], "UTF-8"); } - StringEntity entity = new StringEntity(req, "UTF-8"); + post.setEntity(entity); response = httpClient.execute(post); @@ -97,16 +131,44 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //success try { - String entityResponse = EntityUtils.toString(response.getEntity()); + entity = response.getEntity(); + String entityResponse = EntityUtils.toString(entity); + entity.consumeContent(); if (!db.equals(JSONDataBinding.NAME)) { JSONObject jsonResponse = new JSONObject(entityResponse); + if (!jsonResponse.has("result")) { + processException(jsonResponse); + } + DataType outputType = operation.getOutputType(); + if (outputType == null) { + msg.setBody(null); + return msg; + } + //check requestId - if (!jsonResponse.getString("id").equalsIgnoreCase(requestId)) { - throw new RuntimeException("Invalid response id:" + requestId); + if (!requestId.equalsIgnoreCase(jsonResponse.optString("id"))) { + throw new ServiceRuntimeException("Invalid response id:" + requestId); } - msg.setBody(jsonResponse.get("result")); + Object rawResult = jsonResponse.get("result"); + if (rawResult == null) { + processException(jsonResponse); + } + + Class<?> returnType = outputType.getPhysical(); + Type genericReturnType = outputType.getGenericType(); + + ObjectMapper mapper = createObjectMapper(returnType); + String json = rawResult.toString(); + + // Jackson requires the quoted String so that readValue can work + if (returnType == String.class) { + json = "\"" + json + "\""; + } + Object body = mapper.readValue(json, TypeFactory.type(genericReturnType)); + + msg.setBody(body); } else { msg.setBody(entityResponse); } @@ -115,42 +177,68 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { //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 response", e); + throw new ServiceRuntimeException("Unable to parse response", e); } } } catch (Exception e) { - e.printStackTrace(); + // e.printStackTrace(); msg.setFaultBody(e); } return msg; } - private static JSONObject getJSONRequest(Message msg) { - - JSONObject jsonRequest = null; - ; - Object[] args = null; - Object id = null; - try { - // Extract the method - jsonRequest = new JSONObject(); - jsonRequest.putOpt("method", "Service" + "." + msg.getOperation().getName()); - - // Extract the arguments - args = msg.getBody(); - JSONArray array = new JSONArray(); - for (int i = 0; i < args.length; i++) { - array.put(args[i]); + public static ObjectMapper createObjectMapper(Class<?> cls) { + ObjectMapper mapper = new ObjectMapper(); + if (cls != null) { + // Workaround for http://jira.codehaus.org/browse/JACKSON-413 + Package pkg = cls.getPackage(); + if (pkg != null) { + XmlJavaTypeAdapters adapters = pkg.getAnnotation(XmlJavaTypeAdapters.class); + if (adapters != null) { + CustomSerializerFactory serializerFactory = new CustomSerializerFactory(); + CustomDeserializerFactory deserializerFactory = new CustomDeserializerFactory(); + for (XmlJavaTypeAdapter a : adapters.value()) { + XmlAdapter xmlAdapter = null; + try { + xmlAdapter = a.value().newInstance(); + } catch (Throwable e) { + // Ignore + } + if (xmlAdapter != null) { + XmlAdapterJsonDeserializer deserializer = new XmlAdapterJsonDeserializer(xmlAdapter); + XmlAdapterJsonSerializer serializer = new XmlAdapterJsonSerializer(xmlAdapter); + deserializerFactory.addSpecificMapping(a.type(), deserializer); + serializerFactory.addGenericMapping(a.type(), serializer); + StdDeserializerProvider deserializerProvider = + new StdDeserializerProvider(deserializerFactory); + mapper.setSerializerFactory(serializerFactory); + mapper.setDeserializerProvider(deserializerProvider); + } + } + } } - jsonRequest.putOpt("params", array); - id = jsonRequest.put("id", "1"); - - } catch (Exception e) { - throw new RuntimeException("Unable to parse JSON parameter", e); } + AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); + AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); + AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); + mapper.getDeserializationConfig().setAnnotationIntrospector(pair); + // [rfeng] To avoid complaints about javaClass + mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); + mapper.getSerializationConfig().setAnnotationIntrospector(pair); + return mapper; + } - return jsonRequest; + /** + * Generate and throw exception based on the data in the 'responseMessage' + */ + protected void processException(JSONObject responseMessage) throws JSONException { + JSONObject error = (JSONObject)responseMessage.get("error"); + if (error != null) { + throw new ServiceRuntimeException(error.toString()); + } else { + throw new ServiceRuntimeException(responseMessage.toString()); + } } @Override diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClient.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClient.java deleted file mode 100644 index f427233e52..0000000000 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClient.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.jsonrpc.provider; - -import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Iterator; - -import javax.xml.bind.annotation.adapters.XmlAdapter; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; - -import org.codehaus.jackson.JsonFactory; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.map.AnnotationIntrospector; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.deser.CustomDeserializerFactory; -import org.codehaus.jackson.map.deser.StdDeserializerProvider; -import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; -import org.codehaus.jackson.map.ser.CustomSerializerFactory; -import org.codehaus.jackson.map.type.TypeFactory; -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; -import org.codehaus.jackson.xc.XmlAdapterJsonDeserializer; -import org.codehaus.jackson.xc.XmlAdapterJsonSerializer; -import org.jabsorb.JSONRPCBridge; -import org.jabsorb.JSONRPCResult; -import org.jabsorb.JSONSerializer; -import org.jabsorb.client.ClientError; -import org.jabsorb.client.ErrorResponse; -import org.jabsorb.client.Session; -import org.jabsorb.serializer.FixUp; -import org.jabsorb.serializer.SerializerState; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -public class JSONRPCClient implements InvocationHandler { - // private static Logger log = LoggerFactory.getLogger(JsonrpcClient.class); - - private Session session; - private JSONSerializer serializer; - - /** - * Maintain a unique id for each message - */ - private int id = 0; - - /** - * Allow access to the serializer - * - * @return The serializer for this class - */ - public JSONSerializer getSerializer() { - return serializer; - } - - /** - * Create a client given a session - * - * @param session -- - * transport session to use for this connection - */ - public JSONRPCClient(Session session) { - try { - this.session = session; - serializer = new JSONSerializer(); - serializer.registerDefaultSerializers(); - serializer.setMarshallClassHints(false); - serializer.setMarshallNullAttributes(false); - } catch (Exception e) { - throw new ClientError(e); - } - } - - private synchronized int getId() { - return id++; - } - - /** Manual instantiation of HashMap<String, Object> */ - private static class ProxyMap extends HashMap<Object, Object> { - public String getString(Object key) { - return (String)super.get(key); - } - - public Object putString(String key, Object value) { - return super.put(key, value); - } - } - - private ProxyMap proxyMap = new ProxyMap(); - - /** - * Create a proxy for communicating with the remote service. - * - * @param key - * the remote object key - * @param klass - * the class of the interface the remote object should adhere to - * @return created proxy - */ - public Object openProxy(String key, Class klass) { - Object result = java.lang.reflect.Proxy.newProxyInstance(klass.getClassLoader(), new Class[] {klass}, this); - proxyMap.put(result, key); - return result; - } - - /** - * Dispose of the proxy that is no longer needed - * - * @param proxy - */ - public void closeProxy(Object proxy) { - proxyMap.remove(proxy); - } - - /** - * This method is public because of the inheritance from the - * InvokationHandler -- should never be called directly. - */ - public Object invoke(Object proxyObj, Method method, Object[] args) throws Exception { - String methodName = method.getName(); - if (methodName.equals("hashCode")) { - return new Integer(System.identityHashCode(proxyObj)); - } else if (methodName.equals("equals")) { - return (proxyObj == args[0] ? Boolean.TRUE : Boolean.FALSE); - } else if (methodName.equals("toString")) { - return proxyObj.getClass().getName() + '@' + Integer.toHexString(proxyObj.hashCode()); - } - return invoke(proxyMap.getString(proxyObj), - method.getName(), - args, - method.getReturnType(), - method.getGenericReturnType()); - } - - private Object invoke(String objectTag, String methodName, Object[] args, Class returnType, Type genericReturnType) - throws Exception { - final int id = getId(); - JSONObject message = new JSONObject(); - String methodTag = objectTag == null ? "" : objectTag + "."; - methodTag += methodName; - message.put("method", methodTag); - - { - SerializerState state = new SerializerState(); - - if (args != null) { - - JSONArray params = marshal(args); // (JSONArray)serializer.marshall(state, /* parent */ null, args, "params"); - - if ((state.getFixUps() != null) && (state.getFixUps().size() > 0)) { - JSONArray fixups = new JSONArray(); - for (Iterator i = state.getFixUps().iterator(); i.hasNext();) { - FixUp fixup = (FixUp)i.next(); - fixups.put(fixup.toJSONArray()); - } - message.put("fixups", fixups); - } - message.put("params", params); - } else { - message.put("params", new JSONArray()); - } - } - message.put("id", id); - - JSONObject responseMessage = session.sendAndReceive(message); - - if (!responseMessage.has("result")) { - processException(responseMessage); - } - Object rawResult = responseMessage.get("result"); - if (rawResult == null) { - processException(responseMessage); - } - if (returnType.equals(Void.TYPE)) { - return null; - } - - { - JSONArray fixups = responseMessage.optJSONArray("fixups"); - - if (fixups != null) { - for (int i = 0; i < fixups.length(); i++) { - JSONArray assignment = fixups.getJSONArray(i); - JSONArray fixup = assignment.getJSONArray(0); - JSONArray original = assignment.getJSONArray(1); - JSONRPCBridge.applyFixup(rawResult, fixup, original); - } - } - } - if (returnType.isInterface()) { - ObjectMapper mapper = createObjectMapper(returnType); - return mapper.readValue(rawResult.toString(), TypeFactory.type(genericReturnType)); - } - return serializer.unmarshall(new SerializerState(), returnType, rawResult); - } - - private JSONArray marshal(Object[] args) throws Exception { - if(args==null) { - return new JSONArray(); - } - ObjectMapper mapper = createObjectMapper(null); - String json = mapper.writeValueAsString(args); - return new JSONArray(json); - } - - public static JsonParser createJsonParser(String content) { - JsonFactory jsonFactory = new JsonFactory(); - try { - return jsonFactory.createJsonParser(content); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - } - - public static ObjectMapper createObjectMapper(Class<?> cls) { - ObjectMapper mapper = new ObjectMapper(); - if (cls != null) { - // Workaround for http://jira.codehaus.org/browse/JACKSON-413 - Package pkg = cls.getPackage(); - if (pkg != null) { - XmlJavaTypeAdapters adapters = pkg.getAnnotation(XmlJavaTypeAdapters.class); - if (adapters != null) { - CustomSerializerFactory serializerFactory = new CustomSerializerFactory(); - CustomDeserializerFactory deserializerFactory = new CustomDeserializerFactory(); - for (XmlJavaTypeAdapter a : adapters.value()) { - XmlAdapter xmlAdapter = null; - try { - xmlAdapter = a.value().newInstance(); - } catch (Throwable e) { - // Ignore - } - if (xmlAdapter != null) { - XmlAdapterJsonDeserializer deserializer = new XmlAdapterJsonDeserializer(xmlAdapter); - XmlAdapterJsonSerializer serializer = new XmlAdapterJsonSerializer(xmlAdapter); - deserializerFactory.addSpecificMapping(a.type(), deserializer); - serializerFactory.addGenericMapping(a.type(), serializer); - StdDeserializerProvider deserializerProvider = - new StdDeserializerProvider(deserializerFactory); - mapper.setSerializerFactory(serializerFactory); - mapper.setDeserializerProvider(deserializerProvider); - } - } - } - } - } - AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); - AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); - AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); - mapper.getDeserializationConfig().setAnnotationIntrospector(pair); - // [rfeng] To avoid complaints about javaClass - mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.getSerializationConfig().setAnnotationIntrospector(pair); - return mapper; - } - - /** - * Generate and throw exception based on the data in the 'responseMessage' - */ - protected void processException(JSONObject responseMessage) throws JSONException { - JSONObject error = (JSONObject)responseMessage.get("error"); - if (error != null) { - Integer code = new Integer(error.has("code") ? error.getInt("code") : 0); - String trace = error.has("trace") ? error.getString("trace") : null; - String msg = error.has("msg") ? error.getString("msg") : null; - throw new ErrorResponse(code, msg, trace); - } else - throw new ErrorResponse(new Integer(JSONRPCResult.CODE_ERR_PARSE), - "Unknown response:" + responseMessage.toString(2), null); - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClientInvoker.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClientInvoker.java deleted file mode 100644 index 3b2d2b707d..0000000000 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCClientInvoker.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.jsonrpc.provider; - -import java.lang.reflect.Method; - -import org.apache.http.client.HttpClient; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaOperation; -import org.apache.tuscany.sca.invocation.DataExchangeSemantics; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.jabsorb.client.Session; -import org.jabsorb.client.TransportRegistry; - -/** - * Invoker for the JSONRPC Binding - * - * @version $Rev$ $Date$ - */ -public class JSONRPCClientInvoker implements Invoker, DataExchangeSemantics { - private EndpointReference endpointReference; - private Operation operation; - private Method method; - private String uri; - - public JSONRPCClientInvoker(EndpointReference endpointReference, Operation operation, HttpClient httpClient) { - this.endpointReference = endpointReference; - this.operation = operation; - this.method = ((JavaOperation)operation).getJavaMethod(); - this.uri = ((JSONRPCBinding)endpointReference.getBinding()).getURI(); - } - - public Message invoke(Message msg) { - Session session = TransportRegistry.i().createSession(uri); - JSONRPCClient client = new JSONRPCClient(session); - Object proxy = client.openProxy("", method.getDeclaringClass()); - - try { - Object result = client.invoke(proxy, method, (Object[])msg.getBody()); - msg.setBody(result); - } catch (Exception e) { - msg.setFaultBody(e); - } finally { - client.closeProxy(proxy); - session.close(); - } - return msg; - } - - @Override - public boolean allowsPassByReference() { - return true; - } - -} diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java index 3eaf6ceb7a..d14d51fd0d 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java @@ -33,7 +33,6 @@ import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; import org.apache.http.protocol.HTTP; import org.apache.tuscany.sca.assembly.EndpointReference; -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.Invoker; @@ -70,7 +69,7 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider */ // Create an HTTP client - httpClient = createHttpClient(); + // httpClient = createHttpClient(); } public HttpClient createHttpClient() { @@ -95,19 +94,18 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider } public Invoker createInvoker(Operation operation) { - final Interface intf = reference.getInterfaceContract().getInterface(); - if (intf.isDynamic()) { - return new JSONRPCBindingInvoker(endpointReference, operation, httpClient); - } - return new JSONRPCClientInvoker(endpointReference, operation, httpClient); + // final Interface intf = reference.getInterfaceContract().getInterface(); + return new JSONRPCBindingInvoker(endpointReference, operation, httpClient); } public void start() { - + this.httpClient = createHttpClient(); } public void stop() { - + if (httpClient != null) { + httpClient.getConnectionManager().shutdown(); + } } public boolean supportsOneWayInvocation() { |