Search in sources :

Example 36 with Response

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

the class LinkImplTest method null_parameter_value.

/**
 * TAP5-922
 *
 * @since 5.3
 */
@Test
public void null_parameter_value() {
    Response response = mockResponse();
    String expectedURI = "/ctx/foo?barney=&fred=flintstone";
    train_encodeURL(response, expectedURI, expectedURI);
    replay();
    Link link = new LinkImpl("/ctx/foo", false, LinkSecurity.INSECURE, response, null, null);
    link.addParameter("fred", "flintstone");
    link.addParameter("barney", null);
    assertEquals(link.toURI(), expectedURI);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 37 with Response

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

Example 38 with Response

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

the class PageTester method runComponentEventRequest.

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();
        }
    }
}
Also used : IOException(java.io.IOException) Link(org.apache.tapestry5.http.Link)

Example 39 with Response

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

the class AjaxLinkComponentEventResultProcessor method processResultValue.

public void processResultValue(Link value) throws IOException {
    JSONObject response = new JSONObject();
    response.in(InternalConstants.PARTIAL_KEY).put("redirectURL", value.toRedirectURI());
    masterProcessor.processResultValue(response);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Example 40 with Response

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

the class AjaxPageNameComponentEventResultProcessor method processResultValue.

/**
 * Obtains a page render {@link org.apache.tapestry5.http.Link} for the named, then builds a JSON response for the
 * client.
 *
 * @param value
 *            page name
 * @throws IOException
 */
public void processResultValue(String value) throws IOException {
    Link link = linkSource.createPageRenderLink(value, false);
    masterProcessor.processResultValue(link);
}
Also used : Link(org.apache.tapestry5.http.Link)

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