summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-02 16:17:38 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-02 16:17:38 +0000
commited1440d4265412db68f41f07e570511a56947081 (patch)
tree8622e5e9989552023a731f128046154261baf63b /sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache
parentfae4b7f974ac7ae22d0a8e5c6923d2cb021081f8 (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-atom-runtime/src/main/java/org/apache')
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java2
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java5
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java12
3 files changed, 13 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
index 4af8c3ca14..e6e85447a9 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
@@ -233,11 +233,13 @@ class AtomBindingInvoker implements Invoker {
}
} else if (status == 404) {
+ response.getEntity().consumeContent();
if (provider.supportsFeedEntries())
msg.setFaultBody(new NotFoundException());
else
msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException());
} else {
+ response.getEntity().consumeContent();
msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status));
}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
index a160925e4e..9d41fd2a50 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
@@ -26,6 +26,7 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.databinding.Mediator;
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;
@@ -43,16 +44,18 @@ public class AtomBindingProviderFactory implements BindingProviderFactory<AtomBi
private MessageFactory messageFactory;
private Mediator mediator;
private ServletHost servletHost;
+ private HttpClientFactory httpClientFactory;
public AtomBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
this.servletHost = ServletHostHelper.getServletHost(extensionPoints);
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
this.messageFactory = modelFactories.getFactory(MessageFactory.class);
this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ this.httpClientFactory = HttpClientFactory.getInstance(extensionPoints);
}
public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) {
- return new AtomReferenceBindingProvider(endpointReference, mediator);
+ return new AtomReferenceBindingProvider(httpClientFactory, endpointReference, mediator);
}
public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) {
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
index 9f4ea496c1..024705803f 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
@@ -39,6 +39,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
* @version $Rev$ $Date$
*/
class AtomReferenceBindingProvider implements ReferenceBindingProvider {
+ private HttpClientFactory httpClientFactory;
private EndpointReference endpointReference;
private RuntimeComponentReference reference;
private AtomBinding binding;
@@ -56,11 +57,13 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider {
* @param binding
* @param mediator
*/
- AtomReferenceBindingProvider(EndpointReference endpointReference,
+ AtomReferenceBindingProvider(HttpClientFactory httpClientFactory,
+ EndpointReference endpointReference,
Mediator mediator) {
+ this.httpClientFactory = httpClientFactory;
this.endpointReference = endpointReference;
- this.reference = (RuntimeComponentReference) endpointReference.getReference();
- this.binding = (AtomBinding) endpointReference.getBinding();
+ this.reference = (RuntimeComponentReference)endpointReference.getReference();
+ this.binding = (AtomBinding)endpointReference.getBinding();
this.mediator = mediator;
// Prepare authorization header
@@ -121,8 +124,7 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider {
// Find the get operation on the reference interface
// Create an HTTP client
- HttpClientFactory clientFactory = new HttpClientFactory();
- httpClient = clientFactory.createHttpClient();
+ httpClient = httpClientFactory.createHttpClient();
}
public void stop() {