Search in sources :

Example 11 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class RequestCycle method handleException.

/**
 * Return {@link IRequestHandler} for the given exception.
 *
 * @param e exception to handle
 * @return RequestHandler instance
 *
 * @see IRequestCycleListener#onException(RequestCycle, Exception)
 * @see IExceptionMapper#map(Exception)
 */
protected IRequestHandler handleException(final Exception e) {
    if (Application.exists() && Application.get().usesDevelopmentConfig()) {
        /*
			 * Call out the fact that we are processing an exception in a loud way, helps to notice
			 * them when developing even if they get wrapped or processed in a custom handler.
			 */
        logExtra.warn("********************************");
        logExtra.warn("Handling the following exception", e);
        logExtra.warn("********************************");
    }
    IRequestHandler handler = listeners.onException(this, e);
    if (handler != null) {
        return handler;
    }
    return exceptionMapper.map(e);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler)

Example 12 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class WebPageRenderer method renderPage.

/**
 * Renders page to a {@link BufferedWebResponse}. All URLs in page will be rendered relative to
 * <code>targetUrl</code>
 *
 * @param targetUrl
 * @param requestCycle
 * @return BufferedWebResponse containing page body
 */
protected BufferedWebResponse renderPage(Url targetUrl, RequestCycle requestCycle) {
    // get the page before checking for a scheduled request handler because
    // the page may call setResponsePage in its constructor
    IRequestablePage requestablePage = getPage();
    IRequestHandler scheduled = requestCycle.getRequestHandlerScheduledAfterCurrent();
    if (scheduled != null) {
        // no need to render
        return null;
    }
    // keep the original response
    final WebResponse originalResponse = (WebResponse) requestCycle.getResponse();
    // buffered web response for page
    BufferedWebResponse response = new BufferedWebResponse(originalResponse);
    // keep the original base URL
    Url originalBaseUrl = requestCycle.getUrlRenderer().setBaseUrl(targetUrl);
    try {
        requestCycle.setResponse(response);
        requestablePage.renderPage();
        if (requestCycle.getRequestHandlerScheduledAfterCurrent() != null) {
            // This is a special case.
            // During page render another request handler got scheduled and will want to
            // overwrite the response, so we need to let it.
            // Just preserve the meta data headers. Clear the initial actions because they are
            // already copied into the new response's actions
            originalResponse.reset();
            response.writeMetaData(originalResponse);
            return null;
        } else {
            return response;
        }
    } finally {
        // restore original response and base URL
        requestCycle.setResponse(originalResponse);
        requestCycle.getUrlRenderer().setBaseUrl(originalBaseUrl);
    }
}
Also used : BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) WebResponse(org.apache.wicket.request.http.WebResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url)

Example 13 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class HttpsMapper method mapRequest.

@Override
public final IRequestHandler mapRequest(Request request) {
    IRequestHandler handler = delegate.mapRequest(request);
    Scheme desired = getDesiredSchemeFor(handler);
    Scheme current = getSchemeOf(request);
    if (!desired.isCompatibleWith(current)) {
        // we are currently on the wrong scheme for this handler
        // construct a url for the handler on the correct scheme
        String url = createRedirectUrl(handler, request, desired);
        // replace handler with one that will redirect to the created url
        handler = createRedirectHandler(url);
    }
    return handler;
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler)

Example 14 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class CustomHomeMapper method mapRequest.

/**
 * Removes the leading segment if it a valid Locale
 *
 * @see org.apache.wicket.core.request.mapper.HomePageMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    IRequestHandler requestHandler = null;
    Url url = request.getUrl();
    List<String> segments = url.getSegments();
    if (segments.size() == 1) {
        String localeAsString = segments.get(0);
        Locale locale = LocaleHelper.parseLocale(localeAsString);
        if (locale != null) {
            Session.get().setLocale(locale);
            segments.remove(0);
            Request requestWithoutLocale = request.cloneWithUrl(url);
            requestHandler = super.mapRequest(requestWithoutLocale);
        }
    }
    return requestHandler;
}
Also used : Locale(java.util.Locale) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url)

Example 15 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class BaseWicketTester method startPage.

/**
 * Renders the page specified by given {@link IPageProvider}. After render the page instance can
 * be retrieved using {@link #getLastRenderedPage()} and the rendered document will be available
 * in {@link #getLastResponse()}.
 *
 * Depending on {@link RenderStrategy} invoking this method can mean that a redirect will happen
 * before the actual render.
 *
 * @param pageProvider
 * @return last rendered page
 */
public Page startPage(final IPageProvider pageProvider) {
    // should be null for Pages
    componentInPage = null;
    // prepare request
    request.setURL(request.getContextPath() + request.getServletPath() + "/");
    IRequestHandler handler = new RenderPageRequestHandler(pageProvider);
    // process request
    processRequest(request, handler);
    // The page rendered
    return getLastRenderedPage();
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler)

Aggregations

IRequestHandler (org.apache.wicket.request.IRequestHandler)188 Test (org.junit.Test)159 Url (org.apache.wicket.request.Url)138 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)65 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)47 PageProvider (org.apache.wicket.core.request.handler.PageProvider)45 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)32 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)28 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)25 Request (org.apache.wicket.request.Request)25 MockPage (org.apache.wicket.MockPage)23 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)20 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)17 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)17 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)16 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)11 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)10 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)8 Page (org.apache.wicket.Page)6