when spring boot startup,throw out the "method names must be tokens" exception

JavaSpring

Java Problem Overview


When spring boot startup,throw out 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

Who know why throw out Invalid character found in method name. HTTP method names must be tokens exception.

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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.

Solution 3 - Java

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;

Solution 4 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondiscipline19810128View Question on Stackoverflow
Solution 1 - JavaPanchito91View Answer on Stackoverflow
Solution 2 - Javarwenz3lView Answer on Stackoverflow
Solution 3 - JavaNight WhiteView Answer on Stackoverflow
Solution 4 - JavaДмитрий ВорогушинView Answer on Stackoverflow