You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gabo Manuel <km...@solegysystems.com> on 2008/10/31 11:57:55 UTC

Re: [JAX-RS][PathParam] object field injection

Sorry for the misleading subject, it was the error I encountered 
earlier. forgot the @PathParam("") in the method.

Gabo Manuel wrote:
> Hi all,
>
> I am currently trying to have the following work. Initially I have a 
> service as follows:
>
>    @GET
>    @Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow}")
>    @ProduceMime("application/xml")
>    public Accounts getList(
>            @PathParam("")
>            SearchFilter sf
>            ) {
>        return super.getList(sf);
>    }
>
> Since there is no means to add a body to an HTTP GET, I used the field 
> injection using @PathParam. I had the SearchFilter file annotated as 
> follows:
>    @PathParam("whereCondition")
>    private String whereCondition;
>    @PathParam("sortString")
>    private String sortString;
>    @PathParam("startingRow")
>    private long startingRow;
>    @PathParam("lastRow")
>    private long lastRow;
>    //it has setters down the code...
>
> I'm trying to follow the example in 
> (http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html). The code works 
> perfect when I access /search/mywhere/mysort/1/10.
>
> I am also wondering if it is possible for the parameters to have 
> defaults, i.e. the service to become accessible if lastRow is omitted. 
> e.g. /search/mywhere/mysort/1 would still be accessible with lastRow 
> defaulting to 10.
>
> As per user's guide, @DefaultValue is only useable for @QueryParam, 
> however, injecting the values to object fields is only applicable to 
> @PathParam. Is it possible to have @QueryParam inject to object fields?
>
> As of the moment, the only work-around I could think of is avoid the 
> use of object in GET and have everything as @QueryParam.
>
> Again, my thanks.
>
> Gabo
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.175 / Virus Database: 270.8.5/1757 - Release Date: 10/30/2008 2:35 PM
>
>   

Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

You might also want to consider injecting UriInfo as a field or as a bean property :

Ex1 :

@Context
private UriInfo ui;

Ex2.

@Context
void setUriInfo(UriInfo ui) {
}

I'm not sure the second example is totally JAX-RS compliant - I think it is as I remember seeing on either Jersey or JAXRS users 
list a discussion about contexts being injected as bean properties...

Cheers, Sergey

