You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bas Gooren <ba...@iswd.nl> on 2011/09/15 01:54:46 UTC

Wicket 1.5: request mapper to make all urls absolute

Hi,

Another wicket 1.5 migration question:
In 1.4 we created a IRequestCodingStrategy decorator which, in encode(), 
translates all urls to be absolute.
We did this by checking if the url started with "/", and if not, 
removing all occurrences of "../" and "./".

To handle being behind a reverse proxy, the constructor optionally 
accepted a prefix which was always prepended.

In 1.5 it seems this could be implemented as an IRequestMapper which 
decorates the root mapper.
However, since we are passed a Url instead of a String, and a lot has 
changed surrounding url generation, what is the best way to make all 
urls absolute?

I'm thinking:
- check Url.isAbsolute()
- remove segments which are ".." or "."
- prepend prefix segments

Is this the correct way?

Sebastian

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by manuelbarzi <ma...@gmail.com>.
cool. may you add this how-to code-example for wicket 1.4 too?
coincidentally, i may need it to test something here... ;-)


On Mon, Sep 19, 2011 at 1:48 PM, Bas Gooren <ba...@iswd.nl> wrote:

> Ok, I've added it.
>
> See https://cwiki.apache.org/**confluence/display/WICKET/**Request+mapping<https://cwiki.apache.org/confluence/display/WICKET/Request+mapping>
> Or https://cwiki.apache.org/**WICKET/request-mapping.html<https://cwiki.apache.org/WICKET/request-mapping.html>when it's updated.
>
> Thanks for the pointer.
>
> Op 19-9-2011 9:09, schreef manuelbarzi:
>
>> https://cwiki.apache.org/**WICKET/how-to-do-things-in-**wicket.html<https://cwiki.apache.org/WICKET/how-to-do-things-in-wicket.html>
>> .
>>
>>
>>
>> On Mon, Sep 19, 2011 at 1:57 AM, Bas Gooren<ba...@iswd.nl>  wrote:
>>
>>  After quite a lot of searching and testing, I've finally been able to get
>>> things working.
>>>
>>> In the end, I was able to solve my problem in the most logical place,
>>> which
>>> once again shows how great Wicket is!
>>> I've created an AbsoluteUrlRenderer (which extends the default
>>> UrlRenderer).
>>>
>>> What is a good place to share this code so other wicket users can save
>>> themselves the time?
>>>
>>> Op 16-9-2011 1:20, schreef Bas Gooren:
>>>
>>>  Ok, I've been playing around with this, and it doesn't work.
>>>
>>>> WebPageRenderer#respond() compares the current url to the target url.
>>>> The current url is always normalized (without context path), so if my
>>>> absolute mapper generates a target url which is absolute, and as such
>>>> includes the context path and the filter path, wicket initiates a
>>>> redirect.
>>>>
>>>> Then, on the next request, the exact same thing happens, so we end up in
>>>> a
>>>> redirect loop.
>>>>
>>>> It appears that the only way to achieve what I want is to override the
>>>> UrlRenderer and it's method #renderRelativeUrl(). Basically, all that is
>>>> required there is to prefix the context path and filter path.
>>>>
>>>> Op 15-9-2011 1:58, schreef Igor Vaynberg:
>>>>
>>>>  that sounds correct.
>>>>>
>>>>> essentially this is the same as running the url through
>>>>> requestcycle.geturlrenderer().****renderFullUrl(url) but with a
>>>>> different
>>>>> prefix
>>>>>
>>>>> -igor
>>>>>
>>>>> On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren<ba...@iswd.nl>   wrote:
>>>>>
>>>>>  Hi,
>>>>>>
>>>>>> Another wicket 1.5 migration question:
>>>>>> In 1.4 we created a IRequestCodingStrategy decorator which, in
>>>>>> encode(),
>>>>>> translates all urls to be absolute.
>>>>>> We did this by checking if the url started with "/", and if not,
>>>>>> removing
>>>>>> all occurrences of "../" and "./".
>>>>>>
>>>>>> To handle being behind a reverse proxy, the constructor optionally
>>>>>> accepted
>>>>>> a prefix which was always prepended.
>>>>>>
>>>>>> In 1.5 it seems this could be implemented as an IRequestMapper which
>>>>>> decorates the root mapper.
>>>>>> However, since we are passed a Url instead of a String, and a lot has
>>>>>> changed surrounding url generation, what is the best way to make all
>>>>>> urls
>>>>>> absolute?
>>>>>>
>>>>>> I'm thinking:
>>>>>> - check Url.isAbsolute()
>>>>>> - remove segments which are ".." or "."
>>>>>> - prepend prefix segments
>>>>>>
>>>>>> Is this the correct way?
>>>>>>
>>>>>> Sebastian
>>>>>>
>>>>>>  ------------------------------****----------------------------**--**
>>>>>>
>>>>> ---------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>>> <us...@wicket.apache.org>
>>>>> >
>>>>>
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by Bas Gooren <ba...@iswd.nl>.
Ok, I've added it.

