I've never used Tomcat before, but I've recently inherited a JSP project and now I need to get it running. I've managed to install Tomcat 8.0 locally in Eclipse and everything works fine. I've also installed Tomcat 8.0 on an Ubuntu VPS. The app is running fine, except for a small issue with how it handles URLs.
The client-side application produces URLs with unescaped square and curly brackets in parameters, like this:
GET /saveItems.json?items=[{%22json%22:%22here%22}]
As much as I would like to change the client-side app, I can't. I just need to get this backend running.
My local copy of the application handles this fine. On the server, however, I get this error:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:286)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1504)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1460)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
I've been looking for a setting that might affect this, without any luck. What am I missing here?
I make this workable by editing $CATALINA_HOME\conf\server.xml
Old Value: <Connector ... protocol="HTTP/1.1"... />
New Value: <Connector ... protocol="HTTP/1.1"... relaxedQueryChars='[]|{}^\`"<>' />
I was experiencing a similar problem, but using Spring boot too, the following solution resolved my issue:
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedQueryChars", "|{}[]");
}
});
return factory;
}
Credited to Matthias-lohr - https://stackoverflow.com/questions/46251131/invalid-character-found-in-the-request-target-in-spring-boot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With