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 29bd5a4d9fcaaefb9cad6b0e94b287d0520adfd1
Author: Robert Lazarski <[email protected]>
AuthorDate: Sun Apr 19 18:24:55 2026 -1000

    AXIS2-6103 Remove SimpleHttpResponse buffering, unify on streaming path
    
    execute() now delegates to executeStreaming() with a ByteArrayOutputStream
    instead of using SimpleHttpRequest/SimpleHttpResponse. This avoids the
    internal buffering overhead of SimpleHttpResponse and ensures both methods
    use the same streaming transport (AbstractBinResponseConsumer with 64KB
    HTTP/2 flow control).
    
    Also fixes: null body NPE in error path, adds non-2xx status check to
    executeStreaming() for consistent error handling contract.
    
    Removes unused Simple* imports.
    
    Found by local Gemini Pro review + code consistency check.
---
 .../springboot/client/Http2JsonClient.java         | 48 ++++++----------------
 1 file changed, 12 insertions(+), 36 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 7a91dc9fdf..0074f470d4 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
@@ -25,9 +25,6 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
-import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
-import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
 import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
 import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
 import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
@@ -131,6 +128,11 @@ public class Http2JsonClient {
     /**
      * POST JSON to an Axis2 service and return the response as a String.
      *
+     * <p>Uses the same streaming transport as {@link #executeStreaming},
+     * writing to a {@code ByteArrayOutputStream} and converting to String.
+     * This avoids {@code SimpleHttpResponse}'s internal buffering overhead
+     * while maintaining a simple String return type.</p>
+     *
      * @param url            HTTPS endpoint (e.g., {@code 
https://host:8443/axis2-json-api/services/MyService})
      * @param json           JSON-RPC request body
      * @param timeoutSeconds maximum wait time for the response
@@ -138,39 +140,9 @@ public class Http2JsonClient {
      * @throws Exception on HTTP error or timeout
      */
     public static String execute(String url, String json, int timeoutSeconds) 
throws Exception {
-        CloseableHttpAsyncClient client = getClient();
-
-        SimpleHttpRequest request = SimpleRequestBuilder.post(url)
-            .setBody(json, ContentType.APPLICATION_JSON)
-            .setHeader("Accept", "application/json")
-            .build();
-
-        CompletableFuture<SimpleHttpResponse> future = new 
CompletableFuture<>();
-        Future<SimpleHttpResponse> requestFuture = client.execute(request,
-            new FutureCallback<SimpleHttpResponse>() {
-                @Override public void completed(SimpleHttpResponse r) { 
future.complete(r); }
-                @Override public void failed(Exception ex) { 
future.completeExceptionally(ex); }
-                @Override public void cancelled() { future.cancel(true); }
-            });
-
-        SimpleHttpResponse response;
-        try {
-            response = future.get(timeoutSeconds, TimeUnit.SECONDS);
-        } catch (Exception e) {
-            requestFuture.cancel(true);
-            if (e instanceof InterruptedException) {
-                Thread.currentThread().interrupt();
-            }
-            throw e;
-        }
-
-        int status = response.getCode();
-        if (status < 200 || status >= 300) {
-            throw new java.io.IOException("HTTP " + status + ": "
-                + response.getBodyText().substring(0, Math.min(500,
-                    response.getBodyText() != null ? 
response.getBodyText().length() : 0)));
-        }
-        return response.getBodyText();
+        java.io.ByteArrayOutputStream baos = new 
java.io.ByteArrayOutputStream();
+        executeStreaming(url, json, timeoutSeconds, baos);
+        return baos.toString(StandardCharsets.UTF_8.name());
     }
 
     /**
@@ -270,6 +242,10 @@ public class Http2JsonClient {
             throw e;
         }
 
+        if (result < 200 || result >= 300) {
+            throw new java.io.IOException("HTTP " + result + " from streaming 
request");
+        }
+
         return result;
     }
 

Reply via email to