Search in sources :

Example 1 with IRequestMapper

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

the class HttpsMapperTest method mapRequestWithCustomPorts.

@Test
public void mapRequestWithCustomPorts() {
    IRequestMapper delegate = mock(IRequestMapper.class);
    HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig(10, 20));
    ServletWebRequest request = mock(ServletWebRequest.class);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(request.getContainerRequest()).thenReturn(req);
    // https handler on http request, redirect to https
    setupRequest(req, "http", "localhost", 10, "/ctx", "foo=bar");
    IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
    when(delegate.mapRequest(request)).thenReturn(handler);
    IRequestHandler resolved = mapper.mapRequest(request);
    assertThat(resolved, is(instanceOf(RedirectHandler.class)));
    assertThat(((RedirectHandler) resolved).getUrl(), is("https://localhost:20/ctx?foo=bar"));
    // http handler on http request, return the original handler
    handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
    reset(delegate);
    when(delegate.mapRequest(request)).thenReturn(handler);
    setupRequest(req, "https", "localhost", 20, "/ctx", "foo=bar");
    resolved = mapper.mapRequest(request);
    assertThat(resolved, is(instanceOf(RedirectHandler.class)));
    assertThat(((RedirectHandler) resolved).getUrl(), is("http://localhost:10/ctx?foo=bar"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Test(org.junit.Test)

Example 2 with IRequestMapper

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

the class HttpsMapperTest method getDesiredSchemeOfHandler.

@Test
public void getDesiredSchemeOfHandler() {
    IRequestMapper delegate = mock(IRequestMapper.class);
    HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
    IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
    assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTPS));
    handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
    assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTP));
    handler = mock(IRequestHandler.class);
    assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.ANY));
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) Test(org.junit.Test)

Example 3 with IRequestMapper

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

the class HttpsMapperTest method mapHandler.

@Test
public void mapHandler() {
    IRequestMapper delegate = mock(IRequestMapper.class);
    HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
    ServletWebRequest request = mock(ServletWebRequest.class);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(request.getContainerRequest()).thenReturn(req);
    // rendering url to https page on http, set protocol
    IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
    Url url = new Url();
    when(delegate.mapHandler(handler)).thenReturn(url);
    when(req.getScheme()).thenReturn("http");
    mapper.mapHandler(handler, request);
    assertThat(url.getProtocol(), is("https"));
    assertThat(url.getPort(), is(443));
    // render url to http page on http, ignore protocol
    handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
    url = new Url();
    reset(delegate);
    when(delegate.mapHandler(handler)).thenReturn(url);
    when(req.getScheme()).thenReturn("http");
    mapper.mapHandler(handler, request);
    assertThat(url.getProtocol(), is(nullValue()));
    // render url to http page on https, set protocol
    handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
    url = new Url();
    reset(delegate);
    when(delegate.mapHandler(handler)).thenReturn(url);
    when(req.getScheme()).thenReturn("https");
    mapper.mapHandler(handler, request);
    assertThat(url.getProtocol(), is("http"));
    assertThat(url.getPort(), is(80));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 4 with IRequestMapper

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

the class PageRequestHandlerTrackerTest method trackPagesWithMapperDelegate.

/**
 * Uses PageRequestHandlerTracker to check last IRequestHandler encapsulated in IRequestHandlerDelegate
 */
@Test
public void trackPagesWithMapperDelegate() {
    IRequestMapper mapper = tester.getApplication().getRootRequestMapper();
    tester.getApplication().setRootRequestMapper(new MapperDelegate(mapper));
    tester.startPage(new PageA());
    tester.getApplication().setRootRequestMapper(mapper);
}
Also used : IRequestMapperDelegate(org.apache.wicket.request.mapper.IRequestMapperDelegate) IRequestMapper(org.apache.wicket.request.IRequestMapper) Test(org.junit.Test)

Example 5 with IRequestMapper

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

the class MountedMapperTest method construct2.

/**
 * Overriding mounting on '/' (see HomePageMapper) should be possible
 */
@Test
public void construct2() {
    IRequestMapper homePageMapper = new MountedMapper("/", MockPage.class);
    assertNotNull(homePageMapper);
}
Also used : IRequestMapper(org.apache.wicket.request.IRequestMapper) Test(org.junit.Test)

Aggregations

IRequestMapper (org.apache.wicket.request.IRequestMapper)14 Test (org.junit.Test)8 IRequestHandler (org.apache.wicket.request.IRequestHandler)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)4 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)4 Request (org.apache.wicket.request.Request)3 Url (org.apache.wicket.request.Url)3 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)2 Response (org.apache.wicket.request.Response)2 ICompoundRequestMapper (org.apache.wicket.request.mapper.ICompoundRequestMapper)2 IRequestMapperDelegate (org.apache.wicket.request.mapper.IRequestMapperDelegate)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 HomePageMapper (org.apache.wicket.core.request.mapper.HomePageMapper)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1 ReplaceHandlerException (org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)1 WebRequest (org.apache.wicket.request.http.WebRequest)1