use of org.apache.wicket.request.http.WebRequest in project wicket by apache.
the class AbstractResource method setRequestMetaData.
/**
* Reads the plain request header information and applies enriched information as meta data to
* the current request. Those information are available for the whole request cycle.
*
* @param attributes
* the attributes to get the plain request header information
*/
protected void setRequestMetaData(Attributes attributes) {
Request request = attributes.getRequest();
if (request instanceof WebRequest) {
WebRequest webRequest = (WebRequest) request;
setRequestRangeMetaData(webRequest);
}
}
use of org.apache.wicket.request.http.WebRequest in project wicket by apache.
the class WicketFilter method processRequest.
/**
* This is Wicket's main method to execute a request
*
* @param request
* @param response
* @param chain
* @return false, if the request could not be processed
* @throws IOException
* @throws ServletException
*/
boolean processRequest(ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final ThreadContext previousThreadContext = ThreadContext.detach();
// Assume we are able to handle the request
boolean res = true;
final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader newClassLoader = getClassLoader();
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
try {
if (previousClassLoader != newClassLoader) {
Thread.currentThread().setContextClassLoader(newClassLoader);
}
// Make sure getFilterPath() gets called before checkIfRedirectRequired()
String filterPath = getFilterPath(httpServletRequest);
if (filterPath == null) {
throw new IllegalStateException("filter path was not configured");
}
if (shouldIgnorePath(httpServletRequest)) {
log.debug("Ignoring request {}", httpServletRequest.getRequestURL());
if (chain != null) {
// invoke next filter from within Wicket context
chain.doFilter(request, response);
}
return false;
}
if ("OPTIONS".equalsIgnoreCase(httpServletRequest.getMethod())) {
// handle the OPTIONS request outside of normal request processing.
// wicket pages normally only support GET and POST methods, but resources and
// special pages acting like REST clients can also support other methods, so
// we include them all.
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse.setHeader("Allow", "GET,POST,OPTIONS,PUT,HEAD,PATCH,DELETE,TRACE");
httpServletResponse.setHeader("Content-Length", "0");
return true;
}
String redirectURL = checkIfRedirectRequired(httpServletRequest);
if (redirectURL == null) {
// No redirect; process the request
ThreadContext.setApplication(application);
WebRequest webRequest = application.createWebRequest(httpServletRequest, filterPath);
WebResponse webResponse = application.createWebResponse(webRequest, httpServletResponse);
RequestCycle requestCycle = application.createRequestCycle(webRequest, webResponse);
res = processRequestCycle(requestCycle, webResponse, httpServletRequest, httpServletResponse, chain);
} else {
if (Strings.isEmpty(httpServletRequest.getQueryString()) == false) {
redirectURL += "?" + httpServletRequest.getQueryString();
}
try {
// send redirect - this will discard POST parameters if the request is POST
// - still better than getting an error because of lacking trailing slash
httpServletResponse.sendRedirect(httpServletResponse.encodeRedirectURL(redirectURL));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} finally {
ThreadContext.restore(previousThreadContext);
if (newClassLoader != previousClassLoader) {
Thread.currentThread().setContextClassLoader(previousClassLoader);
}
if (response.isCommitted() && httpServletRequest.isAsyncStarted() == false) {
response.flushBuffer();
}
}
return res;
}
use of org.apache.wicket.request.http.WebRequest in project wicket by apache.
the class WebPageRenderer method isAjax.
protected boolean isAjax(RequestCycle requestCycle) {
boolean isAjax = false;
Request request = requestCycle.getRequest();
if (request instanceof WebRequest) {
WebRequest webRequest = (WebRequest) request;
isAjax = webRequest.isAjax();
}
return isAjax;
}
use of org.apache.wicket.request.http.WebRequest in project wicket by apache.
the class ListenerRequestHandler method respond.
@Override
public void respond(final IRequestCycle requestCycle) {
final IRequestablePage page = getPage();
final boolean freshPage = pageComponentProvider.doesProvideNewPage();
final boolean isAjax = ((WebRequest) requestCycle.getRequest()).isAjax();
IRequestableComponent component;
try {
component = getComponent();
} catch (ComponentNotFoundException e) {
// either the page is stateless and the component we are looking for is not added in the
// constructor
// or the page is stateful+stale and a new instances was created by pageprovider
// we denote this by setting component to null
component = null;
}
if ((component == null && !freshPage) || (component != null && component.getPage() != page)) {
throw new ComponentNotFoundException("Component '" + getComponentPath() + "' has been removed from page.");
}
if (page instanceof Page) {
// initialize the page to be able to check whether it is stateless
((Page) page).internalInitialize();
}
RedirectPolicy policy = page.isPageStateless() ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
boolean blockIfExpired = component != null && !component.canCallListenerAfterExpiry();
boolean lateComponent = component == null && freshPage;
if ((pageComponentProvider.wasExpired() && blockIfExpired) || lateComponent) {
if (LOG.isDebugEnabled()) {
LOG.debug("An IRequestListener was called but its page/component({}) couldn't be resolved. " + "Scheduling re-create of the page and ignoring the listener interface...", getComponentPath());
}
if (isAjax) {
policy = RedirectPolicy.ALWAYS_REDIRECT;
}
requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
return;
}
invokeListener(requestCycle, policy, isAjax);
}
use of org.apache.wicket.request.http.WebRequest in project wicket by apache.
the class AjaxRequestHandler method getLastFocusedElementId.
/**
* @return the markup id of the focused element in the browser
*/
@Override
public String getLastFocusedElementId() {
WebRequest request = (WebRequest) page.getRequest();
String id = request.getHeader("Wicket-FocusedElementId");
return Strings.isEmpty(id) ? null : id;
}
Aggregations