Author: veithen
Date: Sun Oct 16 21:58:15 2016
New Revision: 1765193

URL: http://svn.apache.org/viewvc?rev=1765193&view=rev
Log:
AXIS2-5809: Ensure that connections are properly released.

Modified:
    
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/EchoServiceImpl.java
    
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java

Modified: 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/EchoServiceImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/EchoServiceImpl.java?rev=1765193&r1=1765192&r2=1765193&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/EchoServiceImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/EchoServiceImpl.java
 Sun Oct 16 21:58:15 2016
@@ -21,6 +21,10 @@ package org.apache.axis2.databinding.axi
 public class EchoServiceImpl extends EchoServiceSkeleton {
     @Override
     public EchoResponse echo(Echo echo) {
+        String content = echo.getContent();
+        if (content.isEmpty()) {
+            throw new RuntimeException();
+        }
         EchoResponse response = new EchoResponse();
         response.setContent(echo.getContent());
         return response;

Modified: 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java?rev=1765193&r1=1765192&r2=1765193&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
 Sun Oct 16 21:58:15 2016
@@ -19,7 +19,9 @@
 package org.apache.axis2.databinding.axis2_5809;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.testutils.Axis2Server;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -29,7 +31,7 @@ public class ServiceTest {
     public static Axis2Server server = new 
Axis2Server("target/repo/AXIS2-5809");
     
     @Test
-    public void test() throws Exception {
+    public void testWithNormalResponse() throws Exception {
         EchoServiceStub stub = new 
EchoServiceStub(server.getConfigurationContext(), 
server.getEndpoint("EchoService"));
         for (int i=0; i<500; i++) {
             Echo request = new Echo();
@@ -37,4 +39,19 @@ public class ServiceTest {
             assertThat(stub.echo(request).getContent()).isEqualTo("test");
         }
     }
+    
+    @Test
+    public void testWithFault() throws Exception {
+        EchoServiceStub stub = new 
EchoServiceStub(server.getConfigurationContext(), 
server.getEndpoint("EchoService"));
+        for (int i=0; i<500; i++) {
+            Echo request = new Echo();
+            request.setContent("");
+            try {
+                stub.echo(request);
+                fail("Expected AxisFault");
+            } catch (AxisFault ex) {
+                // Expected
+            }
+        }
+    }
 }

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java?rev=1765193&r1=1765192&r2=1765193&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java
 Sun Oct 16 21:58:15 2016
@@ -19,9 +19,13 @@
 
 package org.apache.axis2.transport.http.impl.httpclient4;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.transport.http.AbstractHTTPSender;
 import org.apache.axis2.transport.http.AbstractHTTPTransportSender;
 import org.apache.axis2.transport.http.HTTPConstants;
@@ -38,10 +42,20 @@ public class HTTPClient4TransportSender
 
     @Override
     public void cleanup(MessageContext msgContext) throws AxisFault {
-        // We don't need to call cleanup here because httpclient4 releases
-        // the connection and cleanup automatically
-        // TODO : Don't do this if we're not on the right thread! Can we 
confirm?
         log.trace("cleanup() releasing connection");
+        
+        OperationContext opContext = msgContext.getOperationContext();
+        if (opContext != null) {
+            InputStream in = 
(InputStream)opContext.getProperty(MessageContext.TRANSPORT_IN);
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ex) {
+                    // Ignore
+                }
+            }
+        }
+        
         // guard against multiple calls
         msgContext.removeProperty(HTTPConstants.HTTP_METHOD);
 


Reply via email to