Many applications bounded to application context


I need to implement web filter which needs the Vaadin application instance. I know how to get (Web)ApplicationContext. But what makes me doubt is that in AbstractApplicationContext has field “applications” which is colletion of applications.

Is there any situation when there will exist more than 1 application for 1 user/http session?
Till now I thought that there is “1 to 1” mapping between http session and Vaadin application and now I am confused.

No, a HTTP session can have multiple Vaadin applications.

This is because the Java Servlet API is originally designed for conventional non-Ajax applications, which use different URLs for different types of requests, each of which URL is mapped to a different servlet. For example, an web application with a simple form could have a “/app/showform” request, which is mapped to one servlet, and a “/app/submitform” request, which is mapped to another. Both of the servlets would run in the same “application” (or context), which would have a base URL, such as “/app”, and there would be just one session.

As the definition of

There is one context per “web application” per Java Virtual Machine. (A “web application” is a collection of servlets and content installed under a specific subset of the server’s URL namespace such as /catalog and possibly installed via a .war file.)

Vaadin applications, on the other hand, run in a single servlet in a single URL. It is therefore possible to have multiple Ajax (such as Vaadin) applications in the same “web application”.

OK, got it.
But as long as I have only 1 place in whole application which has ability to create Vaadin application (1 servlet in .war that has getNewApplication(…) method to create Vaadin application) it is
possible to have many applications yes?

Well, it’s always possible to push the “application” abstraction further. You could have, for example, a Hello World and Calc applications in a single Vaadin application, but then differentiate between them in getWindow(). They could have separate URLs /mycontext/helloworld and /mycontext/calc.