cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r897053 - in /cxf/trunk: api/src/main/java/org/apache/cxf/io/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/
Date Thu, 07 Jan 2010 23:31:39 GMT
Author: dkulp
Date: Thu Jan  7 23:31:38 2010
New Revision: 897053

URL: http://svn.apache.org/viewvc?rev=897053&view=rev
Log:
[CXF-2545] When pushing a message onto a background thread, we need to
suck in all the data from the input stream and cache it as the transport
may close the original stream when the current stack unwinds.

Added:
    cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java   (with props)
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java

Added: 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=897053&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java (added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java Thu Jan  7 23:31:38
2010
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.io;
+
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cxf.helpers.IOUtils;
+
+public class DelegatingInputStream extends FilterInputStream {
+    private InputStream origIn;
+    
+    public DelegatingInputStream(InputStream is) {
+        super(is);
+        origIn = is;
+    }
+
+
+    public void setInputStream(InputStream inputStream) {
+        in = inputStream;
+    }
+    public InputStream getInputStream() {
+        return in;
+    }
+    
+
+    public void close() throws IOException {
+        super.close();
+        if (in != origIn) {
+            origIn.close();
+        }
+    }
+    
+    /**
+     * Read the entire original input stream and cache it.  Useful
+     * if switching threads or doing something where the original
+     * 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
+        }
+    }
+    
+}
\ No newline at end of file

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/io/DelegatingInputStream.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java?rev=897053&r1=897052&r2=897053&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
Thu Jan  7 23:31:38 2010
@@ -25,6 +25,7 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.io.DelegatingInputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -59,6 +60,25 @@
             
             message.put(OneWayProcessorInterceptor.class, this);
             final InterceptorChain chain = message.getInterceptorChain();
+
+            Object o = message.getContextualProperty(USE_ORIGINAL_THREAD);
+            if (o == null) {
+                o = Boolean.FALSE;
+            } else if (o instanceof String) {
+                o = Boolean.valueOf((String)o);
+            }
+
+            
+            if (Boolean.FALSE.equals(o)) {
+                //need to suck in all the data from the input stream as
+                //the transport might discard any data on the stream when this 
+                //thread unwinds or when the empty response is sent back
+                DelegatingInputStream in = message.get(DelegatingInputStream.class);
+                if (in != null) {
+                    in.cacheInput();
+                }
+            }
+
             
             try {
                 Message partial = createMessage(message.getExchange());
@@ -71,12 +91,6 @@
                 //IGNORE
             }
             
-            Object o = message.getContextualProperty(USE_ORIGINAL_THREAD);
-            if (o == null) {
-                o = Boolean.FALSE;
-            } else if (o instanceof String) {
-                o = Boolean.valueOf((String)o);
-            }
             if (Boolean.FALSE.equals(o)) {
                 chain.pause();
                 try {

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=897053&r1=897052&r2=897053&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
Thu Jan  7 23:31:38 2010
@@ -54,6 +54,7 @@
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.io.AbstractWrappedOutputStream;
+import org.apache.cxf.io.DelegatingInputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.security.SecurityContext;
@@ -265,7 +266,9 @@
                                 final HttpServletRequest req, 
                                 final HttpServletResponse resp) throws IOException {
 
-        inMessage.setContent(InputStream.class, req.getInputStream());
+        DelegatingInputStream in = new DelegatingInputStream(req.getInputStream());
+        inMessage.setContent(DelegatingInputStream.class, in);
+        inMessage.setContent(InputStream.class, in);
         inMessage.put(HTTP_REQUEST, req);
         inMessage.put(HTTP_RESPONSE, resp);
         inMessage.put(HTTP_CONTEXT, context);

Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java?rev=897053&r1=897052&r2=897053&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java (original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java Thu
Jan  7 23:31:38 2010
@@ -41,6 +41,7 @@
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.interceptor.OutgoingChainInterceptor;
+import org.apache.cxf.io.DelegatingInputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -397,6 +398,14 @@
                     }
                     
                     if (retrieveAsyncPostResponseDispatch(inMessage)) {
+                        //need to suck in all the data from the input stream as
+                        //the transport might discard any data on the stream when this 
+                        //thread unwinds or when the empty response is sent back
+                        DelegatingInputStream in = inMessage.get(DelegatingInputStream.class);
+                        if (in != null) {
+                            in.cacheInput();
+                        }
+                        
                         // async service invocation required *after* a response
                         // has been sent (i.e. to a oneway, or a partial response
                         // to a decoupled twoway)



Mime
View raw message