You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2026/10/15 14:57:22 UTC

(cxf) branch main updated: CXF-8272: Don't fail a one-way invocation if the response stream can't be drained (#3586)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e16926ff8b CXF-8272: Don't fail a one-way invocation if the response stream can't be drained (#3586)
2e16926ff8b is described below

commit 2e16926ff8b76389261e0d754ab20a4de7a3b225
Author: Colm O hEigeartaigh <co...@users.noreply.github.com>
AuthorDate: Thu Oct 15 15:57:16 2026 +0100

    CXF-8272: Don't fail a one-way invocation if the response stream can't be drained (#3586)
---
 .../transport/http/URLConnectionHTTPConduit.java   |  8 +++++-
 .../transport/http/HTTPConduitURLEasyMockTest.java | 32 ++++++++++++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
index 028eaf950f4..33b952cc155 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
@@ -357,7 +357,13 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
                 ins = connection.getInputStream();
             }
             if (ins != null) {
-                IOUtils.consume(ins);
+                try {
+                    IOUtils.consume(ins);
+                } catch (IOException ex) {
+                    // Draining is only done so the connection might be reused, so a failure here
+                    // (for example the stream was already closed) should not fail the invocation
+                    LOG.log(Level.FINE, "Could not consume the response stream: " + ex.getMessage(), ex);
+                }
                 ins.close();
             }
         }
diff --git a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
index 3850ce338be..40adb2d10c4 100644
--- a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
+++ b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
@@ -64,6 +64,7 @@ import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 /**
@@ -73,7 +74,9 @@ public class HTTPConduitURLEasyMockTest {
 
     private static final String HTTP_RESPONSE_MESSAGE = "Some Response Message I can test";
     
-    private enum ResponseStyle { NONE, BACK_CHANNEL, BACK_CHANNEL_ERROR, DECOUPLED, ONEWAY_NONE };
+    private enum ResponseStyle {
+        NONE, BACK_CHANNEL, BACK_CHANNEL_ERROR, DECOUPLED, ONEWAY_NONE, ONEWAY_STREAM_CLOSED
+    };
     private enum ResponseDelimiter { LENGTH, CHUNKED, EOF };
 
     private static final String NOWHERE = "http://nada.nothing.nowhere.null/";
@@ -259,6 +262,21 @@ public class HTTPConduitURLEasyMockTest {
                           "POST");
     }
 
+    @Test
+    public void testSendOnewayResponseStreamAlreadyClosed()
+        throws Exception {
+        HTTPConduit conduit = setUpConduit(true, false, "POST");
+        Message message = createMessage();
+        conduit.prepare(message);
+        verifySentMessage(conduit,
+                          message,
+                          ResponseStyle.ONEWAY_STREAM_CLOSED,
+                          ResponseDelimiter.CHUNKED,
+                          true,  // empty response
+                          "POST");
+        verify(is).close();
+    }
+
     @Test
     public void testSendTwowayDecoupledEmptyPartialResponse()
         throws Exception {
@@ -443,7 +461,8 @@ public class HTTPConduitURLEasyMockTest {
             doNothing().when(os).close();
         }
 
-        setUpExchange(message, style == ResponseStyle.NONE || style == ResponseStyle.ONEWAY_NONE);
+        setUpExchange(message, style == ResponseStyle.NONE || style == ResponseStyle.ONEWAY_NONE
+            || style == ResponseStyle.ONEWAY_STREAM_CLOSED);
 
         when(connection.getRequestMethod()).thenReturn(method);
         verifyHandleResponse(style, delimiter, emptyResponse, conduit);
@@ -568,6 +587,15 @@ public class HTTPConduitURLEasyMockTest {
             when(connection.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[0]));
             break;
 
+        case ONEWAY_STREAM_CLOSED:
+            is = mock(InputStream.class);
+            when(connection.getInputStream()).thenReturn(is);
+            when(connection.getContentLength()).thenReturn(-1);
+            when(connection.getHeaderField("Transfer-Encoding")).thenReturn("chunked");
+            when(is.read()).thenReturn(-1);
+            when(is.available()).thenThrow(new IOException("stream is closed"));
+            break;
+
         default:
             break;
         }