I am using Tomcat 7.0.54.0.
There is one REST API in my application using the GET
method. In the URI for this API, there is one slash character (/
) which I am encoding before calling the API. That example: http://192.168.168.168:38080/myApp/getDetails/test%2Fstring
.
The actual string in the URI parameter is test/string
. Before calling the API, I use URLEncoder.encode("test/string", "UTF-8")
, which gives me test%2Fstring
. Same as I used in my URL.
This API call works fine in one environment, but for other environment it gives me an HTTP 400 (Bad request)
error.
The Java version, Tomcat version, OS environment (Linux) and version, they are all the same for both servers. In server.xml
, I configured the connector port like this:
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="38080" protocol="HTTP/1.1" redirectPort="8443"/>
Also, there is a character encoding filter configured with the following code:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest httpRequest = null;
HttpServletResponse httpResponse = null;
if (request instanceof HttpServletRequest)
{
httpRequest = (HttpServletRequest) request;
}
if (response instanceof HttpServletResponse)
{
httpResponse = (HttpServletResponse) response;
}
// it means its not http request
if (httpRequest == null || httpResponse == null)
{
chain.doFilter(request, response);
return;
}
httpRequest.setCharacterEncoding("UTF-8");
httpResponse.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
When I debug, I found that the request is not even reaching this filter. Which means the server itself is restricting that URL.
This API worked fine previously, but recently it started giving this problem. The only difference is that I took a fresh Tomcat of the same version, and configured it in exactly the same way as the existing Tomcat.
Can anyone explain what is happening and how to fix it?