See https://cwiki.apache.org/confluence/display/WICKET/Request+mapping
Or https://cwiki.apache.org/WICKET/request-mapping.html when it's updated.

Thanks for the pointer.

Op 19-9-2011 9:09, schreef manuelbarzi:
> https://cwiki.apache.org/WICKET/how-to-do-things-in-wicket.html
> .
>
>
>
> On Mon, Sep 19, 2011 at 1:57 AM, Bas Gooren<ba...@iswd.nl>  wrote:
>
>> After quite a lot of searching and testing, I've finally been able to get
>> things working.
>>
>> In the end, I was able to solve my problem in the most logical place, which
>> once again shows how great Wicket is!
>> I've created an AbsoluteUrlRenderer (which extends the default
>> UrlRenderer).
>>
>> What is a good place to share this code so other wicket users can save
>> themselves the time?
>>
>> Op 16-9-2011 1:20, schreef Bas Gooren:
>>
>>   Ok, I've been playing around with this, and it doesn't work.
>>> WebPageRenderer#respond() compares the current url to the target url.
>>> The current url is always normalized (without context path), so if my
>>> absolute mapper generates a target url which is absolute, and as such
>>> includes the context path and the filter path, wicket initiates a redirect.
>>>
>>> Then, on the next request, the exact same thing happens, so we end up in a
>>> redirect loop.
>>>
>>> It appears that the only way to achieve what I want is to override the
>>> UrlRenderer and it's method #renderRelativeUrl(). Basically, all that is
>>> required there is to prefix the context path and filter path.
>>>
>>> Op 15-9-2011 1:58, schreef Igor Vaynberg:
>>>
>>>> that sounds correct.
>>>>
>>>> essentially this is the same as running the url through
>>>> requestcycle.geturlrenderer().**renderFullUrl(url) but with a different
>>>> prefix
>>>>
>>>> -igor
>>>>
>>>> On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren<ba...@iswd.nl>   wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Another wicket 1.5 migration question:
>>>>> In 1.4 we created a IRequestCodingStrategy decorator which, in encode(),
>>>>> translates all urls to be absolute.
>>>>> We did this by checking if the url started with "/", and if not,
>>>>> removing
>>>>> all occurrences of "../" and "./".
>>>>>
>>>>> To handle being behind a reverse proxy, the constructor optionally
>>>>> accepted
>>>>> a prefix which was always prepended.
>>>>>
>>>>> In 1.5 it seems this could be implemented as an IRequestMapper which
>>>>> decorates the root mapper.
>>>>> However, since we are passed a Url instead of a String, and a lot has
>>>>> changed surrounding url generation, what is the best way to make all
>>>>> urls
>>>>> absolute?
>>>>>
>>>>> I'm thinking:
>>>>> - check Url.isAbsolute()
>>>>> - remove segments which are ".." or "."
>>>>> - prepend prefix segments
>>>>>
>>>>> Is this the correct way?
>>>>>
>>>>> Sebastian
>>>>>
>>>>>   ------------------------------**------------------------------**
>>>> ---------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by manuelbarzi <ma...@gmail.com>.
https://cwiki.apache.org/WICKET/how-to-do-things-in-wicket.html
.



