tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1164605 - in /tuscany/sca-java-2.x/trunk/modules: binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/ binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/
Date Fri, 02 Sep 2011 16:17:39 GMT
Author: rfeng
Date: Fri Sep  2 16:17:38 2011
New Revision: 1164605

URL: http://svn.apache.org/viewvc?rev=1164605&view=rev
Log:
Fix the usage of HttpClient and make sure connections are closed gracefully

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
    tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
    tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java
Fri Sep  2 16:17:38 2011
@@ -233,11 +233,13 @@ class AtomBindingInvoker implements Invo
                     }
 
                 } 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));
                 }
 

Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java
Fri Sep  2 16:17:38 2011
@@ -26,6 +26,7 @@ import org.apache.tuscany.sca.core.Utili
 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 
     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)
{

Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java
Fri Sep  2 16:17:38 2011
@@ -39,6 +39,7 @@ import org.apache.tuscany.sca.runtime.Ru
  * @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 imple
      * @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 imple
 
         // 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() {

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
Fri Sep  2 16:17:38 2011
@@ -183,6 +183,10 @@ public class JSONRPCBindingInvoker imple
                     // 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();

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
Fri Sep  2 16:17:38 2011
@@ -24,6 +24,7 @@ import org.apache.tuscany.sca.core.Exten
 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 JSONRPCBindingProviderFacto
 
     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)
{

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java?rev=1164605&r1=1164604&r2=1164605&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
Fri Sep  2 16:17:38 2011
@@ -39,10 +39,11 @@ public class JSONRPCReferenceBindingProv
     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 JSONRPCReferenceBindingProv
 
     public void start() {
         // Create an HTTP client
-        HttpClientFactory clientFactory = new HttpClientFactory();
-        httpClient = clientFactory.createHttpClient();
+        httpClient = httpClientFactory.createHttpClient();
     }
 
     public void stop() {



Mime
View raw message