Is it possible to have a global request handler, associated with a specifie

Hi,

I’m struggling to work out how to invoke a connected session in another browser.

The particular case I have, is that I’m trying to open a connected session in Google Earth from my application.

I have a StreamSource, which generate a KML network link (basically a file with an embedded URL in it):

class KmlNetworkLinkSource implements StreamResource.StreamSource {
    @Override
    InputStream getStream() {
        String servletPath = VaadinServlet.getCurrent().getServletContext();
        String linkUrl = "http://localhost:8080" + servletPath + "/networkLinkKml";

        return new ByteArrayInputStream(myNetworkLinkGenerator.generate(linkUrl).bytes);
    }
}

This is linked to a downloader, which downloads the KML file when the button is pressed.

It contain an absolute linkUrl which is opened by the Google Earth web browser externally (without any reference to the current session).

I handle that session using a requestHandler:

    VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest vaadinRequest, VaadinResponse response) {
            if ("/networkLinkKml".equals(vaadinRequest.getPathInfo())) {
                String bbox = vaadinRequest.getParameter("BBOX")
                response.setContentType("application/vnd.google-earth.kml+xml")
                response.getWriter().append(kmlGenerator.requestForBBox(bbox))
                return true
            } else
                return false
        }

So, this is supposed to handle the external request and render a KML file into the google earth browser.

But, of course, what happens is that it does the right think if I open that URL in a different tab of the browser that has the current session running, but if I open that URL in a different browser the session isn’t active yet, and so the request handler hasn’t bound, and instead of that handler running and serving the file, I just get the app again.

Is there a way of binding the request handler more globally? And in that global handler is it possible to make an association with the session (perhaps by embedded an id in the URL, and finding the session via it through a global singleton?)

The reason that I want to find the session, is that I also want to Push to that session based on the values of the BBOX in the request.

Any pointers would be gratefully received.

Cheers.

Ok, I’ve found out how. The RequestHandler needed to be bound globally so that it can handle the request immediately:

   public static class Servlet extends VaadinServlet {
        @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(googleEarthView.globalRequestHandler())
                }
            });
            super.service(request, response)
        }
    }