Search in sources :

Example 1 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler 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 RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler 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 RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler 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 RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class ModalWindow method getWindowOpenJavaScript.

/**
 * Returns the javascript used to open the window. Subclass
 * {@link #postProcessSettings(AppendingStringBuffer)} to modify the JavaScript if needed.
 *
 * See WICKET-12
 *
 * @return javascript that opens the window
 */
protected final String getWindowOpenJavaScript() {
    JSONObject settings = new JSONObject();
    settings.put("minWidth", getMinimalWidth());
    settings.put("minHeight", getMinimalHeight());
    settings.put("className", getCssClassName());
    settings.put("width", getInitialWidth());
    if ((isUseInitialHeight() == true) || (isCustomComponent() == false)) {
        settings.put("height", getInitialHeight());
    } else {
        settings.put("height", (Object) null);
    }
    settings.put("resizable", isResizable());
    if (isResizable() == false) {
        settings.put("widthUnit", getWidthUnit());
        settings.put("heightUnit", getHeightUnit());
    }
    if (isCustomComponent() == false) {
        Page page = createPage();
        if (page == null) {
            throw new WicketRuntimeException("Error creating page for modal dialog.");
        }
        CharSequence pageUrl;
        RequestCycle requestCycle = RequestCycle.get();
        page.getSession().getPageManager().touchPage(page);
        if (page.isPageStateless()) {
            pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
        } else {
            IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
            pageUrl = requestCycle.urlFor(handler);
        }
        settings.put("src", pageUrl);
    } else {
        settings.put("element", new JSONFunction("document.getElementById(\"" + getContentMarkupId() + "\")"));
    }
    if (getCookieName() != null) {
        settings.put("cookieId", getCookieName());
    }
    String title = getTitle() != null ? getTitle().getObject() : null;
    if (title != null) {
        settings.put("title", getDefaultModelObjectAsString(title));
    }
    if (getMaskType() == MaskType.TRANSPARENT) {
        settings.put("mask", "transparent");
    } else if (getMaskType() == MaskType.SEMI_TRANSPARENT) {
        settings.put("mask", "semi-transparent");
    }
    settings.put("autoSize", autoSize);
    settings.put("unloadConfirmation", showUnloadConfirmation());
    // set true if we set a windowclosedcallback
    boolean haveCloseCallback = false;
    // notification request
    if (windowClosedCallback != null) {
        WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
        settings.put("onClose", new JSONFunction("function() { " + behavior.getCallbackScript() + " }"));
        haveCloseCallback = true;
    }
    // close window property (thus cleaning the shown flag)
    if ((closeButtonCallback != null) || (haveCloseCallback == false)) {
        CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
        settings.put("onCloseButton", new JSONFunction("function() { " + behavior.getCallbackScript() + "; return false; }"));
    }
    postProcessSettings(settings);
    AppendingStringBuffer buffer = new AppendingStringBuffer(500);
    buffer.append("var settings = ");
    buffer.append(settings.toString());
    buffer.append(";");
    buffer.append(getShowJavaScript());
    return buffer.toString();
}
Also used : AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Page(org.apache.wicket.Page) JSONFunction(org.apache.wicket.ajax.json.JSONFunction) JSONObject(com.github.openjson.JSONObject) PageProvider(org.apache.wicket.core.request.handler.PageProvider)

Example 5 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class RequestCycle method setResponsePage.

/**
 * Convenience method for setting next page to be rendered.
 *
 * @param pageClass
 *              The class of the page to render
 * @param parameters
 *              The query parameters for the page to be rendered
 * @param redirectPolicy
 *              The policy to use when deciding whether to redirect or not
 */
public void setResponsePage(Class<? extends IRequestablePage> pageClass, PageParameters parameters, RenderPageRequestHandler.RedirectPolicy redirectPolicy) {
    IPageProvider provider = new PageProvider(pageClass, parameters);
    scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(provider, redirectPolicy));
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider)

Aggregations

RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)75 IRequestHandler (org.apache.wicket.request.IRequestHandler)64 Test (org.junit.Test)61 Url (org.apache.wicket.request.Url)50 PageProvider (org.apache.wicket.core.request.handler.PageProvider)36 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)32 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)19 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)16 MockPage (org.apache.wicket.MockPage)13 Request (org.apache.wicket.request.Request)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2