Here is a workaround which uses only Wicket API (no need of java.net.URI):
String url = urlFor(new MyResRef(), null).toString();
UrlRenderer urlRenderer = getRequestCycle().getUrlRenderer();
Url baseUrl = new Url(urlRenderer.getBaseUrl());
baseUrl.resolveRelative(Url.parse(url));
String full = urlRenderer.renderFullUrl(baseUrl);
but here what I don't like is that Url#resolveRelative() modifies
"this", so I have to be careful to not touch the original "baseUrl".
I think #resolveRelative() should return a completely new Url that is
resolved from "this" with the passed "relative", but neither "this"
nor the passed argument should be modified anyhow.
WDYT ?
On Tue, Apr 24, 2012 at 1:00 PM, Martin Grigorov <[email protected]> wrote:
> Hi,
>
> I just hit another problem with UrlRenderer and full urls.
>
> MyApp#init():
> mountPage("/one/two/three", MyPage.class);
> mountResource("/one/four", new MyResRef());
>
> In a MyPage's #renderHead() I have something like:
>
> String url = urlFor(new MyResRef(), null).toString();
> Url parsedUrl = Url.parse(url);
> String fullUrl =
> getRequestCycle().getUrlRenderer().renderFullUrl(parsedUrl);
>
> And 'fullUrl' is : http://localhost:8080/../four
>
> I checked #renderFullUrl()'s source and indeed it expects proper
> filter path relative url just to join it with
> http://host/port/contextPath/filterPath
>
> For now my workaround is :
> String url = urlFor(new MyResRef(), null).toString();
> UrlRenderer urlRenderer = getRequestCycle().getUrlRenderer();
> String baseUrl = urlRenderer.getBaseUrl().toString();
> URI baseUri = URI.create(baseUrl);
> URI resolved = baseUri.resolve(url);
> String fullUrl =
> urlRenderer.renderFullUrl(Url.parse(resolved.toString()));
>
> And this produces : http://localhost:8080/one/four as I'd like it.
>
> The question is: Is there a bug in UrlRenderer#renderFullUrl() or this
> is how it should behave ?
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com