Skip to content

Commit 9ca5d0e

Browse files
committed
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 45dfc09)
1 parent c3c0d69 commit 9ca5d0e

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.activemq.transport.xstream.XStreamWireFormat;
4141
import org.apache.activemq.util.IOExceptionSupport;
4242
import org.apache.activemq.util.ServiceListener;
43+
import org.apache.http.HttpStatus;
4344
import org.slf4j.Logger;
4445
import org.slf4j.LoggerFactory;
4546

@@ -122,44 +123,53 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
122123

123124
@Override
124125
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
126+
try {
127+
if (wireFormatOptions.get("maxFrameSize") != null && request.getContentLength() > Integer.parseInt(wireFormatOptions.get("maxFrameSize").toString())) {
128+
response.setStatus(405);
129+
response.setContentType("plain/text");
130+
PrintWriter writer = response.getWriter();
131+
writer.println("maxFrameSize exceeded");
132+
writer.flush();
133+
writer.close();
134+
return;
135+
}
125136

126-
if (wireFormatOptions.get("maxFrameSize") != null && request.getContentLength() > Integer.parseInt(wireFormatOptions.get("maxFrameSize").toString())) {
127-
response.setStatus(405);
128-
response.setContentType("plain/text");
129-
PrintWriter writer = response.getWriter();
130-
writer.println("maxFrameSize exceeded");
131-
writer.flush();
132-
writer.close();
133-
return;
134-
}
137+
InputStream stream = request.getInputStream();
138+
String contentType = request.getContentType();
139+
if (contentType != null && contentType.equals("application/x-gzip")) {
140+
stream = new GZIPInputStream(stream);
141+
}
135142

136-
InputStream stream = request.getInputStream();
137-
String contentType = request.getContentType();
138-
if (contentType != null && contentType.equals("application/x-gzip")) {
139-
stream = new GZIPInputStream(stream);
140-
}
143+
// Read the command directly from the reader, assuming UTF8 encoding
144+
Command command = (Command) wireFormat.unmarshalText(new InputStreamReader(stream, "UTF-8"));
141145

142-
// Read the command directly from the reader, assuming UTF8 encoding
143-
Command command = (Command) wireFormat.unmarshalText(new InputStreamReader(stream, "UTF-8"));
146+
if (command instanceof WireFormatInfo) {
147+
WireFormatInfo info = (WireFormatInfo) command;
148+
if (!canProcessWireFormatVersion(info.getVersion())) {
149+
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot process wire format of version: "
150+
+ info.getVersion());
151+
}
144152

145-
if (command instanceof WireFormatInfo) {
146-
WireFormatInfo info = (WireFormatInfo) command;
147-
if (!canProcessWireFormatVersion(info.getVersion())) {
148-
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot process wire format of version: "
149-
+ info.getVersion());
150-
}
153+
} else {
151154

152-
} else {
155+
BlockingQueueTransport transport = getTransportChannel(request, response);
156+
if (transport == null) {
157+
return;
158+
}
153159

154-
BlockingQueueTransport transport = getTransportChannel(request, response);
155-
if (transport == null) {
156-
return;
160+
if (command instanceof ConnectionInfo) {
161+
((ConnectionInfo) command).setTransportContext(request.getAttribute("jakarta.servlet.request.X509Certificate"));
162+
}
163+
transport.doConsume(command);
157164
}
158-
159-
if (command instanceof ConnectionInfo) {
160-
((ConnectionInfo) command).setTransportContext(request.getAttribute("jakarta.servlet.request.X509Certificate"));
165+
} catch (Exception e) {
166+
// no stack trace
167+
if (wireFormatOptions.get("sendStackTrace") != null && Boolean.parseBoolean(wireFormatOptions.get("sendStackTrace").toString()) == false) {
168+
LOG.warn(e.getMessage(), e);
169+
response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR);
170+
} else {
171+
throw e;
161172
}
162-
transport.doConsume(command);
163173
}
164174
}
165175

0 commit comments

Comments
 (0)