Search in sources :

Example 1 with RequestHandler

use of org.apache.tapestry5.http.services.RequestHandler in project tapestry-5 by apache.

the class StaticFilesFilterTest method existing_file.

@Test
public void existing_file() throws Exception {
    URL url = new URL("file://.");
    String path = "/cell.gif";
    Request request = newRequest(path);
    Response response = mockResponse();
    RequestHandler handler = mockRequestHandler();
    Context context = mockContext();
    train_getResource(context, path, url);
    replay();
    RequestFilter filter = new StaticFilesFilter(context);
    assertFalse(filter.service(request, response, handler));
    verify();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) Context(org.apache.tapestry5.http.services.Context) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) Request(org.apache.tapestry5.http.services.Request) URL(java.net.URL) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) Test(org.testng.annotations.Test)

Example 2 with RequestHandler

use of org.apache.tapestry5.http.services.RequestHandler in project tapestry-5 by apache.

the class StaticFilesFilterTest method colon_in_path_prevents_static_file_check.

/**
 * TAPESTRY-2606
 */
@Test
public void colon_in_path_prevents_static_file_check() throws Exception {
    String path = "/start.update:anevent";
    Request request = newRequest(path);
    Response response = mockResponse();
    RequestHandler handler = mockRequestHandler();
    Context context = mockContext();
    train_service(handler, request, response, true);
    replay();
    RequestFilter filter = new StaticFilesFilter(context);
    assertTrue(filter.service(request, response, handler));
    verify();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) Context(org.apache.tapestry5.http.services.Context) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) Request(org.apache.tapestry5.http.services.Request) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) Test(org.testng.annotations.Test)

Example 3 with RequestHandler

use of org.apache.tapestry5.http.services.RequestHandler in project tapestry-5 by apache.

the class StaticFilesFilterTest method existing_template_file_case_insenitive.

@Test
public void existing_template_file_case_insenitive() throws Exception {
    URL url = new URL("file://.");
    String path = "/cell.TML";
    Request request = newRequest(path);
    Response response = mockResponse();
    RequestHandler handler = mockRequestHandler();
    Context context = mockContext();
    train_getResource(context, path, url);
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "URI /cell.TML may not be accessed remotely.");
    replay();
    RequestFilter filter = new StaticFilesFilter(context);
    assertTrue(filter.service(request, response, handler));
    verify();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) Context(org.apache.tapestry5.http.services.Context) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) Request(org.apache.tapestry5.http.services.Request) URL(java.net.URL) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) Test(org.testng.annotations.Test)

Example 4 with RequestHandler

use of org.apache.tapestry5.http.services.RequestHandler in project tapestry-5 by apache.

the class StaticFilesFilterTest method request_for_favicon.

@Test
public void request_for_favicon() throws IOException {
    Request request = newRequest("/favicon.ico");
    Response response = mockResponse();
    RequestHandler handler = mockRequestHandler();
    Context context = mockContext();
    replay();
    RequestFilter filter = new StaticFilesFilter(context);
    assertFalse(filter.service(request, response, handler));
    verify();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) Context(org.apache.tapestry5.http.services.Context) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) Request(org.apache.tapestry5.http.services.Request) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) Test(org.testng.annotations.Test)

Example 5 with RequestHandler

use of org.apache.tapestry5.http.services.RequestHandler in project tapestry-5 by apache.

the class TapestryModule method contributeRequestHandler.

/**
 * Continues a number of filters into the RequestHandler service:
 * <dl>
 * <dt>StaticFiles</dt>
 * <dd>Checks to see if the request is for an actual file, if so, returns true to let the servlet container process
 * the request</dd>
 * <dt>CheckForUpdates</dt>
 * <dd>Periodically fires events that checks to see if the file system sources for any cached data has changed (see
 * {@link org.apache.tapestry5.internal.services.CheckForUpdatesFilter}). Starting in 5.3, this filter will be null
 * in production mode (it will only be active in development mode).
 * <dt>ErrorFilter</dt>
 * <dd>Catches request errors and lets the {@link org.apache.tapestry5.services.RequestExceptionHandler} handle them
 * </dd>
 * <dt>StoreIntoGlobals</dt>
 * <dd>Stores the request and response into the {@link org.apache.tapestry5.http.services.RequestGlobals} service (this
 * is repeated at the end of the pipeline, in case any filter substitutes the request or response).
 * <dt>EndOfRequest</dt>
 * <dd>Notifies internal services that the request has ended</dd>
 * </dl>
 */
public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration, Context context, @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE) boolean productionMode) {
    RequestFilter staticFilesFilter = new StaticFilesFilter(context);
    RequestFilter storeIntoGlobals = new RequestFilter() {

        public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
            requestGlobals.storeRequestResponse(request, response);
            return handler.service(request, response);
        }
    };
    RequestFilter fireEndOfRequestEvent = new RequestFilter() {

        public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
            try {
                return handler.service(request, response);
            } finally {
                endOfRequestEventHub.fire();
            }
        }
    };
    if (productionMode) {
        configuration.add("CheckForUpdates", null, "before:*");
    } else {
        configuration.addInstance("CheckForUpdates", CheckForUpdatesFilter.class, "before:*");
    }
    configuration.add("StaticFiles", staticFilesFilter);
    configuration.add("StoreIntoGlobals", storeIntoGlobals);
    configuration.add("EndOfRequest", fireEndOfRequestEvent);
    configuration.addInstance("ErrorFilter", RequestErrorFilter.class);
}
Also used : StreamResponse(org.apache.tapestry5.StreamResponse) Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestHandler(org.apache.tapestry5.services.ComponentEventRequestHandler) RequestHandler(org.apache.tapestry5.http.services.RequestHandler) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) PageRenderRequestHandler(org.apache.tapestry5.services.PageRenderRequestHandler) Request(org.apache.tapestry5.http.services.Request) HttpServletRequestFilter(org.apache.tapestry5.http.services.HttpServletRequestFilter) ComponentRequestFilter(org.apache.tapestry5.services.ComponentRequestFilter) PageRenderRequestFilter(org.apache.tapestry5.services.PageRenderRequestFilter) RequestFilter(org.apache.tapestry5.http.services.RequestFilter) ComponentEventRequestFilter(org.apache.tapestry5.services.ComponentEventRequestFilter)

Aggregations

Request (org.apache.tapestry5.http.services.Request)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 Response (org.apache.tapestry5.http.services.Response)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Context (org.apache.tapestry5.http.services.Context)7 Test (org.testng.annotations.Test)7 URL (java.net.URL)3 StreamResponse (org.apache.tapestry5.StreamResponse)1 HttpServletRequestFilter (org.apache.tapestry5.http.services.HttpServletRequestFilter)1 ComponentEventRequestFilter (org.apache.tapestry5.services.ComponentEventRequestFilter)1 ComponentEventRequestHandler (org.apache.tapestry5.services.ComponentEventRequestHandler)1 ComponentRequestFilter (org.apache.tapestry5.services.ComponentRequestFilter)1 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)1 PageRenderRequestFilter (org.apache.tapestry5.services.PageRenderRequestFilter)1 PageRenderRequestHandler (org.apache.tapestry5.services.PageRenderRequestHandler)1