Request Type

In our application we need special handling for static files. In Vaadin 6 we simply made a hook in servlet’s service() method, in Vaadin 7 is getRequestType() deprecated. Can anybody explain the right way to get this info in Vaadin7?

you could use a request handler.

add it with getSession().addRequestHandler(new RequestTest());

Example:

import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.vaadin.server.RequestHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
import com.vaadin.server.VaadinServiceSession;

public class RequestTest implements RequestHandler {

	public RequestTest() {
	}

	@Override
	public boolean handleRequest(VaadinServiceSession session,
			VaadinRequest request, VaadinResponse response) throws IOException {
		String s = request.getRequestPathInfo();
		response.setCacheTime(-1);
		if( s.contains("/img/")){
		BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_3BYTE_BGR);
                bi.getGraphics().drawString(s, 10, 10);
                response.setContentType("image/png");
                ImageIO.write(bi, "png", response.getOutputStream());
		return true;
		}
        return false;
	}
}

Unfortunately RequestHandler does not work for static resources from /VAADIN/ directory. And VaadinServlet.serveStaticResourcesInVAADIN() is private. We need to server /VAADIN/ too because of proprietary file access in our embedded system. We used our working solution from Vaadin 6 - serve all /VAADIN/ resources in overriden VaadinServlet.service(). Making serveStaticResourcesInVAADIN() protected would be more elegant.

Currently there isn’t a better way to override the handling of static resources in /VAADIN. Some of what the servlet does should still be refactored and some functionality moved to the service class (with a better, more open API), but that is unlikely to happen before 7.0.0.

Thus, you can either use the deprecated method and change the approach in the future or override the protected service() method - for static resources, it should not be a problem to hook right at the beginning of service().