Search in sources :

Example 16 with Response

use of org.apache.tapestry5.services.Response 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 17 with Response

use of org.apache.tapestry5.services.Response 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 18 with Response

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

the class ComponentEventDispatcher method dispatch.

public boolean dispatch(Request request, Response response) throws IOException {
    ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request);
    if (parameters == null)
        return false;
    // Inside this pipeline, may find that the component id does not exist (this check only occurs in production
    // mode) ...
    componentRequestHandler.handleComponentEvent(parameters);
    // ... in which case, this attribute is set.
    if (request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND) != null) {
        return false;
    }
    return true;
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters)

Example 19 with Response

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

the class ComponentEventLinkEncoderImpl method createComponentEventLink.

public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) {
    StringBuilder builder = new StringBuilder(BUFFER_SIZE);
    // Build up the absolute URI.
    String activePageName = parameters.getActivePageName();
    String containingPageName = parameters.getContainingPageName();
    String eventType = parameters.getEventType();
    String nestedComponentId = parameters.getNestedComponentId();
    boolean hasComponentId = InternalUtils.isNonBlank(nestedComponentId);
    builder.append(contextPath);
    encodeAppFolderAndLocale(builder);
    builder.append(SLASH);
    builder.append(activePageName.toLowerCase());
    if (hasComponentId) {
        builder.append('.');
        builder.append(nestedComponentId);
    }
    if (!hasComponentId || !eventType.equals(EventConstants.ACTION)) {
        builder.append(':');
        builder.append(encodePageName(eventType));
    }
    appendContext(true, parameters.getEventContext(), builder);
    Link result = new LinkImpl(builder.toString(), forForm, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
    EventContext pageActivationContext = parameters.getPageActivationContext();
    if (pageActivationContext.getCount() != 0) {
        // Reuse the builder
        builder.setLength(0);
        appendContext(true, pageActivationContext, builder);
        // Omit that first slash
        result.addParameter(InternalConstants.PAGE_CONTEXT_NAME, builder.substring(1));
    }
    if (!containingPageName.equalsIgnoreCase(activePageName))
        result.addParameter(InternalConstants.CONTAINER_PAGE_NAME, encodePageName(containingPageName));
    return result;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 20 with Response

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

the class ResponseImplTest method addHeader.

@Test
public void addHeader() {
    final String HEADER_NAME = "Header-Name";
    final String[] HEADER_VALUES = { "asdfasdf", "FHDFGH", "####" };
    final HttpServletResponse httpServletResponse = mockHttpServletResponse();
    final HttpServletRequest httpServletRequest = mockHttpServletRequest();
    Response response = new ResponseImpl(httpServletRequest, httpServletResponse);
    for (String value : HEADER_VALUES) {
        httpServletResponse.addHeader(HEADER_NAME, value);
    }
    replay();
    for (String value : HEADER_VALUES) {
        response.addHeader(HEADER_NAME, value);
    }
    verify();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResponseImpl(org.apache.tapestry5.http.internal.services.ResponseImpl) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)53 Response (org.apache.tapestry5.http.services.Response)47 Request (org.apache.tapestry5.http.services.Request)25 Link (org.apache.tapestry5.http.Link)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)12 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)12 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)11 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)11 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 JSONObject (org.apache.tapestry5.json.JSONObject)8 Context (org.apache.tapestry5.http.services.Context)7 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)7 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)6 IOException (java.io.IOException)5