Search in sources :

Example 91 with IRequestHandler

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

the class ResourceMapperTest method invalidPathIsEmpty.

/**
 * testInvalidPathIsEmpty()
 */
@Test
public void invalidPathIsEmpty() {
    IRequestHandler requestHandler = mapper.mapRequest(createRequest(""));
    assertNull(requestHandler);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Test(org.junit.Test)

Example 92 with IRequestHandler

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

the class ResourceMapperTest method invalidPathIsTooShort.

/**
 * testInvalidPathIsTooShort()
 */
@Test
public void invalidPathIsTooShort() {
    IRequestHandler requestHandler = mapper.mapRequest(createRequest("test"));
    assertNull(requestHandler);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Test(org.junit.Test)

Example 93 with IRequestHandler

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

the class DefaultExceptionMapper method internalMap.

/**
 * Maps exceptions to their corresponding {@link IRequestHandler}.
 *
 * @param e
 * 			the current exception
 * @return the {@link IRequestHandler} for the current exception
 */
private IRequestHandler internalMap(Exception e) {
    final Application application = Application.get();
    // check if we are processing an Ajax request and if we want to invoke the failure handler
    if (isProcessingAjaxRequest()) {
        switch(application.getExceptionSettings().getAjaxErrorHandlingStrategy()) {
            case INVOKE_FAILURE_HANDLER:
                return new ErrorCodeRequestHandler(500);
        }
    }
    IRequestHandler handleExpectedExceptions = mapExpectedExceptions(e, application);
    if (handleExpectedExceptions != null) {
        return handleExpectedExceptions;
    }
    return mapUnexpectedExceptions(e, application);
}
Also used : ErrorCodeRequestHandler(org.apache.wicket.request.http.handler.ErrorCodeRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler)

Example 94 with IRequestHandler

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

the class RequestCycleListenerTest method basicOperations.

/**
 * @throws Exception
 */
@Test
public void basicOperations() throws Exception {
    IncrementingListener incrementingListener = new IncrementingListener();
    Application.get().getRequestCycleListeners().add(incrementingListener);
    RequestCycle cycle = newRequestCycle((RuntimeException) null);
    incrementingListener.assertValues(0, 0, 0, 0, 0, 0);
    assertValues(0, 0, 0);
    cycle.processRequestAndDetach();
    // 0 exceptions mapped
    incrementingListener.assertValues(1, 1, 1, 1, 0, 1);
    // 0 exceptions mapped
    assertValues(0, 1, 1);
    // TEST WITH TWO LISTENERS
    cycle = newRequestCycle((RuntimeException) null);
    cycle.getListeners().add(incrementingListener);
    cycle.processRequestAndDetach();
    // 0 exceptions mapped, all other 2 due to two listeners
    incrementingListener.assertValues(2, 2, 2, 2, 0, 2);
    // 0 exceptions mapped
    assertValues(0, 1, 1);
    // TEST WITH TWO LISTENERS AND AN EXCEPTION DURING RESPONSE
    cycle = newRequestCycle(new RuntimeException("testing purposes only"));
    cycle.getListeners().add(incrementingListener);
    cycle.processRequestAndDetach();
    // 0 executed
    incrementingListener.assertValues(2, 2, 2, 0, 2, 2);
    // 1 exception mapped, 0 responded
    assertValues(1, 0, 1);
    // TEST A REPLACE EXCEPTION DURING RESPONSE
    IRequestHandler replacement = new IRequestHandler() {

        @Override
        public void respond(IRequestCycle requestCycle) {
            responses++;
        }

        @Override
        public void detach(IRequestCycle requestCycle) {
            detaches++;
        }
    };
    cycle = newRequestCycle(new ReplaceHandlerException(replacement, true));
    cycle.scheduleRequestHandlerAfterCurrent(new IRequestHandler() {

        @Override
        public void respond(IRequestCycle requestCycle) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void detach(IRequestCycle requestCycle) {
            throw new UnsupportedOperationException();
        }
    });
    cycle.processRequestAndDetach();
    // 2 resolved, 1 executed, 0 exception mapped
    incrementingListener.assertValues(1, 1, 2, 1, 0, 1);
    // 0 exception mapped, 1 responded, 2 detached
    assertValues(0, 1, 2);
    // TEST A REPLACE EXCEPTION DURING RESPONSE
    cycle = newRequestCycle(new ReplaceHandlerException(replacement, false));
    cycle.scheduleRequestHandlerAfterCurrent(new IRequestHandler() {

        @Override
        public void respond(IRequestCycle requestCycle) {
            responses++;
        }

        @Override
        public void detach(IRequestCycle requestCycle) {
            detaches++;
        }
    });
    cycle.processRequestAndDetach();
    // 2 resolved, 2 executed, 0 exception mapped
    incrementingListener.assertValues(1, 1, 3, 2, 0, 1);
    // 0 exception mapped, 2 responded, 3 detached
    assertValues(0, 2, 3);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException) IRequestCycle(org.apache.wicket.request.IRequestCycle) IRequestCycle(org.apache.wicket.request.IRequestCycle) Test(org.junit.Test)

Example 95 with IRequestHandler

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

the class ContextRelativeResourceCachingTest method mapHandler.

/**
 */
@Test
public void mapHandler() {
    ContextRelativeResource resource = new ContextRelativeResource("/style.css");
    init(resource, "/test/resource");
    Request request = createRequest("test/resource-version-123?bla=4567");
    final IRequestHandler handler = tester.getApplication().getRootRequestMapper().mapRequest(request);
    assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class));
    assertEquals(((ResourceReferenceRequestHandler) handler).getResource(), resource);
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) ContextRelativeResource(org.apache.wicket.request.resource.ContextRelativeResource) Test(org.junit.Test)

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