use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class BehaviorRequestTest method urlForBehavior.
private String urlForBehavior(Behavior behaviorUnderTest) {
final int index = page.container.getBehaviorId(behaviorUnderTest);
final IPageAndComponentProvider provider = new PageAndComponentProvider(page, page.container);
final IRequestHandler handler = new ListenerRequestHandler(provider, index);
return tester.urlFor(handler).toString();
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class DefaultExceptionMapperResourceBlockedDevModeTest method packageResourceBlockedExceptionDevMode.
/**
* In development mode return http status 500 when a resource is blocked
* so the developer can see the problem early (the exception will be displayed
* on the screen)
*/
@Test
public void packageResourceBlockedExceptionDevMode() {
DefaultExceptionMapper mapper = new DefaultExceptionMapper();
PackageResource.PackageResourceBlockedException x = new PackageResource.PackageResourceBlockedException("test");
IRequestHandler handler = mapper.map(x);
assertThat(handler, instanceOf(ErrorCodeRequestHandler.class));
ErrorCodeRequestHandler errorCodeRequestHandler = (ErrorCodeRequestHandler) handler;
assertThat(errorCodeRequestHandler.getErrorCode(), is(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class DefaultUnauthorizedResourceRequestListener method onUnauthorizedRequest.
@Override
public void onUnauthorizedRequest(IResource resource, PageParameters parameters) {
RequestCycle cycle = RequestCycle.get();
if (cycle != null) {
IRequestHandler handler = new ErrorCodeRequestHandler(HttpServletResponse.SC_FORBIDDEN, createErrorMessage(resource, parameters));
cycle.replaceAllRequestHandlers(handler);
}
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class AbstractWebSocketProcessor method broadcastMessage.
/**
* Exports the Wicket thread locals and broadcasts the received message from the client to all
* interested components and behaviors in the page with id {@code #pageId}
* <p>
* Note: ConnectedMessage and ClosedMessage messages are notification-only. I.e. whatever the
* components/behaviors write in the WebSocketRequestHandler will be ignored because the protocol
* doesn't expect response from the user.
* </p>
*
* @param message
* the message to broadcast
*/
public final void broadcastMessage(final IWebSocketMessage message) {
IKey key = getRegistryKey();
IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
if (connection != null && (connection.isOpen() || message instanceof ClosedMessage)) {
Application oldApplication = ThreadContext.getApplication();
Session oldSession = ThreadContext.getSession();
RequestCycle oldRequestCycle = ThreadContext.getRequestCycle();
WebResponse webResponse = webSocketSettings.newWebSocketResponse(connection);
try {
WebSocketRequestMapper requestMapper = new WebSocketRequestMapper(application.getRootRequestMapper());
RequestCycle requestCycle = createRequestCycle(requestMapper, webResponse);
ThreadContext.setRequestCycle(requestCycle);
ThreadContext.setApplication(application);
Session session;
if (oldSession == null || message instanceof IWebSocketPushMessage) {
ISessionStore sessionStore = application.getSessionStore();
session = sessionStore.lookup(webRequest);
ThreadContext.setSession(session);
} else {
session = oldSession;
}
IPageManager pageManager = session.getPageManager();
Page page = getPage(pageManager);
if (page != null) {
WebSocketRequestHandler requestHandler = webSocketSettings.newWebSocketRequestHandler(page, connection);
WebSocketPayload payload = createEventPayload(message, requestHandler);
if (!(message instanceof ConnectedMessage || message instanceof ClosedMessage || message instanceof AbortedMessage)) {
requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
}
IRequestHandler broadcastingHandler = new WebSocketMessageBroadcastHandler(pageId, resourceName, payload);
requestMapper.setHandler(broadcastingHandler);
requestCycle.processRequestAndDetach();
} else {
LOG.debug("Page with id '{}' has been expired. No message will be broadcast!", pageId);
}
} catch (Exception x) {
LOG.error("An error occurred during processing of a WebSocket message", x);
} finally {
try {
webResponse.close();
} finally {
ThreadContext.setApplication(oldApplication);
ThreadContext.setRequestCycle(oldRequestCycle);
ThreadContext.setSession(oldSession);
}
}
} else {
LOG.debug("Either there is no connection({}) or it is closed.", connection);
}
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class AjaxRequestHandler method respond.
/**
* @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
*/
@Override
public final void respond(final IRequestCycle requestCycle) {
final RequestCycle rc = (RequestCycle) requestCycle;
final WebResponse response = (WebResponse) requestCycle.getResponse();
if (shouldRedirectToPage(requestCycle)) {
// the page itself has been added to the request target, we simply issue a redirect
// back to the page
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
final String url = rc.urlFor(handler).toString();
response.sendRedirect(url);
return;
}
respondersFrozen = true;
for (ITargetRespondListener listener : respondListeners) {
listener.onTargetRespond(this);
}
final Application app = page.getApplication();
page.send(app, Broadcast.BREADTH, this);
// Determine encoding
final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
// Set content type based on markup type for page
update.setContentType(response, encoding);
// Make sure it is not cached by a client
response.disableCaching();
final StringResponse bodyResponse = new StringResponse();
update.writeTo(bodyResponse, encoding);
CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
response.write(filteredResponse);
}
Aggregations