users@jersey.java.net

Re: [Jersey] Implicit views and _at_ImplicitProduces

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 22 May 2009 17:27:24 +0200

On May 22, 2009, at 5:16 PM, Rabick, Mark A (IS) wrote:

> Thanks again Paul. I tried using:
>
> @Path("{mapsk: [a-zA-Z0-9\x20]{32}}")
>
> The \x20 is from the docs for java.util.regex.Pattern but I get an
> error
> message:
>
> "Invalid escape sequence (valid ones are \b \t \n \f \r \"
> \' \\
> )"
>

I am not sure what is wrong but in any case it will not work because
you need to match sequences of characters for "%20" i.e. it is not the
hexadecimal character value that you are matching against but the
percent encoded value. I am not sure how you can do that in the regex
because the number of characters in the URI path segment may vary
depending on how many spaces have been encoded into "%20" character
sequences.

> I've removed the regex from the @Path value and moved the validation
> inside the method(s).
>

OK.

Paul.

> --mark
>
> _______________________________________________
> Mark A. Rabick - Software Engineer
> Em: mark.rabick_at_ngc.com
>
>
>
>> -----Original Message-----
>> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
>> Sent: Friday, May 22, 2009 1:37 AM
>> To: users_at_jersey.dev.java.net
>> Subject: Re: [Jersey] Implicit views and @ImplicitProduces
>>
>>
>> On May 21, 2009, at 10:26 PM, Rabick, Mark A (IS) wrote:
>>
>>> Thanks Paul.
>>>
>>> I verified that the resource method was returning the expected
>>> status/URI:
>>>
>>> mapUri:
>>>
>> http://localhost:7001/i3/cnodb/cdal/rest/v1/attributemaps/
>> 704899100000
>>> 32 %20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
>>> Node - getEntityAttributeMap [END] response status: 303
>>>
>>> I set the Client.setFollowRedirects(Boolean.FALSE) my Junit test
>>> passed
>>> - received a status 303 with the URI. I have to figure out what's
>>> going on with the redirected URI. The key value I'm
>> appending to the
>>> URI is an explicit foreign key constraint in our database.
>> The key is
>>> a
>>> char(32) so I'm not sure about the spaces (%20)
>>>
>>
>> The encoding is correct.
>>
>>
>>> The resource method for the redirected target URI is:
>>>
>>> @Path("{mapsk: [a-zA-Z0-9 ]{32}}")
>>> public AttributeMapV1Resource
>>> getMapV1Resource(@PathParam("mapsk") String mapsk)
>>>
>>> Maybe the regex is incorrect? The sk characters need to be
>> letters,
>>> digits, or a space.
>>>
>>
>> The problem is that path matching happens in encoded space,
>> which needs to happen so that information in the path is not
>> lost e.g. think of the case of a URI that is encoded as a
>> path segment.
>>
>> For non regex declare @Path declarations Jersey will
>> contextually encode the path. For regexes this would be a
>> very tricky operation so it is important when using regexes
>> that you are matching the encoded space (which in your case
>> will include the %20 character sequences).
>>
>> I recommend you either explicitly encode the key using say
>> base64 or use a different key generation that does not have
>> space characters in it. Alternatively change the regex
>> expression to match just segment and do the validation
>> yourself, which you can define a class with a String
>> constructor and do:
>>
>> @Path("{mapsk}")
>> public AttributeMapV1Resource
>> getMapV1Resource(@PathParam("mapsk") Key mapsk)
>>
>> Paul.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>