How To: Tomcat Applications With Multiple Folders

In a previous post, I asked about setting up Tomcat with multiple root folders and a single application. Use this recipe if
  • you are deploying a single application as a .war file
  • you need multiple root folders for your application
  • you store data in HttpSession
  • you have the Apache WS with mod_rewrite enabled
Recipe

  1. Open your server.conf file in CATALINA_HOME/conf and add the following parameter to your Connector setting emptySessionPath="true". This setting will force Tomcat to use '/' as the Cookie Path for JSESSIONID, the cookie used for sessions.
  2. Open your httpd.conf file. First, you'll need to add additional proxy statements:
ProxyPass /newpath http://localhost:8080/applicationpath ProxyPassReverse /newpath http://localhost:8080/applicationpath

newpath
is the new folder you want to setup.
applicationpath is the name of your war file

Note: I am assuming you're running apache and Tomcat on the same server. If not, replace localhost with your Tomcat host.

3. Add the following rewrite rule to your httpd.conf file

RewriteRule ^/newpath/(.*) /applicationpath/$1

4. Write your URLs correctly using the /newpath


Why this works?


You've forced tomcat to set the Session's cookie path to '/', so no matter what directories you create, your application will still receive the session cookie. The proxy statement tells Apache about the new folder to map to your application. The rewrite rule makes tomcat think that the URI is for your application.

What else?

In my next report, I'll tell you how to make sure your URLs are unique, something that is important for search engine optimization (SEO).
continue reading "How To: Tomcat Applications With Multiple Folders"

Techies Love Travel

I have started a travel community on TripConnect for Technologists that love to travel called Techies Love Travel. It's still a small group with relatively few members, but with a little work this can grow to an interesting community. In my experience, techies share many similar interests. Find me a good pub, a great sushi restaurant, a noodle house, some strong coffee etc. Now if you're going to travel, say on a vacation or on a business trip, how do you find some good local spots that fit your interests. You can read reviews and articles on this site and ask group members questions. Click here if you would like to join the group.

If you have a family, you can also check out the Family Travel Group or read my blog for Family Travelers. My most recent entry is on Top Tips on Getting through Airport Security with Kids.
continue reading "Techies Love Travel"

Question: Setting SESSION Cookie Paths in Apache Tomcat

One of the developers here has been hunting for a solution to the following configuration issue:

In tomcat, a SESSION's cookie path is automatically generated by Tomcat and set to the application's context path (e.g., the name of the .war file). This creates somewhat of an issue as it forces all URLs of the application to live underneath this folder. The issue is that the application is now getting URLs that are three, four, and even five levels deep. Long URLs are generally bad for SEO (search engine optimization), so it would be great if we could eliminate the application context's urls and have several root folder aliases that point to the same application.

This can easily be done with Apache's mod-rewrite, but the SESSION cookie path is the lingering issue. If the application name is 'foo', then the session cookie's path will be set to '/foo'. If I create new urls that live in a different root folder, say '/bah' and use Apache re-write to translate them to '/foo', then the mapping works and the correct pages fire, but the SESSION cookie won't be included in the browser's request since it lives in the '/foo' path.

Ideally, I should be able to set the SESSION cookie's path to the root folder '/'. This would not create an issue for us since we only have one other application running, the default one, that handles static objects. Ideally, I'd rather not use our application as the default.

So if anyone has a solution to this issue, feel free to comment!

Thanks!
continue reading "Question: Setting SESSION Cookie Paths in Apache Tomcat"
Share

About Isaac Sacolick

Isaac Sacolick is President of StarCIO, a technology leadership company that guides organizations on building digital transformation core competencies. He is the author of Digital Trailblazer and the Amazon bestseller Driving Digital and speaks about agile planning, devops, data science, product management, and other digital transformation best practices. Sacolick is a recognized top social CIO, a digital transformation influencer, and has over 900 articles published at InfoWorld, CIO.com, his blog Social, Agile, and Transformation, and other sites. You can find him sharing new insights @NYIke on Twitter, his Driving Digital Standup YouTube channel, or during the Coffee with Digital Trailblazers.