On Jan 26, 2010, at 5:00 PM, Tim Edwards wrote:
> Issue created https://jersey.dev.java.net/issues/show_bug.cgi?id=468.
>
>
Thanks!
Paul.
> The custom filter did the trick, thanks for the help.
>
> Tim
>
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: 26 January 2010 14:01
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Confusion with normalize/canonicalize features
>
> Hi Tim,
>
> There is a bug. Can you log an issue?
>
> The NormalizeFilter [1] which supports this behavior is not
> modifying the request URI when redirection is set to false.
>
> Plus there is an error in the documentation:
> FEATURE_CANONICALIZE_URI_PATH is only relevant if
> FEATURE_NORMALIZE_URI is true. So we need to update the docs.
>
> A work around is to register your own filter [2].
>
> Paul.
>
>
> [1]
> public class NormalizeFilter implements ContainerRequestFilter {
> @Context ResourceConfig resourceConfig;
>
> public ContainerRequest filter(ContainerRequest request) {
> if
> (resourceConfig.getFeature(ResourceConfig.FEATURE_NORMALIZE_URI)) {
> final URI uri = request.getRequestUri();
> final URI normalizedUri = UriHelper.normalize(uri,
> !
> resourceConfig
> .getFeature(ResourceConfig.FEATURE_CANONICALIZE_URI_PATH));
>
> if (uri != normalizedUri &&
>
> resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT)) {
> throw new WebApplicationException(
>
> Response.temporaryRedirect(normalizedUri).build());
> }
> }
> return request;
> }
> }
>
> [2]
> public class NormalizeFilter implements ContainerRequestFilter {
> @Context ResourceConfig resourceConfig;
>
> public ContainerRequest filter(ContainerRequest request) {
> if
> (resourceConfig.getFeature(ResourceConfig.FEATURE_NORMALIZE_URI)) {
> final URI uri = request.getRequestUri();
> final URI normalizedUri = UriHelper.normalize(uri,
> !
> resourceConfig
> .getFeature(ResourceConfig.FEATURE_CANONICALIZE_URI_PATH));
>
> if (uri != normalizedUri) {
> if
> (resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT)) {
> throw new WebApplicationException(
>
> Response.temporaryRedirect(normalizedUri).build());
> } else {
> request.setUris(request.getBaseUri(), uri);
> }
> }
> }
> return request;
> }
> }
>
>
> On Jan 25, 2010, at 12:26 PM, Tim Edwards wrote:
>
>>
>> Hi,
>>
>> I'm having a bit of a problem with FEATURE_NORMALIZE_URI /
>> FEATURE_CANONICALIZE_URI_PATH and their interaction with
>> FEATURE_REDIRECT. I have set normalize & canonicalize on but
>> have redirect off. From my understanding of the javadoc for
>> ResourceConfig.FEATURE_REDIRECT:
>>
>> "If true, and either NORMALIZE_URI or CANONICALIZE_URI_PATH is
>> true, and the normalization and/or path canonicalization operations
>> on the request URI result in a new URI that is not equal to the
>> request URI, then the client is (temporarily) redirected to the new
>> URI. Otherwise the request URI is set to be the new URI."
>>
>> This setup should result in the URI being rewritten if appropriate
>> but with no temporary redirect. However my experience is that the
>> rewritten URI is never used (resulting in a 404). Looking at the
>> code for NormalizeFilter, I can see that if redirect is not set,
>> then nothing happens with the rewritten URI.
>>
>> Is this the intended behaviour? If so, it would imply the javadoc
>> is misleading. If not, could be a bug. Or am I just missing
>> something?
>>
>> Cheers,
>> Tim
>>
>>
>>
>> If you are not the intended recipient, employee or agent
>> responsible for delivering the message to the intended recipient,
>> you are hereby notified that any dissemination or copying of this
>> communication and its attachments is strictly prohibited. If you
>> have received this communication and its attachments in error,
>> please return the original message and attachments to the sender
>> using the reply facility on e-mail. Internet communications are not
>> secure and therefore Cambridge Assessment (the brand name for the
>> University of Cambridge Local Examinations Syndicate, the
>> constituent elements of which are CIE, ESOL and OCR [Oxford
>> Cambridge and RSA Examinations is a Company Limited by Guarantee
>> Registered in England. Registered office: 1 Hills Road, Cambridge
>> CB1 2EU. Company number: 3484466]) does not accept legal
>> responsibility for the contents of this message. Any views or
>> opinions presented are solely those of the author and do not
>> necessarily represent those of Cambridge Assessment unless
>> otherwise specifically stated. The information contained in this
>> email may be subject to public disclosure under the Freedom of
>> Information Act 2000. Unless the information is legally exempt from
>> disclosure, the confidentiality of this email and your reply cannot
>> be guaranteed.
>>
>> This message has been scanned for viruses by BlackSpider MailControl
>>
>
>
>
> Click here to report this email as spam.
>