You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/01/19 19:42:28 UTC
svn commit: r900897 - in /cxf/branches/2.1.x-fixes: ./
api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java
rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Author: dkulp
Date: Tue Jan 19 18:42:27 2010
New Revision: 900897
URL: http://svn.apache.org/viewvc?rev=900897&view=rev
Log:
Merged revisions 900885 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................
r900885 | dkulp | 2010-01-19 13:21:48 -0500 (Tue, 19 Jan 2010) | 10 lines
Merged revisions 900876 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r900876 | dkulp | 2010-01-19 13:14:17 -0500 (Tue, 19 Jan 2010) | 2 lines
[CXF-2619] Make sure we cache incoming content on first write or we
could hit a deadlock
........
................
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java
cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java?rev=900897&r1=900896&r2=900897&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java (original)
+++ cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java Tue Jan 19 18:42:27 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/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=900897&r1=900896&r2=900897&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
+++ cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Tue Jan 19 18:42:27 2010
@@ -43,6 +43,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;
@@ -53,6 +54,7 @@
import org.apache.cxf.helpers.HttpHeaderHelper;
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;
@@ -441,7 +443,40 @@
}
+ /**
+ * 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<Attachment> 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 {
+
+ cacheInput(outMessage);
+
updateResponseHeaders(outMessage);
Object responseObj = outMessage.get(HTTP_RESPONSE);
OutputStream responseStream = null;