Server functionality in multiple web applications

I need to perform preliminary and subsequent processing of all incoming requests to the web server. Functionality is url level access restriction and language translation, as well as other special cases that need to be handled globally.

This can usually be achieved using servlet filters, but when the number of web applications grows, it becomes desirable not to associate filters with each application, since all applications need to be rebuilt and redeployed when changes are made to the filter.

Instead, I would like to install filters around the world on the server, and I found two possible solutions, of which I am not satisfied with any of them.

  • In Tomcat, you can deploy server filters in the "lib" directory and configure the web.xml server to map them to incoming requests. The problem I see is that any filter dependencies must also be deployed globally in the lib directory. From what I understand, this can lead to serious dependency conflicts with installed applications. ( Can Tomcat load the same library file into memory twice if they are in two web applications?

  • Deploying filters in a simple web application, which basically acts as a proxy server, at least associates filters with their respective dependencies. This application can then be deployed to the server and accept all incoming requests before sending them to the target application using the crossContext configuration parameter. ( RequestDispatcher forward between Tomcat instances ) However, this requires tinkering with the URLs so that all links point to "proxies."

None of these solutions seem satisfactory. They are platform dependent as they rely on Tomcat. They both seem to have potential problems and require special dependency handling.

What is the best practice for using server functionality?

+6
java tomcat servlet-filters global
source share
1 answer

This is my unverified thought (so not the best practice) - this is option 2 on your list.

You can use Sitemesh (which is actually intended to decorate several web applications with a common header / footer, but in this case do not use a header / footer).

Submit Sitemesh as a standalone web application using crossContext = true.

Sitemesh will be called as a filter for each web application, so the URLs that the end user sees will not change at all. But you will need to define decortaor.xml for each web application.

You can write your actual filter processor and link it after the Sitemesh filter. All requests are first sent to the Sitemesh application - then to your filter - then to a separate servlet in the web application.

+1
source share

All Articles