use of org.apache.wicket.request.Url in project wicket by apache.
the class PageProviderTest method testStalePageExceptionOnAjaxRequest.
/**
* Request an old URL in an AJAX request and assert that we have an AJAX response.
*
* @see <a href="https://issues.apache.org/jira/browse/WICKET-3252">WICKET-3252</a>
* @throws ParseException
* @throws ResourceStreamNotFoundException
* @throws IOException
*/
@Test
public void testStalePageExceptionOnAjaxRequest() throws IOException, ResourceStreamNotFoundException, ParseException {
tester.startPage(TestPage.class);
TestPage testPage = (TestPage) tester.getLastRenderedPage();
// cache the old URL
Url firstAjaxLinkUrl = tester.urlFor(testPage.ajaxLink);
// request a new page
tester.clickLink("link");
tester.setExposeExceptions(false);
tester.setFollowRedirects(false);
tester.setUseRequestUrlAsBase(false);
// execute the old URL
executeAjaxUrlWithLastBaseUrl(firstAjaxLinkUrl);
assertTrue(tester.getLastResponseAsString().startsWith("<ajax-response>"));
assertTrue(tester.getLastResponse().isRedirect());
}
use of org.apache.wicket.request.Url in project wicket-orientdb by OrienteerBAP.
the class WicketOrientDbTester method executeUrl.
public String executeUrl(String _url, final String method, final String content, String username, String password) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getApplication(), getHttpSession(), getServletContext()) {
{
setMethod(method);
}
@Override
public ServletInputStream getInputStream() throws IOException {
if (content == null)
return super.getInputStream();
else {
final StringReader sr = new StringReader(content);
return new ServletInputStream() {
@Override
public int read() throws IOException {
return sr.read();
}
};
}
}
};
Url url = Url.parse(_url, Charset.forName(request.getCharacterEncoding()));
request.setUrl(url);
request.setMethod(method);
if (username != null && password != null) {
request.setHeader(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()));
}
if (!processRequest(request)) {
throw new IOException("Request was not sucessfully sent");
}
MockHttpServletResponse response = getLastResponse();
int status = response.getStatus();
if (status >= HttpServletResponse.SC_OK + 100) {
throw new IOException("Code: " + response.getStatus() + " Message: " + response.getErrorMessage() + " Content: " + response.getDocument());
} else {
return response.getDocument();
}
}
use of org.apache.wicket.request.Url in project wicket-orientdb by OrienteerBAP.
the class ReverseProxyResource method mapUrl.
protected HttpUrl mapUrl(Attributes attributes) {
HttpUrl.Builder builder = getBaseUrl(attributes).newBuilder();
WebRequest webRequest = (WebRequest) attributes.getRequest();
Url url = webRequest.getUrl();
PageParameters pageParameters = attributes.getParameters();
for (int i = 0; i < pageParameters.getIndexedCount(); i++) {
builder.addPathSegment(pageParameters.get(i).toString());
}
// builder.addEncodedPathSegments(url.getPath());
builder.fragment(url.getFragment());
builder.encodedQuery(webRequest.asHttpServletRequest().getQueryString());
onMapUrl(attributes, builder);
return builder.build();
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class UrlResourceReferenceMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
Url url = null;
if (requestHandler instanceof ResourceReferenceRequestHandler) {
ResourceReferenceRequestHandler resourceReferenceRequestHandler = (ResourceReferenceRequestHandler) requestHandler;
ResourceReference resourceReference = resourceReferenceRequestHandler.getResourceReference();
while (resourceReference instanceof ResourceBundleReference) {
// unwrap the bundle to render the url for the actual reference
resourceReference = ((ResourceBundleReference) resourceReference).getBundleReference();
}
if (resourceReference instanceof UrlResourceReference) {
UrlResourceReference urlResourceReference = (UrlResourceReference) resourceReference;
url = urlResourceReference.getUrl();
}
}
return url;
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class RestartResponseAtInterceptPageException method getOriginalUrl.
/**
* @return the url of the request when the interception happened or {@code null}
* or {@code null} if there was no interception yet
*/
public static Url getOriginalUrl() {
Url originalUrl = null;
InterceptData data = InterceptData.get();
if (data != null) {
originalUrl = data.getOriginalUrl();
}
return originalUrl;
}
Aggregations