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);
}
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);
}
}
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;
}
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;
}
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();
}
Aggregations