问题背景

关于SpringBoot应用挂了很久之后,会发生Invalid character found in method name. HTTP method names must be tokens的问题。


java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokensat org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:426) ~[tomcat-embed-core-8.5.29.jar:8.5.29]at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) ~[tomcat-embed-core-8.5.29.jar:8.5.29]at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.29.jar:8.5.29]at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.29.jar:8.5.29]at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.29.jar:8.5.29]at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.29.jar:8.5.29]at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [na:na]at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [na:na]at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.29.jar:8.5.29]at java.base/java.lang.Thread.run(Thread.java:844) [na:na]

网上方案

据说是tomcat 的设置问题,如果出现相关情况,可以设置一下application.yml文件的tomcat下的max-http-header-size即可。

server:port: 5555servlet:context-path: /xxxxtomcat:remote-ip-header: x-forward-foruri-encoding: UTF-8max-threads: 1000max-http-header-size: 8096

实际情况

发现是正常的http请求,发送为https请求。
例如正常路径为http://localhost:8080/xxxx,现在变成请求https://localhost:8080/xxxx就会报错。(似乎跟项目没有什么关系).

猜测

可能是tomcat8.5的keepalive有关,检测自己http协议的时候顺便检测了自己的https协议,有很多人遇到半夜报错或者隔了一段时间报错,目前这个bug没搜索到很多定论,可以尝试加tomcatconnection-timeout

parseRequestLine

报错的地方代码如下

