|
40 | 40 | import org.apache.activemq.transport.xstream.XStreamWireFormat; |
41 | 41 | import org.apache.activemq.util.IOExceptionSupport; |
42 | 42 | import org.apache.activemq.util.ServiceListener; |
| 43 | +import org.apache.http.HttpStatus; |
43 | 44 | import org.slf4j.Logger; |
44 | 45 | import org.slf4j.LoggerFactory; |
45 | 46 |
|
@@ -122,44 +123,53 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t |
122 | 123 |
|
123 | 124 | @Override |
124 | 125 | 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 | + } |
125 | 136 |
|
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 | + } |
135 | 142 |
|
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")); |
141 | 145 |
|
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 | + } |
144 | 152 |
|
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 { |
151 | 154 |
|
152 | | - } else { |
| 155 | + BlockingQueueTransport transport = getTransportChannel(request, response); |
| 156 | + if (transport == null) { |
| 157 | + return; |
| 158 | + } |
153 | 159 |
|
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); |
157 | 164 | } |
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; |
161 | 172 | } |
162 | | - transport.doConsume(command); |
163 | 173 | } |
164 | 174 | } |
165 | 175 |
|
|
0 commit comments