Quantcast

Troubles getting absolute URL using urlFor and renderFullUrl

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Troubles getting absolute URL using urlFor and renderFullUrl

willo
Dear all,

I've got the following issue trying to generate an absolute url that I would like to send via email to users.
I do get a relative url returned from urlFor:  "../email-verification?key=....".
Please note that email-verification is mounted on root using
 
mountPage("email-verification", EmailVerificationPage.class);

I'm using the following code

CharSequence resetUrl = RequestCycle.get().urlFor(pageClass, parameters);
final Url url = Url.parse(resetUrl.toString());
String absolutUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(url);

The problem is that renderFullUrl produces http://host/app/../email-verification?key=....

Wicket is running under /app (as configured in the web.xml filter). Any ideas how to get http://host/app/email-verification?key=.... instead of http://host/app/../email-verification?key=.... ?

Many thanks
Thomas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Troubles getting absolute URL using urlFor and renderFullUrl

willo
Hehe,

Found it myself ;) Had to add toAbsoluteUrl. The code now looks like:

        /**
         * Get an absoulte URL for a Page and parameters. E.g.
         * http://localhost/wicket/Page?param1=value
         *
         * @param pageClass
         *            Page Class
         * @param parameters
         *            Params
         * @param <C>
         *            Page Class
         * @return Absolute Url
         */
        public static <C extends Page> String getAbsoluteUrl(final Class<C> pageClass, final PageParameters parameters) {

                CharSequence resetUrl = RequestCycle.get().urlFor(pageClass, parameters);
        String abs = RequestUtils.toAbsolutePath("/", resetUrl.toString());
        final Url url = Url.parse(abs);
        return RequestCycle.get().getUrlRenderer().renderFullUrl(url);
        }
Loading...