users@jersey.java.net

Re: help with uritemplate

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 27 Aug 2007 12:33:04 +0200

Hi Vishal,

You have found a bug that is rather tricky to fix, but thankfully has an
easy workaround. In terms of grouping HTTP methods with a URI template
the regular expression of the template needs to be used and it should
not matter what the template variables are, but when extracting out
template values from a matched template it does. At the moment i am not
sure how to fix it...


Some hints you might find useful... we need to improve the java doc...

Given the following:

   return Response.Builder
     .representation("serviceStatus", "text/plain")
     .header("Etag", "0000000")
     .status(200).build();

You can do:

   return Response.Builder
     .representation("serviceStatus", "text/plain")
     .tag("0000000")
     .build();

The static method 'representation' will set the status code to 200.

The method 'tag' can be used to set the "ETag" header.


Given the following:

   return Response.Builder
     .representation(data, "text/plain")
     .header("Etag", transac_id)
     .header("Location", "/")
     .status(201).build();

You can do:

   return Response.Builder
     .created(data, "/")
     .type("text/plain")
     .tag(transac_id)
     .build();


If you want the transaction functionality to be a reusable component (if
possible and makes sense) then make it a separate class that MTest uses
with a sub-locator method:

    @UriTemplate("{transaction_id}")
    public TR getTR(@UriParam("transaction_id") String t_id) {
       return new TR(t_id);
    }

Hope this helps,
Paul.

Vishal Vatsa wrote:
> Hi Jakub,
>
> Thanks for that, it totally works if I have consistent uri params. Please pass
> my thanks to Paul also.
>
> Do you still want me to create bug report or do you guys want to deal with it
> internally?
>
> Thanks Very Much.
> Vishal
>
> On Thursday 23 August 2007 13:31:43 Jakub Podlesak wrote:
>> Hi Vishal,
>>
>> Paul just came with a workaround for you.
>> There is definitely a bug in Jersey, anyway if you had the same
>> (consistent) uri parameter names, it should work for you (as it works for
>> me).
>>
>> Please see the updated source code attached (I have changed the class name,
>> but the content remains same).
>>
>> ~Jakub
>>
>> On Thu, Aug 23, 2007 at 11:24:04AM +0100, Vishal Vatsa wrote:
>>> Hi Jakub,
>>>
>>> Thanks for taking a look at this for me, I will submit a new bug report
>>> with the necessary files to recreate the issue.
>>>
>>> I was really hoping I that I was at fault, crap.
>>>
>>> Thanks Again
>>> Vishal
>>>
>>> On Thursday 23 August 2007 10:49:08 Jakub Podlesak wrote:
>>>> Hi Vishal,
>>>>
>>>> I think it is a bug. Could you please submit a new bug report at
>>>> https://jersey.dev.java.net/issues/
>>>> so that we can track it?
>>>>
>>>> Please do not forget to attach your project files.
>>>>
>>>> Thank you a lot!
>>>>
>>>> ~Jakub
>>>>
>>>> On Thu, Aug 23, 2007 at 07:46:44AM +0100, Vishal Vatsa wrote:
>>>>> Hi Guys,
>>>>>
>>>>> I have a class with three functions on the same uritemplate with
>>>>> diffrent httpmethod (get, post, put) for each. Any time I try to use
>>>>> the post method I keep getting 405 method not allowed, but the really
>>>>> odd thing is that if I comment out the functions with the get and put
>>>>> httpmethod, I can use the post method no problem.
>>>>>
>>>>>
>>>>> So in the below src, if I comment out getTransaction and
>>>>> processInstructon funtions, I can use the post methon on uri
>>>>> "/XmlUpdate/blahblah" and hit the acceptResource function just fine,
>>>>> but the way it it right now if I do the post to the url
>>>>> "/XmlUpdate/blahblah" I keep getting a 405 responce.
>>>>>
>>>>> If any one could please point out what I am doing wrong, it would be
>>>>> great as I am reduced to pulling my hair out at this point.
>>>>>
>>>>> Thanks
>>>>> Vishal
>>>>>
>>>>> ###############################################
>>>>> # java src file
>>>>> ###############################################
>>>>> import javax.ws.rs.ConsumeMime;
>>>>> import javax.ws.rs.HttpMethod;
>>>>> import javax.ws.rs.UriParam;
>>>>> import javax.ws.rs.UriTemplate;
>>>>> import javax.ws.rs.core.HttpContext;
>>>>> import javax.ws.rs.core.HttpHeaders;
>>>>> import javax.ws.rs.core.Response;
>>>>>
>>>>> @UriTemplate("/XmlUpdate")
>>>>> public class MTest {
>>>>>
>>>>> @HttpMethod("GET")
>>>>> public Response serviceStatus(@HttpContext HttpHeaders header){
>>>>> return Response.Builder.representation("serviceStatus",
>>>>> "text/plain") .header("Etag", "0000000")
>>>>> .status(200).build();
>>>>> }
>>>>>
>>>>> @HttpMethod("POST")
>>>>> //_at_ConsumeMime("application/x-www-form-urlencoded")
>>>>> public Response createTransaction(@HttpContext HttpHeaders header,
>>>>> String xml){
>>>>>
>>>>>
>>>>> return Response.Builder.representation("createTransaction",
>>>>> "text/plain") .header("Location", "/")
>>>>> .header("Etag", "11111")
>>>>> .status(201).build();
>>>>> }
>>>>>
>>>>> @UriTemplate("{transac_id}")
>>>>> @HttpMethod("POST")
>>>>> @ConsumeMime("*/*")
>>>>> public Response acceptResource(@UriParam("transac_id") String
>>>>> transac_id, @HttpContext HttpHeaders header,
>>>>> String data){
>>>>> return Response.Builder.representation(data, "text/plain")
>>>>> .header("Etag", transac_id)
>>>>> .header("Location", "/")
>>>>> .status(201).build();
>>>>>
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> @UriTemplate("{transaction_id}")
>>>>> @HttpMethod("GET")
>>>>> public Response getTransactionStatus(@UriParam("transaction_id")
>>>>> String t_id) {
>>>>> return Response.Builder.representation("get transaction",
>>>>> "text/plain") .header("Etag", "222222")
>>>>> .status(200).build();
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> @UriTemplate("{transaction_id}")
>>>>> @HttpMethod("PUT")
>>>>> public Response processInstruction(@UriParam("transaction_id")
>>>>> String t_id, String xml){
>>>>>
>>>>> return Response.Builder.representation(xml, "text/xml")
>>>>> .header("Etag", "3333333")
>>>>> .status(200).build();
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>> --
>>> Last song played: Ryan Adams – I See Monsters, on Thu Aug 23 10:17:27
>>> 2007
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109