Search in sources :

Example 16 with IRequestHandler

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();
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) IPageAndComponentProvider(org.apache.wicket.core.request.handler.IPageAndComponentProvider) IPageAndComponentProvider(org.apache.wicket.core.request.handler.IPageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler)

Example 17 with IRequestHandler

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));
}
Also used : PackageResource(org.apache.wicket.request.resource.PackageResource) IRequestHandler(org.apache.wicket.request.IRequestHandler) ErrorCodeRequestHandler(org.apache.wicket.request.http.handler.ErrorCodeRequestHandler) Test(org.junit.Test)

Example 18 with IRequestHandler

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);
    }
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) ErrorCodeRequestHandler(org.apache.wicket.request.http.handler.ErrorCodeRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 19 with IRequestHandler

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);
    }
}
Also used : IPageManager(org.apache.wicket.page.IPageManager) WebResponse(org.apache.wicket.request.http.WebResponse) ISessionStore(org.apache.wicket.session.ISessionStore) IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) ClosedMessage(org.apache.wicket.protocol.ws.api.message.ClosedMessage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) WebSocketPayload(org.apache.wicket.protocol.ws.api.event.WebSocketPayload) IWebSocketPushMessage(org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage) ConnectedMessage(org.apache.wicket.protocol.ws.api.message.ConnectedMessage) AbortedMessage(org.apache.wicket.protocol.ws.api.message.AbortedMessage) IKey(org.apache.wicket.protocol.ws.api.registry.IKey) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.wicket.Session)

Example 20 with IRequestHandler

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);
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestCycle(org.apache.wicket.request.IRequestCycle) PageProvider(org.apache.wicket.core.request.handler.PageProvider) StringResponse(org.apache.wicket.response.StringResponse) Application(org.apache.wicket.Application)

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