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"));
}
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));
}
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));
}
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();
}
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));
}
Aggregations