You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Er...@wellsfargo.com on 2004/05/29 01:29:15 UTC

FW: cvs commit: ws-axis/java/src/org/apache/axis/transport/http C ommonsHTTPSender.java

Poked around on jira for a bit and didn't see how I'm supposed to mark this
bug as fixed.  Any pointers?

-----Original Message-----
From: ericf@apache.org [mailto:ericf@apache.org]
Sent: Friday, May 28, 2004 4:23 PM
To: ws-axis-cvs@apache.org
Subject: cvs commit: ws-axis/java/src/org/apache/axis/transport/http
CommonsHTTPSender.java


ericf       2004/05/28 16:22:42

  Modified:    java/src/org/apache/axis/transport/http
                        CommonsHTTPSender.java
  Log:
  Fix for AXIS-1369, Deadlock when using HttpClient.
  Added calls to release the connection back to the pool when a fault is
  thrown or when the stream with the response in it is closed.
  
  Revision  Changes    Path
  1.24      +27 -8
ws-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.java
  
  Index: CommonsHTTPSender.java
  ===================================================================
  RCS file:
/home/cvs/ws-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.
java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CommonsHTTPSender.java	11 May 2004 13:36:35 -0000	1.23
  +++ CommonsHTTPSender.java	28 May 2004 23:22:42 -0000	1.24
  @@ -45,6 +45,9 @@
   
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  +import java.io.FilterInputStream;
  +import java.io.InputStream;
  +import java.io.IOException;
   import java.net.URL;
   import java.util.Hashtable;
   import java.util.Iterator;
  @@ -196,11 +199,19 @@
                   + statusMessage, null,
                   null);
                   
  -
fault.setFaultDetailString(Messages.getMessage("return01",
  -                "" + returnCode, method.getResponseBodyAsString()));
  -                throw fault;
  +                try {
  +
fault.setFaultDetailString(Messages.getMessage("return01",
  +                    "" + returnCode, method.getResponseBodyAsString()));
  +                    throw fault;
  +                } finally {
  +                    method.releaseConnection(); // release connection
back to pool.
  +                }
               }
  -            Message outMsg = new
Message(method.getResponseBodyAsStream(),
  +
  +            // wrap the response body stream so that close() also
releases the connection back to the pool.
  +            InputStream releaseConnectionOnCloseStream =
createConnectionReleasingInputStream(method);
  +
  +            Message outMsg = new Message(releaseConnectionOnCloseStream,
               false, contentType, contentLocation);
               // Transfer HTTP headers of HTTP message to MIME headers of
SOAP message
               Header[] responseHeaders = method.getResponseHeaders();
  @@ -209,10 +220,6 @@
                   Header responseHeader = responseHeaders[i];
                   responseMimeHeaders.addHeader(responseHeader.getName(),
responseHeader.getValue());
               }
  -            // no need to invoke method.releaseConnection here, as that
will
  -            // happen automatically when the response body is read.
  -            // issue: what if the stream is never closed?  Are we certain
  -            // that InputStream.close() always gets called?
               outMsg.setMessageType(Message.RESPONSE);
               msgContext.setResponseMessage(outMsg);
               if (log.isDebugEnabled()) {
  @@ -587,6 +594,18 @@
               }
           }
           return true;
  +    }
  +
  +    private InputStream createConnectionReleasingInputStream(final
HttpMethodBase method) throws IOException {
  +        return new FilterInputStream(method.getResponseBodyAsStream()) {
  +                public void close() throws IOException {
  +                    try {
  +                        super.close();
  +                    } finally {
  +                        method.releaseConnection();
  +                    }
  +                }
  +            };
       }
   }
   
  
  
  

Re: FW: cvs commit: ws-axis/java/src/org/apache/axis/transport/http C ommonsHTTPSender.java

Posted by Davanum Srinivas <da...@gmail.com>.
u logging in as "eric.d.friedman@wellsfargo.com" right? added u to the
axis-developers group in jira. please try again.

thanks,
dims