On Mon, Sep 19, 2011 at 1:57 AM, Bas Gooren <ba...@iswd.nl> wrote:

> After quite a lot of searching and testing, I've finally been able to get
> things working.
>
> In the end, I was able to solve my problem in the most logical place, which
> once again shows how great Wicket is!
> I've created an AbsoluteUrlRenderer (which extends the default
> UrlRenderer).
>
> What is a good place to share this code so other wicket users can save
> themselves the time?
>
> Op 16-9-2011 1:20, schreef Bas Gooren:
>
>  Ok, I've been playing around with this, and it doesn't work.
>>
>> WebPageRenderer#respond() compares the current url to the target url.
>> The current url is always normalized (without context path), so if my
>> absolute mapper generates a target url which is absolute, and as such
>> includes the context path and the filter path, wicket initiates a redirect.
>>
>> Then, on the next request, the exact same thing happens, so we end up in a
>> redirect loop.
>>
>> It appears that the only way to achieve what I want is to override the
>> UrlRenderer and it's method #renderRelativeUrl(). Basically, all that is
>> required there is to prefix the context path and filter path.
>>
>> Op 15-9-2011 1:58, schreef Igor Vaynberg:
>>
>>> that sounds correct.
>>>
>>> essentially this is the same as running the url through
>>> requestcycle.geturlrenderer().**renderFullUrl(url) but with a different
>>> prefix
>>>
>>> -igor
>>>
>>> On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren<ba...@iswd.nl>  wrote:
>>>
>>>> Hi,
>>>>
>>>> Another wicket 1.5 migration question:
>>>> In 1.4 we created a IRequestCodingStrategy decorator which, in encode(),
>>>> translates all urls to be absolute.
>>>> We did this by checking if the url started with "/", and if not,
>>>> removing
>>>> all occurrences of "../" and "./".
>>>>
>>>> To handle being behind a reverse proxy, the constructor optionally
>>>> accepted
>>>> a prefix which was always prepended.
>>>>
>>>> In 1.5 it seems this could be implemented as an IRequestMapper which
>>>> decorates the root mapper.
>>>> However, since we are passed a Url instead of a String, and a lot has
>>>> changed surrounding url generation, what is the best way to make all
>>>> urls
>>>> absolute?
>>>>
>>>> I'm thinking:
>>>> - check Url.isAbsolute()
>>>> - remove segments which are ".." or "."
>>>> - prepend prefix segments
>>>>
>>>> Is this the correct way?
>>>>
>>>> Sebastian
>>>>
>>>>  ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by Bas Gooren <ba...@iswd.nl>.
After quite a lot of searching and testing, I've finally been able to 
get things working.

In the end, I was able to solve my problem in the most logical place, 
which once again shows how great Wicket is!
I've created an AbsoluteUrlRenderer (which extends the default UrlRenderer).

What is a good place to share this code so other wicket users can save 
themselves the time?

