@Override protected List<RequestHandler> createRequestHandlers() throws ServiceException { List<RequestHandler> handlers = super.createRequestHandlers(); handlers.add(0, new ServletBootstrapHandler()); handlers.add(new ServletUIInitHandler()); if (isAtmosphereAvailable()) { handlers.add((RequestHandler) (session, request, response) -> { if (!ServletPortletHelper.isPushRequest(request)) { return false; } if (request instanceof VertxVaadinRequest) { ((VertxVaadinRequest) request).getRoutingContext().next(); } return true; }); } return handlers; }
/** * initalize a unique RequestHandler */ private void initRequestHandler() { if (this.requestHandlerUri == null) { this.requestHandlerUri = UUID.randomUUID() .toString(); VaadinSession.getCurrent() .addRequestHandler(new RequestHandler() { @Override public boolean handleRequest(final VaadinSession session, final VaadinRequest request, final VaadinResponse response) throws IOException { if (String.format("/%s", Jcrop.this.requestHandlerUri) .equals(request.getPathInfo())) { Jcrop.this.resource.getStream() .writeResponse(request, response); return true; } else { return false; } } }); } }
@Override protected void servletInitialized() throws ServletException { super.servletInitialized(); HeaderTagHandler.init(getService()); getService().addSessionInitListener(new SessionInitListener() { @Override public void sessionInit(SessionInitEvent event) throws ServiceException { event.getSession().addRequestHandler(new RequestHandler() { @Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { String pathInfo = request.getPathInfo(); InputStream in = null; if (pathInfo.endsWith("sw.js")) { response.setContentType("application/javascript"); in = getClass().getResourceAsStream("/sw.js"); } if (in != null) { OutputStream out = response.getOutputStream(); IOUtils.copy(in, out); in.close(); out.close(); return true; } else { return false; } } }); } }); }
/** * Creates the parameter handler that will be invoked when the user returns * from the OAuth service. * * @return the parameter handler */ protected RequestHandler createRequestHandler() { return new RequestHandler() { public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (request.getParameterMap().containsKey(getVerifierName())) { String v = request.getParameter(getVerifierName()); Verifier verifier = new Verifier(v); accessToken = service .getAccessToken(requestToken, verifier); User user = getUser(); VaadinSession.getCurrent().removeRequestHandler(handler); handler = null; //String url = getAuthUrl(); //callbackPage.open(url, "Authentificate", 400, 300, BorderStyle.DEFAULT); authListener.userAuthenticated(user); } else if (getFailureParameters() != null) { for (String key : getFailureParameters()) { if (request.getParameterMap().containsKey(key)) { authListener.failed(request.getParameter(key)); break; } } } return true; } }; }