RequestHandler not working on first loading

Context:
My development server is a tomcat 7, running on http://127.0.0.1:8080 and my application is called FOO.
I’ve added a RequestHandler to render dynamic files depending on the URL, for instance http://127.0.0.1:8080 /FOO/manifest should return a dynamic list of files instead of the UI.

I added my request handler in the attach() method of my UI class.

Problem:
The first time(after a server restart) that I visit this page: http://127.0.0.1:8080/FOO/manifest, my request handler doesn’t have /manifest in getPathInfo()
Reloading the page (F5) makes it works.

What did I do wrong ?

Thanks

Hey guys,

Problem fixed by adding a VaadinServlet and setting the request handler in a SessionInitListener which is set in service(HttpServletRequest request, HttpServletResponse response).

Again, I don’t know if it’s the good way of doing it.
You guys should write a note in the documentation about this issue.

Hi Serge,

Could you help me?

I try to create a request handler with vaadin 7 but it does not work me.

public class AdminUi extends UI
{
private final RequestHandler requestHandler = new RequestHandler()
{
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
{
System.out.println(“RequestHandler”);
return false;
}
};

/**
 * Main UI
 */
@Override
protected void init(VaadinRequest request)
{
	System.out.println("init");

	Resource resource = new ExternalResource("apple.png");
	
            getSession().addRequestHandler(requestHandler);
	
	Image image = new Image("image", resource);
	setContent(image);
}

@Override
public void detach() {
	super.detach();
	
	// Clean up
    getSession().removeRequestHandler(requestHandler);
    System.out.println("detach");
}

But this code never calls the handleRequest method.

Could you help me?

Thank you.

I ran your code and it did call the handleRequest method and I got the output of the System.out in the console.

This is not true on my setup: vaadin 7.0.5 + tomcat 6
Here is the output for the first loading, and a refresh:


=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
init
RequestHandler
init

The request handler is only called for the refresh; because the session doesn’t exist on the first loading.
Which is really wrong, because some http client will not keep session from one request to another (for instance, a download program)

The “correct” way to add a request handler is to do it in the servlet:


public class MyServlet extends VaadinServlet {
	private final RequestHandler requestHandler = new RequestHandler()

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		getService().addSessionInitListener(new SessionInitListener() {
			@Override
			public void sessionInit(SessionInitEvent event)
					throws ServiceException {
				event.getSession().addRequestHandler(requestHandler);
			}
		});
	}
}

Hi Everybody,

I have a similar problem, but using VaadinPortlet instead a VaadinServlet. As you know, this havent a service method implementation. Where can I set a new requestHandler in order to resolve this issue?
Are there any other solution?

Thanks in advance.

How do you register your custom MyServlet?