use of org.apache.wicket.request.Request in project wicket by apache.
the class RequestSettingRequestHandler method respond.
@Override
public void respond(IRequestCycle requestCycle) {
RequestCycle cycle = (RequestCycle) requestCycle;
Request originalRequest = cycle.getRequest();
try {
cycle.setRequest(request);
delegate.respond(requestCycle);
} finally {
cycle.setRequest(originalRequest);
}
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class BookmarkableMapperTest method decode13.
/**
* WICKET-5071
*
* Decodes a request to
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
* /com.example.MyPage when the current base url is
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()} /
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
*/
@Test
public void decode13() {
final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME);
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
StringBuilder url = new StringBuilder();
url.append(context.getBookmarkableIdentifier()).append('/').append(PAGE_CLASS_NAME);
return Url.parse(url.toString());
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
assertNotNull("A handler should be resolved for relative url to a bookmarkable page url!", handler);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class CryptoMapperTest method resourceReferenceWithModifiedSegments.
/**
* Relative ResourceReferences, WICKET-3514
*/
@Test
public void resourceReferenceWithModifiedSegments() {
PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
url.getSegments().remove(url.getSegments().size() - 1);
url.getSegments().add("modified-crypt.txt");
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class));
ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
assertEquals(getClass(), handler.getResourceReference().getScope());
assertEquals("crypt/modified-crypt.txt", handler.getResourceReference().getName());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class CryptoMapperTest method pageParameters.
/**
* Tests that named and indexed parameters are properly (en|de)crypted
*/
@Test
public void pageParameters() {
String expectedEncrypted = "L7ExSNbPC4sb6TPJDblCAopL53TWmZP5y7BQEaJSJAC05HXod5M5U7gT2yNT0lK5L6L09ZAOoZkGyUhseyPrC4S5tqUUrV6zipc4_Ni877FDOOoE5C_Cd7YCyK1xSScpVhno6LeBz2wiu5oWyf7hB1RKcv6zkhEBmbx8vU7K7-e4xe1_LO8Y3fhEjMSQyU9BVh7Uz4HKzkR2OxFo5LaDzQ/L7E59/yPr6a/5L6ae/OxF2c";
PageParameters expectedParameters = new PageParameters();
expectedParameters.add("namedKey1", "namedValue1");
expectedParameters.add("namedKey2", "namedValue2");
expectedParameters.set(0, "indexedValue1");
expectedParameters.set(1, "indexedValue2");
RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(Page2.class, expectedParameters));
Url url = mapper.mapHandler(renderPageRequestHandler);
assertEquals(expectedEncrypted, url.toString());
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
assertEquals(Page2.class, handler.getPageClass());
PageParameters actualParameters = handler.getPageParameters();
assertEquals(expectedParameters, actualParameters);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class CryptoMapperTest method homePageWithNonEncryptedQueryParameters.
/**
* Verifies that the home page can be reached with non-encrypted query parameters.
* https://issues.apache.org/jira/browse/WICKET-4345
*
* Also, test that the URL for the home page with non-encrypted parameters is not encrypted, to avoid unnecessary redirects.
*/
@Test
public void homePageWithNonEncryptedQueryParameters() {
String expectedEncrypted = "?namedKey1=namedValue1";
PageParameters expectedParameters = new PageParameters();
expectedParameters.add("namedKey1", "namedValue1");
RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(tester.getApplication().getHomePage(), expectedParameters));
Url url = mapper.mapHandler(renderPageRequestHandler);
assertEquals(expectedEncrypted, url.toString());
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
assertEquals(tester.getApplication().getHomePage(), handler.getPageClass());
StringValue queryParam = handler.getPageParameters().get("namedKey1");
assertEquals("namedValue1", queryParam.toOptionalString());
}
Aggregations