74

When Spring Boot starts up, it throws the method names must be tokens exception

2016-08-11 16:53:54.499  INFO 14212 --- [0.1-8888-exec-1] o.apache.coyote.http11.Http11Processor   : 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 method name. HTTP method names must be tokens
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:462) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_72]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_72]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72]

2016-08-11 16:53:58.885  INFO 14212 --- [0.1-8888-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-08-11 16:53:58.888  INFO 14212 --- [0.1-8888-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-08-11 16:53:58.922  INFO 14212 --- [0.1-8888-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 30 ms
11111111-chinadfadf-xxxxxxxx@121.com

Anyone knows why it throws this exception?

informatik01
  • 16,038
  • 10
  • 74
  • 104
discipline19810128
  • 741
  • 1
  • 5
  • 5

5 Answers5

129

This exception can occur when you try to execute https request from client on endpoint which isn't https enabled. Client will encrypt request data when server is expecting raw data.

Change https:// to http:// in your client url.

Panchito91
  • 1,680
  • 3
  • 13
  • 19
  • 3
    Any idea how to (redirect https to http || disable https || catch the error to at least show a meaningful error message)? – crusy May 12 '17 at 07:04
  • I've just stumbled across this issue. It is indeed an issue in tomcat that reflects on an unsupported SSL request, trying to be processed as-is, and of course failing (everything is read as garbled text, unparseable). I only think Tomcat should be able to detect and handle a little more gracefully? I'll open an issue later :D – RickB Sep 01 '22 at 10:26
8

Another Case: SpringBoot and Tomcat use port 8080 or 8888 by default. I had a Jupyter Notebook running at the same time which has a token in it's url path and some random characters. Anyway: The Notebook was still trying to make requests when the jupyter notebook server was down.

If you encounter this error: Check if you have another Application running that is either spawning a webserver or talking to a webserver on such ports.

rwenz3l
  • 237
  • 5
  • 10
  • 20
    When downvoting an answer it would be helpful to explain why you did so. It would help me and others to understand the problem. – rwenz3l Mar 27 '18 at 09:12
4

The same problem.

cmd -> netstat -ano then find the port your have used(e.g 8888)

I find a process try send package not Http request to my 8888 port, so the tomcat throw the method names must be tokens Exception.

you can:

  • change server port;

  • find the process and kill it;

Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38
3

In my case it was when Tomcat created HTTPS request without SSL certificate installed on it. To fix it I changed schema in request to HTTP. Or you should create SSL certificate to use HTTPS.

2

you must have added https intead of http i also was getting same error with given below code

@RestController
public class MyController {
    @GetMapping("/myobject")
    public MyObject getMyObject() {
        return new MyObject("John Doe", true, 42);
    }
}

This is what i got with https enter image description here

Also Error in IDE with stack trace

2023-03-22T03:32:56.767+05:30  INFO 21684 --- [nio-8080-exec-2] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x030x950xa2*tU0x050x1a0xe20xf5]0x1c0x8f0x070x160x0b9q10xa9d0x800xc50xdau0xfd0x8d*0xe00xec0xe80xd3C ]. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:419) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:272) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
    at java.base/java.lang.Thread.run(Thread.java:1589) ~[na:na]

and This is what i got with http only enter image description here