public class MyFilter implements RequestFilter { @Override public boolean service(final Request request, final Response response, final RequestHandler handler) throws IOException { ... //your code try { return handler.service(request, response); } finally { ... //your code } } }
protected final void train_service(RequestHandler handler, Request request, Response response, boolean result) throws IOException { expect(handler.service(request, response)).andReturn(result); }
public boolean service(Request request, Response response, RequestHandler handler) throws IOException { requestGlobals.storeRequestResponse(request, response); return handler.service(request, response); } };
public boolean service(Request request, Response response, RequestHandler handler) throws IOException { try { return handler.service(request, response); } finally { perThreadManager.cleanup(); } } }
public boolean service(Request request, Response response, RequestHandler handler) throws IOException { try { return handler.service(request, response); } finally { endOfRequestEventHub.fire(); } } };
public Boolean invoke() { if (System.currentTimeMillis() - lastCheck >= checkInterval) barrier.tryWithWrite(checker, updateTimeout, TimeUnit.MILLISECONDS); // And, now, back to code within the read lock. try { return handler.service(request, response); } catch (IOException ex) { exceptionHolder.put(ex); return false; } } };
public boolean service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException { requestGlobals.storeServletRequestResponse(servletRequest, servletResponse); // Should have started doing this a long time ago: recoding attributes into // the request for things that may be needed downstream, without having to extend // Request. servletRequest.setAttribute("servletAPI.protocol", servletRequest.getProtocol()); servletRequest.setAttribute("servletAPI.characterEncoding", servletRequest.getCharacterEncoding()); servletRequest.setAttribute("servletAPI.contentLength", servletRequest.getContentLength()); servletRequest.setAttribute("servletAPI.authType", servletRequest.getAuthType()); servletRequest.setAttribute("servletAPI.contentType", servletRequest.getContentType()); servletRequest.setAttribute("servletAPI.scheme", servletRequest.getScheme()); Request request = new RequestImpl(servletRequest, applicationCharset, sessionFactory); Response response = new ResponseImpl(servletRequest, servletResponse); // TAP5-257: Make sure that the "initial guess" for request/response // is available, even ifsome filter in the RequestHandler pipeline replaces them. // Which just goes to show that there should have been only one way to access the Request/Response: // either functionally (via parameters) or global (via ReqeuestGlobals) but not both. // That ship has sailed. requestGlobals.storeRequestResponse(request, response); // Transition from the Servlet API-based pipeline, to the // Tapestry-based pipeline. return handler.service(request, response); } }
public class RenderStatisticsFilter implements RequestFilter { @Override public boolean service(Request request, Response response, RequestHandler handler) throws IOException { this.beforeRender(); final boolean result = handler.service(request, response); this.afterRender(); return result; } private void beforeRender() { ... } private void afterRender() { ... } }
/** * Processes a request for the specified path and returns the response generated. This is for * low-level testing, most of the time {@link #renderPage(String)} is what you want. Note that * unlike {@link #renderPage(String)}, this does not follow redirects - instead the redirect response * is returned. * * @param path the path for the request; must begin with a "/" character (not null) * @return the response (not null) */ public TestableResponse renderResponse(String path) { assert path.startsWith("/"); try { request.clear().setPath(path); response.clear(); boolean handled = requestHandler.service(request, response); if (!handled) { throw new RuntimeException( String.format("Request was not handled: '%s' may not be a valid path.", path)); } return response; } catch (IOException e) { throw new RuntimeException(e); } }
return handler.service(request, response);
public boolean service(Request request, Response response, RequestHandler handler) throws IOException { long startTime = System.nanoTime(); try { return handler.service(request, response); } finally { long elapsed = System.nanoTime() - startTime; log.info(String.format("Request time: %5.2f s -- %s", elapsed * 10E-10d, request.getPath())); } } };
private TestableResponse runComponentEventRequest() { while (true) { response.clear(); try { boolean handled = requestHandler.service(request, response); if (!handled) throw new RuntimeException(String.format("Request for path '%s' was not handled by Tapestry.", request.getPath())); Link link = response.getRedirectLink(); if (link != null) { setupRequestFromLink(link); continue; } return response; } catch (IOException ex) { throw new RuntimeException(ex); } finally { registry.cleanupThread(); } } }
public boolean service(Request request, Response response, RequestHandler handler) throws IOException { try { return handler.service(request, response); } catch (IOException ex) { // Pass it through. throw ex; } catch (Throwable ex) { // Most of the time, we've got exception linked up the kazoo ... but when ClassLoaders // get involved, things go screwy. Exceptions when transforming classes can cause // a NoClassDefFoundError with no cause; here we're trying to link the cause back in. // TAPESTRY-2078 Throwable exceptionToReport = attachNewCause(ex, internalRequestGlobals.getClassLoaderException()); exceptionHandler.handleRequestException(exceptionToReport); // We assume a reponse has been sent and there's no need to handle the request // further. return true; } }
boolean handled = requestHandler.service(request, response);