Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 83032 invoked from network); 19 Jan 2010 18:14:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Jan 2010 18:14:41 -0000 Received: (qmail 70512 invoked by uid 500); 19 Jan 2010 18:14:41 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 70447 invoked by uid 500); 19 Jan 2010 18:14:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 70438 invoked by uid 99); 19 Jan 2010 18:14:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2010 18:14:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2010 18:14:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F2E6123889E0; Tue, 19 Jan 2010 18:14:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r900876 - in /cxf/trunk: api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Date: Tue, 19 Jan 2010 18:14:17 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100119181417.F2E6123889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Jan 19 18:14:17 2010 New Revision: 900876 URL: http://svn.apache.org/viewvc?rev=900876&view=rev Log: [CXF-2619] Make sure we cache incoming content on first write or we could hit a deadlock Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java?rev=900876&r1=900875&r2=900876&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java Tue Jan 19 18:14:17 2010 @@ -55,12 +55,15 @@ * stream may not be valid by the time the next read() occurs */ public void cacheInput() { - CachedOutputStream cache = new CachedOutputStream(); - try { - IOUtils.copy(in, cache); - in = cache.getInputStream(); - } catch (IOException e) { - //ignore + if (in != origIn) { + CachedOutputStream cache = new CachedOutputStream(); + try { + IOUtils.copy(in, cache); + in = cache.getInputStream(); + cache.close(); + } catch (IOException e) { + //ignore + } } } Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=900876&r1=900875&r2=900876&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Tue Jan 19 18:14:17 2010 @@ -28,6 +28,7 @@ import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -44,6 +45,7 @@ import javax.xml.namespace.QName; import org.apache.cxf.Bus; +import org.apache.cxf.attachment.AttachmentDataSource; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.Base64Exception; import org.apache.cxf.common.util.Base64Utility; @@ -52,9 +54,11 @@ import org.apache.cxf.configuration.security.AuthorizationPolicy; import org.apache.cxf.helpers.CastUtils; import org.apache.cxf.helpers.HttpHeaderHelper; +import org.apache.cxf.interceptor.Fault; import org.apache.cxf.interceptor.Interceptor; import org.apache.cxf.io.AbstractWrappedOutputStream; import org.apache.cxf.io.DelegatingInputStream; +import org.apache.cxf.message.Attachment; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; import org.apache.cxf.security.SecurityContext; @@ -450,10 +454,43 @@ } + /** + * On first write, we need to make sure any attachments and such that are still on the incoming stream + * are read in. Otherwise we can get into a deadlock where the client is still trying to send the + * request, but the server is trying to send the response. Neither side is reading and both blocked + * on full buffers. Not a good situation. + * @param outMessage + */ + private void cacheInput(Message outMessage) { + Message inMessage = outMessage.getExchange().getInMessage(); + if (inMessage == null) { + return; + } + Collection atts = inMessage.getAttachments(); + if (atts != null) { + for (Attachment a : atts) { + if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { + try { + ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(); + } catch (IOException e) { + throw new Fault(e); + } + } + } + } + DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class); + if (in != null) { + in.cacheInput(); + } + } + protected OutputStream flushHeaders(Message outMessage) throws IOException { if (isResponseRedirected(outMessage)) { return null; } + + cacheInput(outMessage); + updateResponseHeaders(outMessage); Object responseObj = outMessage.get(HTTP_RESPONSE); OutputStream responseStream = null;