> Hi Sergey,
>
> > @Path({filter:.*})
> > public Response search(@PathParam("") SearchFilter bean) {
>
> Thanks for pointing me in the right direction. I had changed it as follows:
>
>    @GET
>    @Path("/search.*")
>    public Accounts getList(
>            @Context
>            UriInfo uriinfo
>            ) {
>
> From here I'll just parse the path_info.
>
> Again my thanks.
>
> Gabo
> 


RE: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Gabo

We're planning to support JAXRS on a 2.1.x for as long as merging any
new fixes won't make sense, but we're probably talking about JAXRS 2.0
may be.

There's really a very little difference between 0.8 and 1.0 API. I sent
an email to a users list awhile back soliciting some feedback on whether
users want 1.0 api merged into 2.1.x but no feedback followed so it's
unlikely the coming 2.1.4 release will have 1.0 api support.

We can eventually push 1.0 api to 2.1.x too but if some users have some
JAXRS services in production then it can be a bit of pain for them to
start changing ProduceMime to Produces - it won't make difference to the
quality of services. So I guess we can keep 2.1.x at 0.8 api level but
if people will want it they we can put 1.0 api into, say, CXF 2.1.5. At
that time though it's likely 2.2 will've been released, so may be it
would make sense just to keep 2.1.x with 0.8 for as long as needed,
we'll see.

I said in some other email that the regex stuff was part of the 1.0 api.
In principle yes as 1.0 JavaDocs for say @Path talk about the regex
stuff while in 0.8 it's not the case. But I see no reasons for why it
can be supported on the 2.1.x line as the Path's value can accommodate
the arbitrary expressions.
Spring security work will unlikely have any impact - apart from us
fixing whatever bugs we may find while looking at building a system
test/demo.

Cheers, Sergey 


-----Original Message-----
From: Gabo Manuel [mailto:kmanuel@solegysystems.com] 
Sent: 05 December 2008 09:50
To: users@cxf.apache.org
Subject: Re: [JAX-RS][PathParam] object field injection

Hi Sergey,

That's another thing I am a bit worried about. Which "trail"/version 
should I be using. It is a new project, so somewhat clean slate so to
speak.

Do you guys plan to support 2 (or more?) different version trails for a 
long time? I'm thinking of using the version which includes the changes 
related to this, the regex, jsr1 and that of spring security. There is 
not much rush at the moment to get things into production yet, so there 
is still some time to wait. :D

 > no FormParam and GenericEntity support...

I don't use them at the moment so not much issue there :)

Gabo



Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

That's another thing I am a bit worried about. Which "trail"/version 
should I be using. It is a new project, so somewhat clean slate so to speak.

Do you guys plan to support 2 (or more?) different version trails for a 
long time? I'm thinking of using the version which includes the changes 
related to this, the regex, jsr1 and that of spring security. There is 
not much rush at the moment to get things into production yet, so there 
is still some time to wait. :D

 > no FormParam and GenericEntity support...

I don't use them at the moment so not much issue there :)

Gabo



Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Gabo

great it's working - I'd also credit the jaxrs experts who came up with the feature and a cxf user who said a couple of months ago 
arbitrary regexs were not supported :-)

Thanks, Sergey

> Hi Sergey,
>
> Just to note down what I did from your suggestions.
>
> Currently, I am using 2.2 snapshot. I have modified the code as follows:
>
> 1. I have defined the method as follows:
>
>    @GET
>    @Path("/{search:search.*}")
>    public WSAccounts getAccounts(
>            @PathParam("search")
>            SearchFilter sf) {
>
> 2. SearchFilter now has a constructor that accepts a String as parameter.
>
> As a result, the code is able to handle the following cases freely:
>
> /search/accountid%3D%271%27+and+balance+between+1+and+2/accountid/1/10
> /search/accountid%3D%271%27+and+balance+between+1+and+2
> /search?wherecondition=accountid%3D%271%27+and+balance+between+1+and+2&sortstring=accountid&startingrow=1&lastrow=10
> /search?wherecondition=accountid%3D%271%27+and+balance+between+1+and+2
>
> wherein defaults may be loaded in the samples 2 and 4 above.
>
> Again, my thanks!
>
> Gabo
>
> Sergey Beryozkin wrote:
>> Hi Gabo
>>
>>> Hi Sergey,
>>>
>>> > It's correct. Given that you're running a 2.1.4-snapshot, you may
>>> want to try
>>> > @Path(value="/search/{params}", unlimited=true)
>>>
>>> Is there a way that the excess/pattern is not captured? Also, I think the keyword is limited, I'm assuming the value would be 
>>> false.
>>
>> Yes, sorry, it should be limited=false.
>>
>> Please note you can only set a limited value on with 0.8 api, on 2.1.x.
>> Another thing, when using arbitrary regular expressions, you probably don't want to use 'limited=false' at all, but rather use 
>> just @Path(value="/search{bar:.*}")
>>
>> Note the syntax of the expression, {bar:.*}, the 'bar' is seperated by ':' from a regular expression.
>>
>> So, to summarize, on 2.2-snapshot line you can only use custom regular expressions to customize the way some matching is done.
>> On 2.1-snapshot, you can use either regular expressions, or in cases where a greedy all-capturing match is needed, limited=false.
>> For ex,
>> @Path(value="/search{bar:.*}")
>> @Path(value="/search{bar},limited=false)
>>
>> Please try the 2.1.4-SNAPSHOT which Dan released last Friday if you'd like to try the arbitrary reg expressions, otherwise try 
>> using limited=false
>>
>> Cheers, Sergey
>>
>>
>>
>>>
>>>    @Path(value="/search{.*}", limited=false)
>>> results to: Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 6
>>> /search{\.*}(/.*)?
>>>
>>> which is simply hints that the name is required as specified in the docs:
>>> http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0-beta-9/javadocs/javax/ws/rs/Path.html
>>>
>>>    @Path(value="/search.*", limited=false)
>>>    @Path(value="/search", limited=false)
>>> results to: org.apache.cxf.interceptor.Fault: .No operation matching request path /search/additional/path/here
>>>
>>> Gabo
>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.18/1848 - Release Date: 12/14/2008 12:28 PM
>>
>>
> 


Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

Just to note down what I did from your suggestions.

Currently, I am using 2.2 snapshot. I have modified the code as follows:

1. I have defined the method as follows:

    @GET
    @Path("/{search:search.*}")
    public WSAccounts getAccounts(
            @PathParam("search")
            SearchFilter sf) {

2. SearchFilter now has a constructor that accepts a String as parameter.

As a result, the code is able to handle the following cases freely:

/search/accountid%3D%271%27+and+balance+between+1+and+2/accountid/1/10
/search/accountid%3D%271%27+and+balance+between+1+and+2
/search?wherecondition=accountid%3D%271%27+and+balance+between+1+and+2&sortstring=accountid&startingrow=1&lastrow=10
/search?wherecondition=accountid%3D%271%27+and+balance+between+1+and+2

wherein defaults may be loaded in the samples 2 and 4 above.

Again, my thanks!

Gabo

Sergey Beryozkin wrote:
> Hi Gabo
>
>> Hi Sergey,
>>
>> > It's correct. Given that you're running a 2.1.4-snapshot, you may
>> want to try
>> > @Path(value="/search/{params}", unlimited=true)
>>
>> Is there a way that the excess/pattern is not captured? Also, I think 
>> the keyword is limited, I'm assuming the value would be false.
>
> Yes, sorry, it should be limited=false.
>
> Please note you can only set a limited value on with 0.8 api, on 2.1.x.
> Another thing, when using arbitrary regular expressions, you probably 
> don't want to use 'limited=false' at all, but rather use just 
> @Path(value="/search{bar:.*}")
>
> Note the syntax of the expression, {bar:.*}, the 'bar' is seperated by 
> ':' from a regular expression.
>
> So, to summarize, on 2.2-snapshot line you can only use custom regular 
> expressions to customize the way some matching is done.
> On 2.1-snapshot, you can use either regular expressions, or in cases 
> where a greedy all-capturing match is needed, limited=false.
> For ex,
> @Path(value="/search{bar:.*}")
> @Path(value="/search{bar},limited=false)
>
> Please try the 2.1.4-SNAPSHOT which Dan released last Friday if you'd 
> like to try the arbitrary reg expressions, otherwise try using 
> limited=false
>
> Cheers, Sergey
>
>
>
>>
>>    @Path(value="/search{.*}", limited=false)
>> results to: Exception in thread "main" 
>> java.util.regex.PatternSyntaxException: Illegal repetition near index 6
>> /search{\.*}(/.*)?
>>
>> which is simply hints that the name is required as specified in the 
>> docs:
>> http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0-beta-9/javadocs/javax/ws/rs/Path.html 
>>
>>
>>    @Path(value="/search.*", limited=false)
>>    @Path(value="/search", limited=false)
>> results to: org.apache.cxf.interceptor.Fault: .No operation matching 
>> request path /search/additional/path/here
>>
>> Gabo
>>
>>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.176 / Virus Database: 270.9.18/1848 - Release Date: 12/14/2008 12:28 PM
>
>   

Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

> Hi Sergey,
>
> > It's correct. Given that you're running a 2.1.4-snapshot, you may
> want to try
> > @Path(value="/search/{params}", unlimited=true)
>
> Is there a way that the excess/pattern is not captured? Also, I think the keyword is limited, I'm assuming the value would be 
> false.

Yes, sorry, it should be limited=false.

Please note you can only set a limited value on with 0.8 api, on 2.1.x.
Another thing, when using arbitrary regular expressions, you probably don't want to use 'limited=false' at all, but rather use just 
@Path(value="/search{bar:.*}")

Note the syntax of the expression, {bar:.*}, the 'bar' is seperated by ':' from a regular expression.

So, to summarize, on 2.2-snapshot line you can only use custom regular expressions to customize the way some matching is done.
On 2.1-snapshot, you can use either regular expressions, or in cases where a greedy all-capturing match is needed, limited=false.
For ex,
@Path(value="/search{bar:.*}")
@Path(value="/search{bar},limited=false)

Please try the 2.1.4-SNAPSHOT which Dan released last Friday if you'd like to try the arbitrary reg expressions, otherwise try using 
limited=false

Cheers, Sergey



>
>    @Path(value="/search{.*}", limited=false)
> results to: Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 6
> /search{\.*}(/.*)?
>
> which is simply hints that the name is required as specified in the docs:
> http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0-beta-9/javadocs/javax/ws/rs/Path.html
>
>    @Path(value="/search.*", limited=false)
>    @Path(value="/search", limited=false)
> results to: org.apache.cxf.interceptor.Fault: .No operation matching request path /search/additional/path/here
>
> Gabo
>
> 



Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > It's correct. Given that you're running a 2.1.4-snapshot, you may 
want to try
 > @Path(value="/search/{params}", unlimited=true)

Is there a way that the excess/pattern is not captured? Also, I think 
the keyword is limited, I'm assuming the value would be false.

    @Path(value="/search{.*}", limited=false)
results to: Exception in thread "main" 
java.util.regex.PatternSyntaxException: Illegal repetition near index 6
/search{\.*}(/.*)?

which is simply hints that the name is required as specified in the docs:
http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0-beta-9/javadocs/javax/ws/rs/Path.html

    @Path(value="/search.*", limited=false)
    @Path(value="/search", limited=false)
results to: org.apache.cxf.interceptor.Fault: .No operation matching 
request path /search/additional/path/here

Gabo


Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo
> 
> I am getting this error trace:
> 
> INFO: Interceptor has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: .No operation matching request path 
> /search/accountid=1+and+balance+between+1+and+2/accountid/1/10 is found, 

It's correct. Given that you're running a 2.1.4-snapshot, you may want to try
@Path(value="/search/{params}", unlimited=true)

And {params} should capture everything after search

Cheers, Sergey

> ContentType : application/xml; charset=ISO-8859-1, Accept : */*.
>    at 
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:206)
>    at 
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:66)
> 
> > Actually, looks like you're building from the source ?
> 
> ahh, no... i just downloaded the binary.
> 
> > a method parameter has not been annotated with a @PathParam("bar")
> 
> Actually, that is the case. I did not annotate anything with "bar". I'll 
> run the changes again. but I might be able to respond monday.
> 
> Again, my thanks.
> 
> Gabo
> 
> 
> Sergey Beryozkin wrote:
>> Hi Gabo
>>
>>>
>>> Gabo Manuel wrote:
>>>> Hi Sergey,
>>>>
>>>> Any specifics on when the fix regarding regex would be uploaded to 
>>>> any snapshot?
>>
>> This fix is definitely in the 2.1.4-snapshot source tree - but the 
>> actual downloadable jar has not been produced yet.
>>
>>>>
>>>> Also example I have the following annotations:
>>>>
>>>>    @GET
>>>>    @Path("/search")
>>>>    @ProduceMime("application/xml")
>>>>    public Accounts getList
>>>>
>>>> And I try to access "/search/additional/path/here", if no other 
>>>> operation matches the path, i.e. no method annotated with 
>>>> "/search/additional", shouldn't the JAX-RS engine map to the method 
>>>> with "/search"?
>>
>> No. It would actually match @Path("/search") but the final regex group 
>> will contain /additional/path/here
>> and according to the spec only if it's either empty or '/' then the 
>> match is accepted.
>>
>>>>
>>>> When I change the @Path to "/search{bar:.*}" or "/search/{bar:.*}", 
>>>> I only get the response: JAXBException occurred : Premature end of 
>>>> file. There is no exception or stacktrace server side or client side.
>>
>> Actually, looks like you're building from the source ? Please enable a 
>> fine-level logging, a default web application exception handler should 
>> report a message. It seems though it won't report more than what 
>> you've got, it does seem like the failure occurs when a JAXB provider 
>> deserializes the request body ay am early XML parsing time.
>> Which says that it's a GET request but a method parameter has not been 
>> annotated with a @PathParam("bar") ?
>>
>> Thanks, Sergey
>>
>>>> interceptors, both in and out, function ok and it does not go the 
>>>> the fault interceptor chain. What it does not do however, is go 
>>>> inside the method.
>>>>
>>>> Again, my thanks.
>>>>
>>>> Gabo
>>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com 
>> Version: 8.0.176 / Virus Database: 270.9.17/1844 - Release Date: 12/11/2008 8:58 PM
>>
>>   
>


Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > No. It would actually match @Path("/search") but the final regex 
group will contain /additional/path/here
 > and according to the spec only if it's either empty or '/' then the 
match is accepted.

I am getting this error trace:

INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: .No operation matching request path 
/search/accountid=1+and+balance+between+1+and+2/accountid/1/10 is found, 
ContentType : application/xml; charset=ISO-8859-1, Accept : */*.
    at 
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:206)
    at 
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:66)

 > Actually, looks like you're building from the source ?

ahh, no... i just downloaded the binary.

 > a method parameter has not been annotated with a @PathParam("bar")

Actually, that is the case. I did not annotate anything with "bar". I'll 
run the changes again. but I might be able to respond monday.

Again, my thanks.

Gabo


Sergey Beryozkin wrote:
> Hi Gabo
>
>>
>> Gabo Manuel wrote:
>>> Hi Sergey,
>>>
>>> Any specifics on when the fix regarding regex would be uploaded to 
>>> any snapshot?
>
> This fix is definitely in the 2.1.4-snapshot source tree - but the 
> actual downloadable jar has not been produced yet.
>
>>>
>>> Also example I have the following annotations:
>>>
>>>    @GET
>>>    @Path("/search")
>>>    @ProduceMime("application/xml")
>>>    public Accounts getList
>>>
>>> And I try to access "/search/additional/path/here", if no other 
>>> operation matches the path, i.e. no method annotated with 
>>> "/search/additional", shouldn't the JAX-RS engine map to the method 
>>> with "/search"?
>
> No. It would actually match @Path("/search") but the final regex group 
> will contain /additional/path/here
> and according to the spec only if it's either empty or '/' then the 
> match is accepted.
>
>>>
>>> When I change the @Path to "/search{bar:.*}" or "/search/{bar:.*}", 
>>> I only get the response: JAXBException occurred : Premature end of 
>>> file. There is no exception or stacktrace server side or client side.
>
> Actually, looks like you're building from the source ? Please enable a 
> fine-level logging, a default web application exception handler should 
> report a message. It seems though it won't report more than what 
> you've got, it does seem like the failure occurs when a JAXB provider 
> deserializes the request body ay am early XML parsing time.
> Which says that it's a GET request but a method parameter has not been 
> annotated with a @PathParam("bar") ?
>
> Thanks, Sergey
>
>>> interceptors, both in and out, function ok and it does not go the 
>>> the fault interceptor chain. What it does not do however, is go 
>>> inside the method.
>>>
>>> Again, my thanks.
>>>
>>> Gabo
>>>
>>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.176 / Virus Database: 270.9.17/1844 - Release Date: 12/11/2008 8:58 PM
>
>   

Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

>
> Gabo Manuel wrote:
>> Hi Sergey,
>>
>> Any specifics on when the fix regarding regex would be uploaded to any snapshot?

This fix is definitely in the 2.1.4-snapshot source tree - but the actual downloadable jar has not been produced yet.

>>
>> Also example I have the following annotations:
>>
>>    @GET
>>    @Path("/search")
>>    @ProduceMime("application/xml")
>>    public Accounts getList
>>
>> And I try to access "/search/additional/path/here", if no other operation matches the path, i.e. no method annotated with 
>> "/search/additional", shouldn't the JAX-RS engine map to the method with "/search"?

No. It would actually match @Path("/search") but the final regex group will contain /additional/path/here
and according to the spec only if it's either empty or '/' then the match is accepted.

>>
>> When I change the @Path to "/search{bar:.*}" or "/search/{bar:.*}", I only get the response: JAXBException occurred : Premature 
>> end of file. There is no exception or stacktrace server side or client side.

Actually, looks like you're building from the source ? Please enable a fine-level logging, a default web application exception 
handler should report a message. It seems though it won't report more than what you've got, it does seem like the failure occurs 
when a JAXB provider deserializes the request body ay am early XML parsing time.
Which says that it's a GET request but a method parameter has not been annotated with a @PathParam("bar") ?

Thanks, Sergey

>> interceptors, both in and out, function ok and it does not go the the fault interceptor chain. What it does not do however, is go 
>> inside the method.
>>
>> Again, my thanks.
>>
>> Gabo
>>
> 



Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

I am currently testing 2.1.4-snapshot.

Gabo

Gabo Manuel wrote:
> Hi Sergey,
>
> Any specifics on when the fix regarding regex would be uploaded to any 
> snapshot?
>
> Also example I have the following annotations:
>
>    @GET
>    @Path("/search")
>    @ProduceMime("application/xml")
>    public Accounts getList
>
> And I try to access "/search/additional/path/here", if no other 
> operation matches the path, i.e. no method annotated with 
> "/search/additional", shouldn't the JAX-RS engine map to the method 
> with "/search"?
>
> When I change the @Path to "/search{bar:.*}" or "/search/{bar:.*}", I 
> only get the response: JAXBException occurred : Premature end of file. 
> There is no exception or stacktrace server side or client side. The 
> interceptors, both in and out, function ok and it does not go the the 
> fault interceptor chain. What it does not do however, is go inside the 
> method.
>
> Again, my thanks.
>
> Gabo
>

Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

Any specifics on when the fix regarding regex would be uploaded to any 
snapshot?

Also example I have the following annotations:

    @GET
    @Path("/search")
    @ProduceMime("application/xml")
    public Accounts getList

And I try to access "/search/additional/path/here", if no other 
operation matches the path, i.e. no method annotated with 
"/search/additional", shouldn't the JAX-RS engine map to the method with 
"/search"?

When I change the @Path to "/search{bar:.*}" or "/search/{bar:.*}", I 
only get the response: JAXBException occurred : Premature end of file. 
There is no exception or stacktrace server side or client side. The 
interceptors, both in and out, function ok and it does not go the the 
fault interceptor chain. What it does not do however, is go inside the 
method.

Again, my thanks.

Gabo

Sergey Beryozkin wrote:
> Hi Gabo
>
> Yes it will, I think this fix has already been merged into the 2.1.x
> branch, but the regex-related fixes have not yet. I started back-merging
> yesterday all the fixes I've applied to 2.2 recently but hasn't finished
> yet. 
>
> But the jaxrs support in 2.1.x will be nearly equivalent to what 2.2
> offers, with the only difference that ProduceMime/ConsumeMime are used
> there, some methods on some JAXRS helpers have slightly different
> signatures, plus no FormParam and GenericEntity support...
>
> Cheers, Sergey
>   

RE: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Gabo

Yes it will, I think this fix has already been merged into the 2.1.x
branch, but the regex-related fixes have not yet. I started back-merging
yesterday all the fixes I've applied to 2.2 recently but hasn't finished
yet. 

But the jaxrs support in 2.1.x will be nearly equivalent to what 2.2
offers, with the only difference that ProduceMime/ConsumeMime are used
there, some methods on some JAXRS helpers have slightly different
signatures, plus no FormParam and GenericEntity support...

Cheers, Sergey

-----Original Message-----
From: Gabo Manuel [mailto:kmanuel@solegysystems.com] 
Sent: 05 December 2008 04:34
To: users@cxf.apache.org
Subject: Re: [JAX-RS][PathParam] object field injection

Hi Sergey,

 > @Path("/search{bar:.*}")
 > public Accounts getList(@PathParam("bar") List<PathSegment> segments)
{}

Thanks for the heads up. I'll take note of that.

Just to follow up on another issue. Will the fix regarding having JAX-RS

and JAX-WS annotations in one method be released together with these 
regex-related changes?

Gabo


Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > @Path("/search{bar:.*}")
 > public Accounts getList(@PathParam("bar") List<PathSegment> segments) {}

Thanks for the heads up. I'll take note of that.

Just to follow up on another issue. Will the fix regarding having JAX-RS 
and JAX-WS annotations in one method be released together with these 
regex-related changes?

Gabo


Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

> Hi Sergey,
>
> > @Path({filter:.*})
> > public Response search(@PathParam("") SearchFilter bean) {

Will do it shortly once I'm done with the spring security stuff

>
> Thanks for pointing me in the right direction. I had changed it as follows:
>
>    @GET
>    @Path("/search.*")
>    public Accounts getList(
>            @Context
>            UriInfo uriinfo
>            ) {
>

Even though it works for the moment it probably won't eventually. As I've learnt yesterday, regular expressions can be specified as 
part of uri template variables only, which is now supported on the trunk. And the above '.*' will have to be escaped

So you'd have to eventually do
@Path("/search{bar:.*}")

So the PathParam("bar") would capture everything - but you wont have to use it. Now that lists of path segments are supported, you 
can do

@Path("/search{bar:.*}")
public Accounts getList(@PathParam("bar") List<PathSegment> segments) {}

so if you have /search only then this list will be empty (or null ?). if you do search/bar, it will contain /bar, if you do 
search/bar/foo then bar and foo will be two seperate list entries, so you won't have to parse. Plus segment specific matric 
parameters will be available too

Cheers, Sergey

> From here I'll just parse the path_info.
>
> Again my thanks.
>
> Gabo
> 



Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > @Path({filter:.*})
 > public Response search(@PathParam("") SearchFilter bean) {

Thanks for pointing me in the right direction. I had changed it as follows:

    @GET
    @Path("/search.*")
    public Accounts getList(
            @Context
            UriInfo uriinfo
            ) {

 From here I'll just parse the path_info.

Again my thanks.

Gabo


Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

> Hi Sergey,
>
> > you don't need @PathParam annotations inside SearchFilter
> Thanks for the input. This one is noted.
>
> > If yes - then it's not possible at the JAX-RS level, you'd need to
> have a seperate method to start with

ok - if you prefer using path segments

>
> I might have to go for this one for now. However, wouldn't it be easier if I could just have one method have multiple paths 
> pointing to it? Something like @Path("path1", "path2").

JAXRS @Path does not have multiple values, one option is to have multiple methods but to delegate to a common implementation.

Not sure how to have the same method when multiple requests are used. One can have @Path with a 'greedy' regular expression but in 
this case you'd need to parse the resulting path value intop individual fragments yourself.
Perhaps another option is to use either JAX-RS PathSegment, specifically do something like

@Path({filter:.*})
public Response search(@PathParam("filter") List<PathSegment>) {
}

so that all the path segments are captuted in a list, or we can do it with our extension :

@Path({filter:.*})
public Response search(@PathParam("") SearchFilter bean) {
}

I'll look into it a bit later...

Cheers, Sergey

>
> Again, my thanks.
>
> Gabo 


Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > you don't need @PathParam annotations inside SearchFilter
Thanks for the input. This one is noted.

 > If yes - then it's not possible at the JAX-RS level, you'd need to 
have a seperate method to start with

I might have to go for this one for now. However, wouldn't it be easier 
if I could just have one method have multiple paths pointing to it? 
Something like @Path("path1", "path2").

Again, my thanks.

Gabo

Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo

> Hi Sergey,
>
> > You don't need to put @PathParam-annotate inidividual fileds in a
> bean like SearchFilter, just having proprty setters
> > will do.
>
> As soon as I remove the empty @PathParam, I get the premature end of file exception:

Not sure about this one - but I didn't suggest removing the empty @PathParam(""), it should still be

@Path({foo}/{bar})
someMethod(@PathParam("") SearchFilter filer)

as it indicates to the runtime that individual path segments need to be injected as properties into a SearchFilter bean. What I was 
saying was that you don't need @PathParam annotations inside SearchFilter which I noticed in your original example.

> Where/how should I put the @DefaultValue for @PathParam? Note that the method parameter is a java object. I annotated my method as 
> @Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow}") which forces me to access the page as is.

I'm not sure I understand but let me try.

If you do requests like "GET /search/someCondition" you'd still like the method annotated with the
@Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow} be invoked, and as no sortString/startingRow/lastRow are 
available, you'd like default values for sortString/etc injected into SearchFilter ?

If yes - then it's not possible at the JAX-RS level, you'd need to have a seperate method to start with say just
@Path("/search/{whereCondition}") and handle default values at the SearchFilter bean level, that is, if no value has been injected 
then assume some default value for a given property.

A JAX-RS compliant approach is to have all your path variables as method parameters, like this
getIt(@DefaultValue("bar") @PathParam("whereCondition"), ....)

but obviously it makes a signature more brittle/verbose.

Or do you have something else in mind ?

>
> Could I have some sample on injecting via QueryParams? I have tried adding @QueryParam to all the setters of SearchFilter object 
> while having the method annotated as follows:
>
> @GET
> @Path("/search")
> @ProduceMime("application/xml")
> public Accounts getList(
>        @QueryParam("")
>        SearchFilter sf
>        ) {
>

This looks correct.
Here's fragment from my test :

public static class CustomerBean {
private String a;
private Long b;
public void setA(String aString) {
this.a = aString;
}
public void setB(Long bLong) {
this.b = bLong;
}
public String getA() {
return a;
}
public Long getB() {
return b;
}
}

public class Customer {
public void testQueryBean(@QueryParam("") CustomerBean cb){}
}

testcode :

messageImpl.put(Message.QUERY_STRING, "a=aValue&b=123");
...
assertEquals("aValue", cb.getA());
assertEquals(new Long(123), cb.getB());


so if you have a query variable named 'a' then you need to have a setA(...) method. Note, no @QueryParam annotations on the 
CustomerBean class.

I think using a query can be better if you'd like to avoid having multiple methods.

Hope it helps, Sergey

> Again, my thanks.
>
> Gabo 


Re: [JAX-RS][PathParam] object field injection

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

 > You don't need to put @PathParam-annotate inidividual fileds in a 
bean like SearchFilter, just having proprty setters
 > will do.

As soon as I remove the empty @PathParam, I get the premature end of 
file exception:

Caused by: org.xml.sax.SAXParseException: Premature end of file.
        at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
        at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
        at 
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1411)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1037)

 > I think @DefaultValue can now be applied to any JAXRS-annotated 
method parameter, be it @PathParam or @QueryParam or
 > @HeaderParam, can please give it a try ? I need to verify but I 
reckon putting @DefaultValue either on the the method
 > itself (applies to all parameters) or on the class resource (applies 
to all resource methods) should work too - but I
 > don't rememeber at the moment

Where/how should I put the @DefaultValue for @PathParam? Note that the 
method parameter is a java object. I annotated my method as 
@Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow}") 
which forces me to access the page as is.

 > Yes, same should be possible for QueryParams, this CXF extension is 
supported for PathParam and QueryParam but can
 > easily be extended to support HeaderParams, etc

Could I have some sample on injecting via QueryParams? I have tried 
adding @QueryParam to all the setters of SearchFilter object while 
having the method annotated as follows:

@GET
@Path("/search")
@ProduceMime("application/xml")
public Accounts getList(
        @QueryParam("")
        SearchFilter sf
        ) {

Again, my thanks.

Gabo

Re: [JAX-RS][PathParam] object field injection

Posted by Sergey Beryozkin <se...@progress.com>.
Hi

> Sorry for the misleading subject, it was the error I encountered
> earlier. forgot the @PathParam("") in the method.
>
> Gabo Manuel wrote:
>> Hi all,
>>
>> I am currently trying to have the following work. Initially I have a
>> service as follows:
>>
>>    @GET
>>    @Path("/search/{whereCondition}/{sortString}/{startingRow}/{lastRow}")
>>    @ProduceMime("application/xml")
>>    public Accounts getList(
>>            @PathParam("")
>>            SearchFilter sf
>>            ) {
>>        return super.getList(sf);
>>    }
>>
>> Since there is no means to add a body to an HTTP GET, I used the field
>> injection using @PathParam. I had the SearchFilter file annotated as
>> follows:
>>    @PathParam("whereCondition")
>>    private String whereCondition;
<snip/>

You don't need to put @PathParam-annotate inidividual fileds in a bean like SearchFilter, just having proprty setters
will do.


>>
>> I'm trying to follow the example in
>> (http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html). The code works
>> perfect when I access /search/mywhere/mysort/1/10.
>>
>> I am also wondering if it is possible for the parameters to have
>> defaults, i.e. the service to become accessible if lastRow is omitted.
>> e.g. /search/mywhere/mysort/1 would still be accessible with lastRow
>> defaulting to 10.
>>
>> As per user's guide, @DefaultValue is only useable for @QueryParam,

I think @DefaultValue can now be applied to any JAXRS-annotated method parameter, be it @PathParam or @QueryParam or @HeaderParam, 
can please give it a try ? I need to verify but I reckon putting @DefaultValue either on the the method itself (applies to all 
parameters) or on the class resource (applies to all resource methods) should work too - but I don't rememeber at the moment

>> however, injecting the values to object fields is only applicable to
>> @PathParam. Is it possible to have @QueryParam inject to object fields?

Yes, same should be possible for QueryParams, this CXF extension is supported for PathParam and QueryParam but can easily be 
extended to support HeaderParams, etc

Cheers, Sergey

>>
>> As of the moment, the only work-around I could think of is avoid the
>> use of object in GET and have everything as @QueryParam.
>>
>> Again, my thanks.
>>
>> Gabo
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com
>> Version: 8.0.175 / Virus Database: 270.8.5/1757 - Release Date: 10/30/2008 2:35 PM
>>
>>
>