Many thanks Martin,

I followed your advice and ended up overriding SystemMapper's mapRequest. I
decided to simply strip away the page instance instead of moving it to the
query string. It's just noise for me, after all. Quite rough probably, but
it seems to do the job in all the cases I tried.

Do you foresee any problem with this piece of code? I'm not really
confident the way to identify the page instance is correct, and I'm afraid
it could add too much overhead (note: isNumber is implemented using
Character.isDigit, as suggested here:
http://jdevelopment.nl/efficient-determine-string-number/).

setRootRequestMapper(*new* SystemMapper(*this*) {

@Override

 *public* IRequestHandler mapRequest(Request request) {

*final* Url url = request.getUrl();

*final* String lastSegment = !url.getSegments().isEmpty() ?
url.getSegments().get(url.getSegments().size() - 1) : *null*;

*if* (lastSegment != *null* && lastSegment.contains(".")) {

*final* String presumedPageInstance =
lastSegment.substring(lastSegment.lastIndexOf(".") + 1);

*if* (isNumber(presumedPageInstance)) {

// If it's a number, assume it's the page Id and strip it from the request
URL.

*final* String cleanedUpLastSegment = lastSegment.substring(0,
lastSegment.lastIndexOf("."));

url.getSegments().set(url.getSegments().size() - 1, cleanedUpLastSegment);

*return* *super*.mapRequest(request.cloneWithUrl(url));

}

 }

*return* *super*.mapRequest(request);

 }

});


Many thanks,
Fabio


On Wed, Jun 11, 2014 at 2:12 PM, Martin Grigorov <mgrigo...@apache.org>
wrote:

> Hi Fabio,
>
> You can create your own root request mapper that when detecting an old url
> can either :
> 1) return a redirect with code 301 (Moved permanently)
> 2) just "move" the page id from the last segment to the query string
> silently
>
> Martin Grigorov
> Wicket Training and Consulting
>
>
> On Wed, Jun 11, 2014 at 1:00 PM, Fabio Fioretti <
> windom.macroso...@gmail.com
> > wrote:
>
> > Hi all,
> >
> > I am migrating an application from Wicket 1.4 to 6.15. This app makes use
> > of HybridUrlCodingStrategy, that I replaced with a MountedMapped using
> > UrlPathPageParametersEncoder.
> >
> > The problem is that many users have old bookmarks of URLs generated by
> > HybridUrlCodingStrategy, in which the page instance number comes after a
> > dot, like in the following example:
> >
> > http://myapp.com/mount/path/param/value.4
> >
> > Now, with MountedMapper and UrlPathPageParametersEncoder, the same URL
> > looks like this (mind the "?" replacing the "."):
> >
> > http://myapp.com/mount/path/param/value?4
> >
> > The result is that the old dotted bookmarks do not work anymore (HTTP
> 404).
> >
> > Any suggestion on the best approach to guarantee backward compatibility
> > with old URLs?
> >
> > Thanks very much in advance,
> > Fabio Fioretti
> >
>

Reply via email to