Search code examples
javatomcattomcat8

How to fix tomcat org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character [[] is not allowed and will continue to be rejected


There are characters [ and ] in my request URL, and project deployed on Tomcat8.5.33. Some exception happens when I post request.

20-Sep-2018 10:55:36.494 WARNING [http-nio-8075-exec-2] org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character [[] is not allowed and will continue to be rejected.
20-Sep-2018 10:55:36.494 WARNING [http-nio-8075-exec-2] org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character []] is not allowed and will continue to be rejected.
20-Sep-2018 10:56:07.083 INFO [http-nio-8075-exec-10] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
 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.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:479)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:684)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    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)

Solution

  • Tomcat8.5.33 doesn't allow special character in URL, like |{}[]. And there are two methods to avoid this error.

    If your special character is one of |{}, you could add config conf\catalina.properties like below directly:

    tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
    

    If your special character are some others, you could config conf\server.xml like below:

    <Connector port="8075" protocol="HTTP/1.1" relaxedQueryChars='|[]'
                   connectionTimeout="20000"
                   redirectPort="8443" />