2 Replies Latest reply on Jan 8, 2018 4:39 AM by Konrad Gancarz

    Wildfly 9 - add trailing slash to JSESSIONID

    Konrad Gancarz Newbie

      Hello there,

       

      I'm struggling with one problem in my web app deployed to Wildfly 9 server. For application under the context path /myapp JSESSIONID cookie is generated with path=/myapp.

      How do I force wildfly to set cookie path to /myapp/ instead?

       

      I'll be grateful for any advice.

        • 1. Re: Wildfly 9 - add trailing slash to JSESSIONID
          Erik . Newbie

          You can control the cookie settings by adding WEB-INF\jboss-web.xml to your web app with the session-config

          <?xml version="1.0" encoding="UTF-8"?>
          <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_8_0.xsd"
                     version="8.0">
              <context-root>/myapp/</context-root>
              <virtual-host>default-host</virtual-host>
              <session-config>
                  <cookie-config>
                      <path>/myapp/</path>
                      <name>JSESSIONID</name>
                      <http-only>true</http-only>
                      <secure>true</secure>
                  </cookie-config>
              </session-config>
          </jboss-web>
          

           

          Or with adding session-config to WEB-INF\web.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
                   version="3.1">
          ...
              <session-config>
                  <session-timeout>15</session-timeout>
                  <cookie-config>
                      <path>/myapp/</path>
                      <name>JSESSIONID</name>
                      <http-only>true</http-only>
                      <secure>true</secure>
                  </cookie-config>
                  <tracking-mode>COOKIE</tracking-mode>
              </session-config>
          </web-app>
            
          • 2. Re: Wildfly 9 - add trailing slash to JSESSIONID
            Konrad Gancarz Newbie

            I made this workaround, but it has a consequence that application must be deployed under /myapp on my application serwer, otherwise session cookie will not work.

            For example Tomcat adds the trailing slash to session cookie path, so I suspected that it's possible in Wildfly too. If not, I'll have to stick to configuration in web.xml.