How to change Cookie Processor to LegacyCookieProcessor in tomcat 8

你。 提交于 2019-11-26 16:42:33

问题


My code is working on tomcat 8 version 8.0.33 but on 8.5.4 i get : An invalid domain [.mydomain] was specified for this cookie.

I have found that Rfc6265CookieProcessor is introduced in tomcat 8 latest versions.

It says on official doc that this can be reverted to LegacyCookieProcessor in context.xml but i don't know how.

Please let me know how to do this.

Thanks


回答1:


You can try in context.xml

<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />

reference: https://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html




回答2:


Enabling the LegacyCookieProcessor which is used in previous versions of Tomcat has solved the problem in my application. As linzkl mentioned this is explained in Apache's website https://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html.

The reason is that the new version of Tomcat does not understand the . (dot) in front of the domain name of the Cookie being used.

Also, make sure to check this post when you are using Internet Explorer. Apparently, it's very likely to break.

You can find context.xml in the following path.

tomcat8/conf/context.xml

<?xml version="1.0" encoding="UTF-8”?>
<!-- The contents of this file will be loaded for each web application —>
<Context>
<!-- Default set of monitored resources. If one of these changes, the    -->
<!-- web application will be reloaded.                                   -->

<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!-- <Manager pathname="" /> -->
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor"/>
</Context>



回答3:


Case 1: You are using Standalone Tomcat & have access to change files in tomcat server

Please follow answer by @linzkl

Case 2: You are using Standalone Tomcat but you don't have access to change files in tomcat server

Create a new file called context.xml under src/main/webapp/META-INF folder in your application & paste the content given below

<?xml version="1.0" encoding="UTF-8"?> 
<Context>
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
  <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
  <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 
  <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
</Context>

When you deploy your application in Standalone Tomcat, the context.xml file you placed under META-INF folder will override the context.xml file given in tomcat/conf/context.xml

Note: If you are following this solution, you have to do it for every single application because META-INF/context.xml is application specific

Case 3: You are using Embedded Tomcat

Create a new bean for WebServerFactoryCustomizer

@Bean
WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
    return new WebServerFactoryCustomizer<TomcatServletWebServerFactory>() {

        @Override
        void customize(TomcatServletWebServerFactory tomcatServletWebServerFactory) {
            tomcatServletWebServerFactory.addContextCustomizers(new TomcatContextCustomizer() {
                @Override
                public void customize(Context context) {
                    context.setCookieProcessor(new LegacyCookieProcessor());
                }
            });
        }
    };
}



回答4:


The problem is still with Tomcat9. Same process need to follow for Tomcat 9 to set the class.

Add the class in context.xml file.

If you are using eclipse to run the application, need to set in the context.xml file in the server folder. Refer the below screenshot for more reference.

Hope this helps someone.



来源:https://stackoverflow.com/questions/38696081/how-to-change-cookie-processor-to-legacycookieprocessor-in-tomcat-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!