org.apache.coyote.http11.Http11InputBuffer.parseRequestLine

    /*** Read the request line. This function is meant to be used during the* HTTP request header parsing. Do NOT attempt to read the request body* using it.** @throws IOException If an exception occurs during the underlying socket* read operations, or if the given buffer is not big enough to accommodate* the whole line.* @return true if data is properly fed; false if no data is available* immediately and thread should be freed*/boolean parseRequestLine(boolean keptAlive) throws IOException {// check stateif (!parsingRequestLine) {return true;}//// Skipping blank lines//if (parsingRequestLinePhase < 2) {byte chr = 0;do {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (keptAlive) {// Haven't read any request data yet so use the keep-alive// timeout.wrapper.setReadTimeout(wrapper.getEndpoint().getKeepAliveTimeout());}if (!fill(false)) {// A read is pending, so no longer in initial stateparsingRequestLinePhase = 1;return false;}// At least one byte of the request has been received.// Switch to the socket timeout.wrapper.setReadTimeout(wrapper.getEndpoint().getConnectionTimeout());}if (!keptAlive && byteBuffer.position() == 0 && byteBuffer.limit() >= CLIENT_PREFACE_START.length - 1) {boolean prefaceMatch = true;for (int i = 0; i < CLIENT_PREFACE_START.length && prefaceMatch; i++) {if (CLIENT_PREFACE_START[i] != byteBuffer.get(i)) {prefaceMatch = false;}}if (prefaceMatch) {// HTTP/2 preface matchedparsingRequestLinePhase = -1;return false;}}// Set the start time once we start reading data (even if it is// just skipping blank lines)if (request.getStartTime() < 0) {request.setStartTime(System.currentTimeMillis());}chr = byteBuffer.get();} while ((chr == Constants.CR) || (chr == Constants.LF));byteBuffer.position(byteBuffer.position() - 1);parsingRequestLineStart = byteBuffer.position();parsingRequestLinePhase = 2;if (log.isDebugEnabled()) {log.debug("Received [" + new String(byteBuffer.array(), byteBuffer.position(), byteBuffer.remaining(),StandardCharsets.ISO_8859_1) + "]");}}if (parsingRequestLinePhase == 2) {//// Reading the method name// Method name is a token//boolean space = false;while (!space) {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (!fill(false)) // request line parsingreturn false;}// Spec says method name is a token followed by a single SP but// also be tolerant of multiple SP and/or HT.int pos = byteBuffer.position();byte chr = byteBuffer.get();if (chr == Constants.SP || chr == Constants.HT) {space = true;request.method().setBytes(byteBuffer.array(), parsingRequestLineStart,pos - parsingRequestLineStart);} else if (!HttpParser.isToken(chr)) {byteBuffer.position(byteBuffer.position() - 1);throw new IllegalArgumentException(sm.getString("iib.invalidmethod"));}}parsingRequestLinePhase = 3;}if (parsingRequestLinePhase == 3) {// Spec says single SP but also be tolerant of multiple SP and/or HTboolean space = true;while (space) {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (!fill(false)) // request line parsingreturn false;}byte chr = byteBuffer.get();if (!(chr == Constants.SP || chr == Constants.HT)) {space = false;byteBuffer.position(byteBuffer.position() - 1);}}parsingRequestLineStart = byteBuffer.position();parsingRequestLinePhase = 4;}if (parsingRequestLinePhase == 4) {// Mark the current buffer positionint end = 0;//// Reading the URI//boolean space = false;while (!space) {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (!fill(false)) // request line parsingreturn false;}int pos = byteBuffer.position();byte chr = byteBuffer.get();if (chr == Constants.SP || chr == Constants.HT) {space = true;end = pos;} else if (chr == Constants.CR || chr == Constants.LF) {// HTTP/0.9 style requestparsingRequestLineEol = true;space = true;end = pos;} else if (chr == Constants.QUESTION && parsingRequestLineQPos == -1) {parsingRequestLineQPos = pos;} else if (HttpParser.isNotRequestTarget(chr)) {throw new IllegalArgumentException(sm.getString("iib.invalidRequestTarget"));}}if (parsingRequestLineQPos >= 0) {request.queryString().setBytes(byteBuffer.array(), parsingRequestLineQPos + 1,end - parsingRequestLineQPos - 1);request.requestURI().setBytes(byteBuffer.array(), parsingRequestLineStart,parsingRequestLineQPos - parsingRequestLineStart);} else {request.requestURI().setBytes(byteBuffer.array(), parsingRequestLineStart,end - parsingRequestLineStart);}parsingRequestLinePhase = 5;}if (parsingRequestLinePhase == 5) {// Spec says single SP but also be tolerant of multiple and/or HTboolean space = true;while (space) {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (!fill(false)) // request line parsingreturn false;}byte chr = byteBuffer.get();if (!(chr == Constants.SP || chr == Constants.HT)) {space = false;byteBuffer.position(byteBuffer.position() - 1);}}parsingRequestLineStart = byteBuffer.position();parsingRequestLinePhase = 6;// Mark the current buffer positionend = 0;}if (parsingRequestLinePhase == 6) {//// Reading the protocol// Protocol is always "HTTP/" DIGIT "." DIGIT//while (!parsingRequestLineEol) {// Read new bytes if neededif (byteBuffer.position() >= byteBuffer.limit()) {if (!fill(false)) // request line parsingreturn false;}int pos = byteBuffer.position();byte chr = byteBuffer.get();if (chr == Constants.CR) {end = pos;} else if (chr == Constants.LF) {if (end == 0) {end = pos;}parsingRequestLineEol = true;} else if (!HttpParser.isHttpProtocol(chr)) {throw new IllegalArgumentException(sm.getString("iib.invalidHttpProtocol"));}}if ((end - parsingRequestLineStart) > 0) {request.protocol().setBytes(byteBuffer.array(), parsingRequestLineStart, end - parsingRequestLineStart);} else {request.protocol().setString("");}parsingRequestLine = false;parsingRequestLinePhase = 0;parsingRequestLineEol = false;parsingRequestLineStart = 0;return true;}throw new IllegalStateException("Invalid request line parse phase:" + parsingRequestLinePhase);}

SpringBoot:Invalid character found in method name. HTTP method names must be tokens相关推荐

  1. 实测解决:SpringBoot 中 Invalid character found in the request target 异常

    实测解决:SpringBoot 中 Invalid character found in the request target 异常 ​ 原因: SpringBoot 2.0.0 以上都采用内置tom ...

  2. tomcat配置SSL报错解决:java.lang.IllegalArgumentException: Invalid character (CR or LF) found in method nam

    使用CAS单点登陆时,在tomcat的server.xml中配置了https协议的证书认证,但访问时报错: INFO [http-nio-8443-exec-4] org.apache.coyote. ...

  3. Ajax请求SSM后台时提示:Invalid character found in the request target. The valid characters are defined in RF

    场景 前端使用SSM请求后台时提示: Invalid character found in the request target. The valid characters are defined i ...

  4. 成功解决Error:invalid character in identifier

    成功解决Error:invalid character in identifier 目录 解决问题 解决思路 解决方法 解决问题 解决思路 错误:标识符中的字符无效 解决方法 将单引号改为双引号即可! ...

  5. 解决LaTeX:!Package CJK Error:Invalid character code报错

    近期运行一个中文的latex模板总是报错,提示:!Package CJK Error:Invalid character code 我的latex编译套件是: WinEdit + MiKTeX 尝试了 ...

  6. Invalid character (CR or LF) found in method name

    今天给服务器传了个http head,刚开始我手动输入是ok的,后来直接从接口文档(.doc)里粘贴过去,发现获取不到数据了,服务器的报错日志显示 11-Apr-2019 11:29:59.184 I ...

  7. 绝对好用,解决:Invalid character found in the request target. The valid characters are defined。。。

    项目场景: 项目运行中出现的问题 Invalid character found in the request target. The valid characters are defined in ...

  8. golang读取mongodb数据出错:invalid character ‘Ì‘ looking for beginning of value

    今天操作golang读取mongodb数据出错:invalid character 'Ì' looking for beginning of value,一头雾水,于是把条件放入mongo的控制平台执 ...

  9. 解决:Invalid character found in method name. HTTP method names must be tokens

    养成的一个好习惯是,每天早上到公司后都会查看项目日志,看看有无异常数据信息等,今天忽然发现日志中抛了个这个错误(此服务器上安装的是Tomcat8): 06-Jul-2018 03:10:34.029 ...

最新文章

  1. Iptables防火墙详细介绍与实战增强服务器安全
  2. 对DataSet,DataRow,DateTable转换成相应的模型
  3. python 颤音_自成一派,这个作曲大师确实名副其实!
  4. Asp.Net站点整合Discuz论坛实现同步注册和单点登录
  5. 挨踢脱口秀精选集汇总
  6. Apache Camel 3 –骆驼核心vs骆驼核心引擎(较小的核心)
  7. docker如何部署python项目_Docker如何部署Python项目的实现详解
  8. ArcGIS客户端开发学习笔记(二)——XML
  9. 前端工程打开速度优化的循序渐进总结
  10. python界面-Python GUI 编程(Tkinter)
  11. SqlServer修改sa的密码
  12. BERT-BiLSTM-CRF命名实体识别应用
  13. muddleftpd配置和用法
  14. matlab查表svpwm,SVPWM的查表生成方式代码
  15. 思科cisco模拟器路由器的基础配置
  16. java抖音字符视频_代码生成抖音文字视频
  17. Python做一个藏头诗生成器
  18. python中match方法中r什么意思_什么是pythonre.match函数?(实例解析)
  19. UDP通信,看我如何一步一步攻克面试官
  20. 了解TypeScript装饰器

热门文章

  1. Cowboy 2.6 User Guide 中英文对照版【翻译】
  2. 可以自动下载字幕的播放器-shooter player 射手播放器
  3. 冷凝器胶球清洗装置的10条操作事项
  4. 怎么选择电销机器人,电销机器人好不好用主要看什么?
  5. php面向对象编写计算器,使用面向对象的图形计算器,面向对象图形计算器_PHP教程...
  6. 使用Python进行网站页面开发——HTML
  7. 李嘉诚的经典演讲:打工才是最愚蠢的投资
  8. C. Discrete Acceleration
  9. PHP开发的资产管理系统源码基于layuimini框架
  10. 《花开半夏》--4 苏彤(2)