use of org.apache.wicket.request.UrlRenderer in project wicket by apache.
the class ServletWebResponseTest method encodeRedirectAbsoluteUrl.
/**
* WICKET-5582 absolute URLs stay absolute after encoding
*/
@Test
public void encodeRedirectAbsoluteUrl() {
final String url = "http://localhost:8080/path";
ServletWebRequest webRequest = mock(ServletWebRequest.class);
when(webRequest.isAjax()).thenReturn(Boolean.FALSE);
Url baseUrl = Url.parse("./baseUrl");
baseUrl.setProtocol("http");
baseUrl.setHost("someHost");
baseUrl.setPort(80);
when(webRequest.getClientUrl()).thenReturn(baseUrl);
UrlRenderer renderer = new UrlRenderer(webRequest);
RequestCycle requestCycle = mock(RequestCycle.class);
ThreadContext.setRequestCycle(requestCycle);
when(requestCycle.getUrlRenderer()).thenReturn(renderer);
HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
when(httpServletResponse.encodeRedirectURL(Matchers.eq(url))).thenReturn(url + ";foo");
ServletWebResponse webResponse = new ServletWebResponse(webRequest, httpServletResponse);
assertEquals(url + ";foo", webResponse.encodeRedirectURL(url));
}
use of org.apache.wicket.request.UrlRenderer in project wicket by apache.
the class ServletWebResponse method encodeURL.
@Override
public String encodeURL(CharSequence url) {
Args.notNull(url, "url");
UrlRenderer urlRenderer = getUrlRenderer();
Url originalUrl = Url.parse(url);
/*
WICKET-4645 - always pass absolute url to the web container for encoding
because when REDIRECT_TO_BUFFER is in use Wicket may render PageB when
PageA is actually the requested one and the web container cannot resolve
the base url properly
*/
String fullUrl = urlRenderer.renderFullUrl(originalUrl);
String encodedFullUrl = httpServletResponse.encodeURL(fullUrl);
final String encodedUrl;
if (originalUrl.isFull()) {
encodedUrl = encodedFullUrl;
} else {
if (fullUrl.equals(encodedFullUrl)) {
// no encoding happened so just reuse the original url
encodedUrl = url.toString();
} else {
// get the relative url with the jsessionid encoded in it
Url _encoded = Url.parse(encodedFullUrl);
encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
}
}
return encodedUrl;
}
use of org.apache.wicket.request.UrlRenderer in project wicket by apache.
the class ServletWebResponse method encodeRedirectURL.
@Override
public String encodeRedirectURL(CharSequence url) {
Args.notNull(url, "url");
UrlRenderer urlRenderer = getUrlRenderer();
Url originalUrl = Url.parse(url);
/*
* WICKET-4645 - always pass absolute url to the web container for encoding because when
* REDIRECT_TO_BUFFER is in use Wicket may render PageB when PageA is actually the requested
* one and the web container cannot resolve the base url properly
*/
String fullUrl = urlRenderer.renderFullUrl(originalUrl);
String encodedFullUrl = httpServletResponse.encodeRedirectURL(fullUrl);
final String encodedUrl;
if (originalUrl.isFull()) {
encodedUrl = encodedFullUrl;
} else {
if (fullUrl.equals(encodedFullUrl)) {
// no encoding happened so just reuse the original url
encodedUrl = url.toString();
} else {
// get the relative url with the jsessionid encoded in it
Url _encoded = Url.parse(encodedFullUrl);
encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
}
}
return encodedUrl;
}
use of org.apache.wicket.request.UrlRenderer in project wicket by apache.
the class HeaderResponseTest method before.
/**
* Prepare
*/
@Before
public void before() {
final Response realResponse = new StringResponse();
headerResponse = new HeaderResponse() {
@Override
protected Response getRealResponse() {
return realResponse;
}
};
reference = new ResourceReference("testReference") {
private static final long serialVersionUID = 1L;
@Override
public IResource getResource() {
return null;
}
};
RequestCycle requestCycle = mock(RequestCycle.class);
when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
when(requestCycle.find(any())).thenReturn(Optional.empty());
Request request = mock(Request.class);
when(request.getCharset()).thenReturn(Charset.defaultCharset());
when(requestCycle.getRequest()).thenReturn(request);
UrlRenderer urlRenderer = mock(UrlRenderer.class);
when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
ThreadContext.setRequestCycle(requestCycle);
}
use of org.apache.wicket.request.UrlRenderer in project wicket by apache.
the class UrlRendererTest method test6.
/**
*/
@Test
public void test6() {
UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("url/")));
assertEquals("./x?1", r1.renderUrl(Url.parse("url/x?1")));
}
Aggregations