use of org.apache.wicket.core.request.handler.PageAndComponentProvider in project wicket by apache.
the class CryptoMapperTest method mountedPageRequestListenerParameter.
/**
* Tests that PageComponentInfo parameters are encrypted on Mounted pages
*/
@Test
public void mountedPageRequestListenerParameter() {
final String componentPath = "link";
PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, componentPath);
IRequestHandler requestHandler = new ListenerRequestHandler(provider);
Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
assertTrue(plainUrl.toString().startsWith(MOUNTED_URL));
/*
* Do not allow unencrypted request listener urls to mounted pages.
*/
assertNull(mapper.mapRequest(getRequest(plainUrl)));
/*
* Test encryption of request listener parameter.
*/
Url encryptedUrl = mapper.mapHandler(requestHandler);
assertEquals(Url.parse(MOUNTED_URL).getSegments(), encryptedUrl.getSegments());
assertTrue(encryptedUrl.getQueryParameters().size() > 0);
for (Url.QueryParameter qp : encryptedUrl.getQueryParameters()) {
if (Strings.isEmpty(qp.getValue())) {
PageComponentInfo pci = PageComponentInfo.parse(qp.getName());
assertNull("PageComponentInfo query parameter not encrypted", pci);
}
}
requestHandler = mapper.mapRequest(getRequest(encryptedUrl));
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
assertEquals(componentPath, handler.getComponentPath());
assertEquals(Page1.class, handler.getPageClass());
/*
* We anticipate that sometimes multiple cryptomappers will be used. It should still work in these situations.
*/
requestHandler = new CryptoMapper(mapper, tester.getApplication()).mapRequest(getRequest(encryptedUrl));
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
handler = (ListenerRequestHandler) requestHandler;
assertEquals(componentPath, handler.getComponentPath());
assertEquals(Page1.class, handler.getPageClass());
}
use of org.apache.wicket.core.request.handler.PageAndComponentProvider in project wicket by apache.
the class PageInstanceMapper method mapRequest.
/**
* @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
*/
@Override
public IRequestHandler mapRequest(Request request) {
if (matches(request)) {
Url url = request.getUrl();
PageComponentInfo info = getPageComponentInfo(url);
if (info != null && info.getPageInfo().getPageId() != null) {
Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
if (info.getComponentInfo() == null) {
PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
provider.setPageSource(getContext());
// render page
return new RenderPageRequestHandler(provider);
} else {
ComponentInfo componentInfo = info.getComponentInfo();
PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
provider.setPageSource(getContext());
return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
}
}
}
return null;
}
use of org.apache.wicket.core.request.handler.PageAndComponentProvider in project wicket by apache.
the class BaseWicketTester method executeListener.
/**
* Simulates processing URL that invokes an {@link IRequestListener} on a component.
*
* After the listener is invoked the page containing the component will be rendered
* (with an optional redirect - depending on {@link RenderStrategy}).
*
* @param component
* @param listener
*/
public void executeListener(final Component component) {
Args.notNull(component, "component");
// there are two ways to do this. RequestCycle could be forced to call the handler
// directly but constructing and parsing the URL increases the chance of triggering bugs
Page page = component.getPage();
PageAndComponentProvider pageAndComponentProvider = new PageAndComponentProvider(page, component);
IRequestHandler handler = null;
if (page.isPageStateless() || (page.isBookmarkable() && page.wasCreatedBookmarkable())) {
handler = new BookmarkableListenerRequestHandler(pageAndComponentProvider);
} else {
handler = new ListenerRequestHandler(pageAndComponentProvider);
}
Url url = urlFor(handler);
request.setUrl(url);
// Process the request
processRequest(request, null);
}
use of org.apache.wicket.core.request.handler.PageAndComponentProvider in project wicket by apache.
the class BaseWicketTester method invokeListener.
/**
* Simulates invoking an {@link IRequestListener} on a component. As opposed to the
* {@link #executeListener(Component)} method, current request/response objects will be used
*
* After the listener is invoked the page containing the component will be rendered
* (with an optional redirect - depending on {@link RenderStrategy}).
*
* @param component
* @param listener
*/
public void invokeListener(final Component component) {
Args.notNull(component, "component");
// there are two ways to do this. RequestCycle could be forced to call the handler
// directly but constructing and parsing the URL increases the chance of triggering bugs
IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider(component.getPage(), component));
processRequest(handler);
}
use of org.apache.wicket.core.request.handler.PageAndComponentProvider in project wicket by apache.
the class BaseWicketTester method invokeListener.
/**
* Simulates invoking an {@link IRequestListener} on a component. As opposed to the
* {@link #executeListener(Component)} method, current request/response objects will be used
*
* After the listener is invoked the page containing the component will be rendered
* (with an optional redirect - depending on {@link RenderStrategy}).
*
* @param component
* @param listener
*/
public void invokeListener(Component component, final Behavior behavior) {
Args.notNull(component, "component");
Args.notNull(behavior, "behavior");
// there are two ways to do this. RequestCycle could be forced to call the handler
// directly but constructing and parsing the URL increases the chance of triggering bugs
IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider(component.getPage(), component), component.getBehaviorId(behavior));
processRequest(handler);
}
Aggregations