Web application using vaadin - facing problem in tomcat clustering

Dear Team,

We are doing clustering in our web based vaadin application using apache tomcat.

We have done successful proof of concept in normal jsp-servlet applications.

Now we are doing same activity on our vaadin based application.

We have taken care all necessary steps for clustering like Serializable implementations , add tags in web.xml , add cluster in server.xml etc.

We are facing below problem:

We have one production server. And for clustering and load balancing , we have installed two node (tomcat instance) on production server.
When we down the one node , then second node should automatically pick up request without user knowing that something is happened on server.
Same things is working fine in jsp-servlet demo application.
However in vaadin based application , we are receiving vaadin internal message like “Session Expired , please click here to login” when instance is down. So every time we need to login to application.

We do not want this message when one instance is down , as per rule of thumb of clustering second configured node should automatically pick up next request.

Please let me know how to achieve this ?

I would really appreciate on your prompt response.

Looking forward to your great support and co’ operations.

Thanks and Regards,
Ashish Patel

Looks like the the Vaadin sessions aren’t replicated properly to the other node, so that when the cluster switches to it, the session isn’t there. Can’t say what is the difference with the JSP servlet example.

Might be some configuration problem. Anything in the server logs? Clustering should work with Terracotta at least (see
this post
) and also normally in Tomcat (see
this post
which encountered a problem with Tomcat).

Do your servlet/JSP application put anything in the HttpSession?
Is that content replicated when node 1 is down.

I’d not work on the Vaadin test until you see that working in your servlet/JSP application.

Dear John,

Please find my sample code for jsp application - which is working fine (session id is replicated to other node2 when node1 is down)…

===========================================================================================
<%@ page language=“java” %>

node2

    <BR>
    <% if (session.isNew()) {%>
    <h2><font color="green"> This is a new session ! </font></h2><BR>
    <%} else {%>
    <h2><font color="pink">This is an existing session </font></h2><BR>
    <%}%>
</body>

<%
Integer counter = (Integer) session.getAttribute(“counter”);
if (counter == null) {
counter = new Integer(1);
} else {
counter = new Integer(counter.intValue() + 1);
}

        session.setAttribute("counter", counter);

%>

Using Sessions to Track Users

Session ID: <%=session.getId()%>
Session creation time: <%=new java.util.Date(session.getCreationTime())%>
Last accessed time: <%=new java.util.Date(session.getLastAccessedTime())%>
Number of times you have been here: <%=counter%> ===========================================================================================

Dear Marko,

I have configured tomcat valve as per link given by you.
Sample jsp application is working fine.
Still getting vaadin internal message “Session Expired” when node1 is down on vaadin application.

Please help.

Please find attached Screen shot for your information.
11568.jpg

What version of Vaadin are you using? I just tried this out with GlassFish 3.1 (you can always try that – final release was yesterday and it includes clustering) and Vaadin 6.5.0 and it worked for me.

My entire web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
		  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">

    <distributable />

</web-app>

And my simple class (a button with counter) is:


public class SimpleApp extends Application implements Serializable,
    Button.ClickListener {

    int count = 5;
    Label countLabel = new Label(count + " Click(s)");

    @Override
    public void init() {
        Window mainWindow = new Window("Test Application");
        Label instructions = new Label("Click the button a few times to " +
            "increase the counter. Then stop instance and view on another " +
            "instance to make sure the state (and, thus, sesion) " +
            "was replicated.");

        Button button = new Button("Click", this);

        // add 'em
        mainWindow.addComponent(instructions);
        mainWindow.addComponent(countLabel);
        mainWindow.addComponent(button);

        // add window to the application
        setMainWindow(mainWindow);
    }

    @Override
    public void buttonClick(Button.ClickEvent clickEvent) {
        countLabel.setValue(++count + " Clicks");
    }

    @WebServlet(urlPatterns = "/*")
    public static class MyServlet extends AbstractApplicationServlet {

        @Override
        protected Class<? extends Application> getApplicationClass() {
            return SimpleApp.class;
        }

        @Override
        protected Application getNewApplication(HttpServletRequest request)
            throws ServletException {

            return new SimpleApp();
        }
    }

}

I deployed it with the GlassFish
–availabilityenabled=true
flag; I don’t know if there’s a similar setting in Tomcat. After deploying it to a cluster with 2 instances, I loaded it on one instance and incremented the counter a couple times. I then shut down the instance and loaded the page from a different instance (e.g. changed port number in my URL – am not using a load balancer here). I saw that the counter stayed where I left it.

So at least with Vaadin 6.5.0, I don’t see anything in Vaadin that is preventing failover from working. If you want to try it with GlassFish, it’s just as free as Tomcat. :slight_smile: (I’m about 500 messages behind on the forum, or I’d announce here that it’s available with some tips for Vaadin users – e.g. turn off ‘maintain session on redeployment’.)

Cheers,
Bobby