Re: Backward compatibility with URLs generated by HybridUrlCodingStrategy.
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
Re: Backward compatibility with URLs generated by HybridUrlCodingStrategy.
Hi Fabio, The code looks OK! Indeed it is not very easy to create really bookmarkable url! The page has to be stateless to have url that will produce the same result every time. With stateful pages (pages with pageId in their url) there is a chance to load something different than what you expect ... but all this is known. You can search the mail archives for NoVersionRequestMapper to workaround this. But it will lead to different kind of problems. Martin Grigorov Wicket Training and Consulting On Thu, Jun 12, 2014 at 2:19 PM, Fabio Fioretti windom.macroso...@gmail.com wrote: 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
Re: Backward compatibility with URLs generated by HybridUrlCodingStrategy.
Hi Martin, Thanks for your time and help. Even though my 1.4 URLs contain pageIds, in the moment they were bookmarked they were basically made stateless to my application, as the pageId lost meaning. It is now just noise that gets misinterpreted by the migrated app because of the dotted notation. All I wanted to achieve is to make them work in Wicket 6.x and, to do that, it is sufficient to strip the bookmarked pageId away and let Wicket reassign a new one with the proper encoding (? instead of .). Kind regards, Fabio On Thu, Jun 12, 2014 at 2:54 PM, Martin Grigorov mgrigo...@apache.org wrote: Hi Fabio, The code looks OK! Indeed it is not very easy to create really bookmarkable url! The page has to be stateless to have url that will produce the same result every time. With stateful pages (pages with pageId in their url) there is a chance to load something different than what you expect ... but all this is known. You can search the mail archives for NoVersionRequestMapper to workaround this. But it will lead to different kind of problems. Martin Grigorov Wicket Training and Consulting On Thu, Jun 12, 2014 at 2:19 PM, Fabio Fioretti windom.macroso...@gmail.com wrote: 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
Backward compatibility with URLs generated by HybridUrlCodingStrategy.
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
Re: Backward compatibility with URLs generated by HybridUrlCodingStrategy.
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