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

jbonofre pushed a commit to branch activemq-6.1.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-6.1.x by this push:
     new 9ca5d0ea7a AMQ-9503: Add wireFormat.displayStackTrace option on the 
HTTP transport connector to display or not the full stack trace to the client 
(#1457)
9ca5d0ea7a is described below

commit 9ca5d0ea7a4e58ea0fe59bd817989fc1c9055a80
Author: JB Onofré <[email protected]>
AuthorDate: Mon Jun 16 19:04:44 2025 +0200

    AMQ-9503: Add wireFormat.displayStackTrace option on the HTTP transport 
connector to display or not the full stack trace to the client (#1457)
    
    (cherry picked from commit 45dfc098534f988c383e56c58c2b2a1761243229)
---
 .../activemq/transport/http/HttpTunnelServlet.java | 70 ++++++++++++----------
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git 
a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
 
b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
index 06f1b8218b..2454c4b2b4 100644
--- 
a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
+++ 
b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
@@ -40,6 +40,7 @@ import org.apache.activemq.transport.util.TextWireFormat;
 import org.apache.activemq.transport.xstream.XStreamWireFormat;
 import org.apache.activemq.util.IOExceptionSupport;
 import org.apache.activemq.util.ServiceListener;
+import org.apache.http.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -122,44 +123,53 @@ public class HttpTunnelServlet extends HttpServlet {
 
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        try {
+            if (wireFormatOptions.get("maxFrameSize") != null && 
request.getContentLength() > 
Integer.parseInt(wireFormatOptions.get("maxFrameSize").toString())) {
+                response.setStatus(405);
+                response.setContentType("plain/text");
+                PrintWriter writer = response.getWriter();
+                writer.println("maxFrameSize exceeded");
+                writer.flush();
+                writer.close();
+                return;
+            }
 
-        if (wireFormatOptions.get("maxFrameSize") != null && 
request.getContentLength() > 
Integer.parseInt(wireFormatOptions.get("maxFrameSize").toString())) {
-            response.setStatus(405);
-            response.setContentType("plain/text");
-            PrintWriter writer = response.getWriter();
-            writer.println("maxFrameSize exceeded");
-            writer.flush();
-            writer.close();
-            return;
-        }
+            InputStream stream = request.getInputStream();
+            String contentType = request.getContentType();
+            if (contentType != null && 
contentType.equals("application/x-gzip")) {
+                stream = new GZIPInputStream(stream);
+            }
 
-        InputStream stream = request.getInputStream();
-        String contentType = request.getContentType();
-        if (contentType != null && contentType.equals("application/x-gzip")) {
-            stream = new GZIPInputStream(stream);
-        }
+            // Read the command directly from the reader, assuming UTF8 
encoding
+            Command command = (Command) wireFormat.unmarshalText(new 
InputStreamReader(stream, "UTF-8"));
 
-        // Read the command directly from the reader, assuming UTF8 encoding
-        Command command = (Command) wireFormat.unmarshalText(new 
InputStreamReader(stream, "UTF-8"));
+            if (command instanceof WireFormatInfo) {
+                WireFormatInfo info = (WireFormatInfo) command;
+                if (!canProcessWireFormatVersion(info.getVersion())) {
+                    response.sendError(HttpServletResponse.SC_NOT_FOUND, 
"Cannot process wire format of version: "
+                            + info.getVersion());
+                }
 
-        if (command instanceof WireFormatInfo) {
-            WireFormatInfo info = (WireFormatInfo) command;
-            if (!canProcessWireFormatVersion(info.getVersion())) {
-                response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot 
process wire format of version: "
-                        + info.getVersion());
-            }
+            } else {
 
-        } else {
+                BlockingQueueTransport transport = 
getTransportChannel(request, response);
+                if (transport == null) {
+                    return;
+                }
 
-            BlockingQueueTransport transport = getTransportChannel(request, 
response);
-            if (transport == null) {
-                return;
+                if (command instanceof ConnectionInfo) {
+                    ((ConnectionInfo) 
command).setTransportContext(request.getAttribute("jakarta.servlet.request.X509Certificate"));
+                }
+                transport.doConsume(command);
             }
-
-            if (command instanceof ConnectionInfo) {
-                ((ConnectionInfo) 
command).setTransportContext(request.getAttribute("jakarta.servlet.request.X509Certificate"));
+        } catch (Exception e) {
+            // no stack trace
+            if (wireFormatOptions.get("sendStackTrace") != null && 
Boolean.parseBoolean(wireFormatOptions.get("sendStackTrace").toString()) == 
false) {
+                LOG.warn(e.getMessage(), e);
+                response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+            } else {
+                throw e;
             }
-            transport.doConsume(command);
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to