Merge pull request #472 from jbonofre/AMQ-7419

[AMQ-7419] Return 405 error code instead of 500 in case of maxFrameSize exceeded on HTTP connector
This commit is contained in:
Jean-Baptiste Onofré 2020-02-28 07:33:52 +01:00 committed by GitHub
commit 46148e3dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -16,17 +16,14 @@
*/
package org.apache.activemq.transport.http;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import javax.jms.JMSException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -121,7 +118,13 @@ public class HttpTunnelServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (wireFormatOptions.get("maxFrameSize") != null && request.getContentLength() > Integer.parseInt(wireFormatOptions.get("maxFrameSize").toString())) {
throw new ServletException("maxFrameSize exceeded");
response.setStatus(405);
response.setContentType("plain/text");
PrintWriter writer = response.getWriter();
writer.println("maxFrameSize exceeded");
writer.flush();
writer.close();
return;
}
InputStream stream = request.getInputStream();

View File

@ -56,7 +56,7 @@ public class HttpMaxFrameSizeTest {
try {
send(5000);
} catch (JMSException jmsException) {
Assert.assertTrue(jmsException.getMessage().contains("500 Server Error"));
Assert.assertTrue(jmsException.getMessage().contains("405 Method Not Allowed"));
}
}