On Fri, 28 May 2004 16:29:15 -0700, eric.d.friedman@wellsfargo.com
<er...@wellsfargo.com> wrote:
> 
> Poked around on jira for a bit and didn't see how I'm supposed to mark this
> bug as fixed.  Any pointers?
> 
> -----Original Message-----
> From: ericf@apache.org [mailto:ericf@apache.org]
> Sent: Friday, May 28, 2004 4:23 PM
> To: ws-axis-cvs@apache.org
> Subject: cvs commit: ws-axis/java/src/org/apache/axis/transport/http
> CommonsHTTPSender.java
> 
> ericf       2004/05/28 16:22:42
> 
>   Modified:    java/src/org/apache/axis/transport/http
>                         CommonsHTTPSender.java
>   Log:
>   Fix for AXIS-1369, Deadlock when using HttpClient.
>   Added calls to release the connection back to the pool when a fault is
>   thrown or when the stream with the response in it is closed.
> 
>   Revision  Changes    Path
>   1.24      +27 -8
> ws-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.java
> 
>   Index: CommonsHTTPSender.java
>   ===================================================================
>   RCS file:
> /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.
> java,v
>   retrieving revision 1.23
>   retrieving revision 1.24
>   diff -u -r1.23 -r1.24
>   --- CommonsHTTPSender.java    11 May 2004 13:36:35 -0000      1.23
>   +++ CommonsHTTPSender.java    28 May 2004 23:22:42 -0000      1.24
>   @@ -45,6 +45,9 @@
> 
>    import java.io.ByteArrayInputStream;
>    import java.io.ByteArrayOutputStream;
>   +import java.io.FilterInputStream;
>   +import java.io.InputStream;
>   +import java.io.IOException;
>    import java.net.URL;
>    import java.util.Hashtable;
>    import java.util.Iterator;
>   @@ -196,11 +199,19 @@
>                    + statusMessage, null,
>                    null);
> 
>   -
> fault.setFaultDetailString(Messages.getMessage("return01",
>   -                "" + returnCode, method.getResponseBodyAsString()));
>   -                throw fault;
>   +                try {
>   +
> fault.setFaultDetailString(Messages.getMessage("return01",
>   +                    "" + returnCode, method.getResponseBodyAsString()));
>   +                    throw fault;
>   +                } finally {
>   +                    method.releaseConnection(); // release connection
> back to pool.
>   +                }
>                }
>   -            Message outMsg = new
> Message(method.getResponseBodyAsStream(),
>   +
>   +            // wrap the response body stream so that close() also
> releases the connection back to the pool.
>   +            InputStream releaseConnectionOnCloseStream =
> createConnectionReleasingInputStream(method);
>   +
>   +            Message outMsg = new Message(releaseConnectionOnCloseStream,
>                false, contentType, contentLocation);
>                // Transfer HTTP headers of HTTP message to MIME headers of
> SOAP message
>                Header[] responseHeaders = method.getResponseHeaders();
>   @@ -209,10 +220,6 @@
>                    Header responseHeader = responseHeaders[i];
>                    responseMimeHeaders.addHeader(responseHeader.getName(),
> responseHeader.getValue());
>                }
>   -            // no need to invoke method.releaseConnection here, as that
> will
>   -            // happen automatically when the response body is read.
>   -            // issue: what if the stream is never closed?  Are we certain
>   -            // that InputStream.close() always gets called?
>                outMsg.setMessageType(Message.RESPONSE);
>                msgContext.setResponseMessage(outMsg);
>                if (log.isDebugEnabled()) {
>   @@ -587,6 +594,18 @@
>                }
>            }
>            return true;
>   +    }
>   +
>   +    private InputStream createConnectionReleasingInputStream(final
> HttpMethodBase method) throws IOException {
>   +        return new FilterInputStream(method.getResponseBodyAsStream()) {
>   +                public void close() throws IOException {
>   +                    try {
>   +                        super.close();
>   +                    } finally {
>   +                        method.releaseConnection();
>   +                    }
>   +                }
>   +            };
>        }
>    }
> 
>