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

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 5d7cb4fc21e26347321adcc5d766e455966b88d0
Author: Robert Lazarski <[email protected]>
AuthorDate: Sun Apr 19 18:31:03 2026 -1000

    AXIS2-6103 Fail-fast on non-2xx in streaming start(), thread-safe shutdown
    
    Move status code check into AbstractBinResponseConsumer.start() so
    non-2xx responses abort before writing the error body to the caller's
    OutputStream. Prevents corruption when the server returns HTML error
    pages instead of JSON.
    
    Make shutdown() synchronized and set sharedClient=null after close to
    prevent race with getClient() during concurrent shutdown/startup.
    
    Found by local Gemini Pro review.
---
 .../java/userguide/springboot/client/Http2JsonClient.java  | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git 
a/modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/client/Http2JsonClient.java
 
b/modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/client/Http2JsonClient.java
index 0074f470d4..ec19244c3f 100644
--- 
a/modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/client/Http2JsonClient.java
+++ 
b/modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/client/Http2JsonClient.java
@@ -188,6 +188,10 @@ public class Http2JsonClient {
                                      org.apache.hc.core5.http.ContentType 
contentType)
                         throws org.apache.hc.core5.http.HttpException, 
java.io.IOException {
                     statusCode[0] = response.getCode();
+                    // Fail fast on non-2xx — abort before writing error body 
to the OutputStream
+                    if (statusCode[0] < 200 || statusCode[0] >= 300) {
+                        throw new java.io.IOException("HTTP " + statusCode[0] 
+ " from streaming request");
+                    }
                 }
 
                 @Override
@@ -242,22 +246,20 @@ public class Http2JsonClient {
             throw e;
         }
 
-        if (result < 200 || result >= 300) {
-            throw new java.io.IOException("HTTP " + result + " from streaming 
request");
-        }
-
         return result;
     }
 
     /**
      * Shut down the shared HTTP/2 client. Call once at application exit.
      */
-    public static void shutdown() {
+    public static synchronized void shutdown() {
         if (sharedClient != null) {
             try {
                 sharedClient.close();
             } catch (Exception e) {
-                // ignore
+                System.err.println("Error shutting down HTTP/2 client: " + 
e.getMessage());
+            } finally {
+                sharedClient = null;
             }
         }
     }

Reply via email to