diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-02 16:17:38 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-02 16:17:38 +0000 |
commit | ed1440d4265412db68f41f07e570511a56947081 (patch) | |
tree | 8622e5e9989552023a731f128046154261baf63b /sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca | |
parent | fae4b7f974ac7ae22d0a8e5c6923d2cb021081f8 (diff) |
Fix the usage of HttpClient and make sure connections are closed gracefully
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1164605 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca')
3 files changed, 12 insertions, 5 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 526283c8fa..348b76bd14 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 @@ -183,6 +183,10 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { // JavaScript exceptions. throw new ServiceRuntimeException("Unable to parse response", e); } + } else { + // Consume the content so the connection can be released + response.getEntity().consumeContent(); + throw new ServiceRuntimeException("Abnormal HTTP response: " + response.getStatusLine().toString()); } } catch (Exception e) { // e.printStackTrace(); diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java index c9b9328b61..8ecadf4a92 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java @@ -24,6 +24,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostHelper; +import org.apache.tuscany.sca.host.http.client.HttpClientFactory; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; @@ -40,16 +41,18 @@ public class JSONRPCBindingProviderFactory implements BindingProviderFactory<JSO private MessageFactory messageFactory; private ServletHost servletHost; + private HttpClientFactory httpClientFactory; public JSONRPCBindingProviderFactory(ExtensionPointRegistry extensionPoints) { this.servletHost = ServletHostHelper.getServletHost(extensionPoints); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); messageFactory = modelFactories.getFactory(MessageFactory.class); + this.httpClientFactory = HttpClientFactory.getInstance(extensionPoints); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { - return new JSONRPCReferenceBindingProvider(endpointReference); + return new JSONRPCReferenceBindingProvider(httpClientFactory, endpointReference); } public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { 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 d0b24a0253..f7fda6e83c 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 @@ -39,10 +39,11 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider private RuntimeComponentReference reference; private InterfaceContract referenceContract; + private HttpClientFactory httpClientFactory; private HttpClient httpClient; - public JSONRPCReferenceBindingProvider(EndpointReference endpointReference) { - + public JSONRPCReferenceBindingProvider(HttpClientFactory httpClientFactory, EndpointReference endpointReference) { + this.httpClientFactory = httpClientFactory; this.endpointReference = endpointReference; this.reference = (RuntimeComponentReference)endpointReference.getReference(); @@ -74,8 +75,7 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider public void start() { // Create an HTTP client - HttpClientFactory clientFactory = new HttpClientFactory(); - httpClient = clientFactory.createHttpClient(); + httpClient = httpClientFactory.createHttpClient(); } public void stop() { |