Op 16-9-2011 1:20, schreef Bas Gooren:
> Ok, I've been playing around with this, and it doesn't work.
>
> WebPageRenderer#respond() compares the current url to the target url.
> The current url is always normalized (without context path), so if my 
> absolute mapper generates a target url which is absolute, and as such 
> includes the context path and the filter path, wicket initiates a 
> redirect.
>
> Then, on the next request, the exact same thing happens, so we end up 
> in a redirect loop.
>
> It appears that the only way to achieve what I want is to override the 
> UrlRenderer and it's method #renderRelativeUrl(). Basically, all that 
> is required there is to prefix the context path and filter path.
>
> Op 15-9-2011 1:58, schreef Igor Vaynberg:
>> that sounds correct.
>>
>> essentially this is the same as running the url through
>> requestcycle.geturlrenderer().renderFullUrl(url) but with a different
>> prefix
>>
>> -igor
>>
>> On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren<ba...@iswd.nl>  wrote:
>>> Hi,
>>>
>>> Another wicket 1.5 migration question:
>>> In 1.4 we created a IRequestCodingStrategy decorator which, in 
>>> encode(),
>>> translates all urls to be absolute.
>>> We did this by checking if the url started with "/", and if not, 
>>> removing
>>> all occurrences of "../" and "./".
>>>
>>> To handle being behind a reverse proxy, the constructor optionally 
>>> accepted
>>> a prefix which was always prepended.
>>>
>>> In 1.5 it seems this could be implemented as an IRequestMapper which
>>> decorates the root mapper.
>>> However, since we are passed a Url instead of a String, and a lot has
>>> changed surrounding url generation, what is the best way to make all 
>>> urls
>>> absolute?
>>>
>>> I'm thinking:
>>> - check Url.isAbsolute()
>>> - remove segments which are ".." or "."
>>> - prepend prefix segments
>>>
>>> Is this the correct way?
>>>
>>> Sebastian
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by Bas Gooren <ba...@iswd.nl>.
Ok, I've been playing around with this, and it doesn't work.

WebPageRenderer#respond() compares the current url to the target url.
The current url is always normalized (without context path), so if my 
absolute mapper generates a target url which is absolute, and as such 
includes the context path and the filter path, wicket initiates a redirect.

Then, on the next request, the exact same thing happens, so we end up in 
a redirect loop.

It appears that the only way to achieve what I want is to override the 
UrlRenderer and it's method #renderRelativeUrl(). Basically, all that is 
required there is to prefix the context path and filter path.

Op 15-9-2011 1:58, schreef Igor Vaynberg:
> that sounds correct.
>
> essentially this is the same as running the url through
> requestcycle.geturlrenderer().renderFullUrl(url) but with a different
> prefix
>
> -igor
>
> On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren<ba...@iswd.nl>  wrote:
>> Hi,
>>
>> Another wicket 1.5 migration question:
>> In 1.4 we created a IRequestCodingStrategy decorator which, in encode(),
>> translates all urls to be absolute.
>> We did this by checking if the url started with "/", and if not, removing
>> all occurrences of "../" and "./".
>>
>> To handle being behind a reverse proxy, the constructor optionally accepted
>> a prefix which was always prepended.
>>
>> In 1.5 it seems this could be implemented as an IRequestMapper which
>> decorates the root mapper.
>> However, since we are passed a Url instead of a String, and a lot has
>> changed surrounding url generation, what is the best way to make all urls
>> absolute?
>>
>> I'm thinking:
>> - check Url.isAbsolute()
>> - remove segments which are ".." or "."
>> - prepend prefix segments
>>
>> Is this the correct way?
>>
>> Sebastian
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

Re: Wicket 1.5: request mapper to make all urls absolute

Posted by Igor Vaynberg <ig...@gmail.com>.
that sounds correct.

essentially this is the same as running the url through
requestcycle.geturlrenderer().renderFullUrl(url) but with a different
prefix

-igor

On Wed, Sep 14, 2011 at 4:54 PM, Bas Gooren <ba...@iswd.nl> wrote:
> Hi,
>
> Another wicket 1.5 migration question:
> In 1.4 we created a IRequestCodingStrategy decorator which, in encode(),
> translates all urls to be absolute.
> We did this by checking if the url started with "/", and if not, removing
> all occurrences of "../" and "./".
>
> To handle being behind a reverse proxy, the constructor optionally accepted
> a prefix which was always prepended.
>
> In 1.5 it seems this could be implemented as an IRequestMapper which
> decorates the root mapper.
> However, since we are passed a Url instead of a String, and a lot has
> changed surrounding url generation, what is the best way to make all urls
> absolute?
>
> I'm thinking:
> - check Url.isAbsolute()
> - remove segments which are ".." or "."
> - prepend prefix segments
>
> Is this the correct way?
>
> Sebastian
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org