Get cookie from init() in vaadin 6

Hey guys!
I am trying to make an application that can switch between multiple languages and that can save the chosen language in a cookie for future uses. My problem is that i can’t seems to find a way to get my cookies in the init() method. I create all my components in this method so i need to find the chosen language there to choose which strings to display.
For the moment i get my cookies by implementing HttpServletRequestListener and using onRequestStart() to get my cookies from HttpServletRequest, but onRequestStart() is called after the init()
Is there any way to have access to my cookies in the init() method, or am i not supposed to do that and im doing something wrong?
Thanks!

I usually override the Serverlets service(…) method, then place the cookies in the session. You can get hold of the session in the init() method…

I tried to use a custom Application servlet to try to be able to override the method Service(), but i don’t know if its the right way to go…
So i made a new servlet:


public class TestServlet extends AbstractApplicationServlet{
	private static final long serialVersionUID = 2243541609997529913L;

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException,
			IOException {
		System.out.println("TestServlet.service() called");
	};

	@Override
	protected Class<? extends Application> getApplicationClass() {
		System.out.println("TestServlet.getApplicationClass() called");
		return Vaadin6_testsApplication.class;
	}

	@Override
	protected Application getNewApplication(HttpServletRequest request)
			throws ServletException {
		System.out.println("TestServlet.getNewApplication() called");
		return new Vaadin6_testsApplication();
	}
}

and Vaadin6_testsApplication extends com.vaadin.Application;

I also changed my web.xml to use my custom application servlet instead of com.vaadin.server.VaadinServlet:


	<servlet>
		<servlet-name>Vaadin6_tests Application</servlet-name>
		<servlet-class>com.example.vaadin6_tests.TestServlet</servlet-class>
		<init-param>
			<description>
			Vaadin application class to start</description>
			<param-name>application</param-name>
			<param-value>com.example.vaadin6_tests.Vaadin6_testsApplication</param-value>
		</init-param>
	</servlet>

The problem is when i launch the website, the method TestServlet .service() is called but nothing else and my application is now showing. Did i forget something?

The obvious thing that might be easy to forget: you need to call super.service(…) in your service(…) method after getting the cookie from the request and putting it somewhere (ThreadLocal) where the init() method can use it (or keeping the whole request).

I would recommend resetting the ThreadLocal immediately after calling super.service(…) - just set null as its value.

Ahh yes i missed that. thanks it works now!