在 tomcat 中使用不同的适配器

Use a different adapter in tomcat

我想将 tomcat 7 配置为使用与默认 CoyoteAdapter 不同的适配器来处理一些格式错误的 cookie。这可能吗?

原因是我们低于异常

SEVERE: Error processing request
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
    at org.apache.tomcat.util.http.CookieSupport.isHttpSeparator(CookieSupport.java:205)
    at org.apache.tomcat.util.http.Cookies.getTokenEndPosition(Cookies.java:530)
    at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:377)
    at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:195)
    at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:119)
    at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:1089)
    at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:796)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:440)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    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:745)

您不能更改 Coyote 适配器,除非您实现自己的 org.apache.coyote.Processor。但在tomcat-8中,您可以更改cookie处理器:

  1. 实施org.apache.tomcat.util.http.CookieProcessor
  2. 将 jar 放入 tomcat 的 lib 文件夹
  3. 将 tomcat 配置为使用您自己的 cookie 处理器,方法是将其放入 context.xml:
<Context>
    <CookieProcessor className="org.example.MonsterCookieProcessor"/>
<Context>

很遗憾,您不能在 tomcat-7 中执行此操作,因为 cookie 处理器逻辑已硬编码在 CoyoteRequest:

    private Cookies cookies = new Cookies(headers);