You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <se...@iona.com> on 2009/11/05 19:58:17 UTC

Re: JAXRS: Multiple service beans problem

Hi,

See 

http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceComparator.java

it can be registered as jaxrs:server/jaxrs:resourceComparator

The custom implementation will be given a chance to select between multiple
matching class resources or resource methods

thanks, Sergey


Kynan Fraser wrote:
> 
> Done: https://issues.apache.org/jira/browse/CXF-2439
> 
> 
> Sergey Beryozkin wrote:
>> 
>> Hi Kynan
>> 
>> No, not yet. Please open the JIRA for it (make it 'Fix for 2.3')
>> 
>> thanks, Sergey
>> 
>> 
>> Kynan Fraser wrote:
>>> 
>>> Hi Sergey,
>>> 
>>> Was there a JIRA issue opened for this or has it been added as a
>>> feature?
>>> 
>>> Regards,
>>> Kynan
>>> 
>>> 
>>> Sergey Beryozkin-2 wrote:
>>>> 
>>>> Hi
>>>> 
>>>> It's just a JAXRS selection algorithm that dictates it, or rather, it
>>>> does not allow for selecting between multiple resource classes 
>>>> which have the same Path value. Perhaps you may want to consider using
>>>> Path values with custom regular expressions rather than 
>>>> hardcoding unique values into each root class's Path values.
>>>> I kind of like the idea of trying another resource class if the
>>>> initially taken route through the initially chosen root class 
>>>> produces no valid operation - I'll add it to the list...
>>>> 
>>>> Can you explain a bit more please about this issue :
>>>> 
>>>>>>> Not sure if it is related, but also ran into a similar problem,
>>>>>>> where when
>>>>>>> I have two service interfaces like below...where service A and B
>>>>>>> both have a
>>>>>>> common sub-path.  It seems that both /v3/authenticate and
>>>>>>> /v4/authenticate
>>>>>>> are available.  However, /v4/authenticate/validate is not available. 
>>>>>>> No
>>>>>>> sub-path for a method is available in v4 if v3 doesn't have the same
>>>>>>> path.
>>>>>>> If I remove the v3 bean, then both v4 methods are available.
>>>>>>>
>>>>>>> *Take the following from cxf_beans.xml where I define 2 service
>>>>>>> beans:*
>>>>>>>
>>>>>>>   <jaxrs:server id="serviceServer" address="/">
>>>>>>>     <jaxrs:serviceBeans>
>>>>>>>       <ref bean="contactServiceImpl3" />
>>>>>>>       <ref bean="contactServiceImpl4" />
>>>>>>>     </jaxrs:serviceBeans>
>>>>>>>
>>>>>>> *Here are the service interfaces:*
>>>>>>>
>>>>>>> =====
>>>>>>>
>>>>>>> @Path("/v3")
>>>>>>> public interface AuthenticationService {
>>>>>>>     @GET
>>>>>>>     @Path("/authenticate/{uid}:{pass}")
>>>>>>>     public Response authenticate(@PathParam("uid") String username,
>>>>>>> @PathParam("pass") String password);
>>>>>>> }
>>>>>>>
>>>>>>> =====
>>>>>>>
>>>>>>> @Path("/v4")
>>>>>>> public interface AuthenticationService {
>>>>>>>     @GET
>>>>>>>     @Path("/authenticate/{uid}:{pass}")
>>>>>>>     public Response authenticate(@PathParam("uid") String username,
>>>>>>> @PathParam("pass") String password);
>>>>>>>
>>>>>>>     @GET
>>>>>>>     @Path("/authenticate/validate/{token}")
>>>>>>>     public Response validate(@PathParam("token") String token);
>>>>>>> }
>>>>>>>
>>>>>>> =====
>>>> 
>>>> I'm presuming those 2 AuthenticationService(s) are in different
>>>> packages ?
>>>> 
>>>> So if you do "/v4/authenticate/validate/BTaaZUycRa" then no operation
>>>> can be found unless you remove a bean which implements
>>>> AuthenticationService with /v3 ?
>>>> 
>>>> 
>>>> cheers, Sergey
>>>> 
>>>> ----- Original Message ----- 
>>>> From: "David Castro" <ap...@entwash.org>
>>>> To: <us...@cxf.apache.org>
>>>> Sent: Thursday, April 16, 2009 1:59 AM
>>>> Subject: Re: JAXRS: Multiple service beans problem
>>>> 
>>>> 
>>>>> Have my own little conversation going here now ;)   So looking deeper
>>>>> at
>>>>> that other post, apparently you need to have a unique root path name
>>>>> for
>>>>> each service class for the matching to work right now.  Kind of a
>>>>> bummer
>>>>> that you can't have multiple classes with / for a root path and just
>>>>> have
>>>>> CXF search all / path classes for particular sub-resource locators.
>>>>> But at
>>>>> least I know how to get around the issue there.
>>>>>
>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/JAXRS%3A-Multiple-service-beans-problem-tp23069677p26217379.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAXRS: Multiple service beans problem

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

>
> I have run into the same issue, coupled with the fact that this is my 2nd day
> of trying to use cxf.
> can you provide any sort of example as to how this would be used?
> (I ran into the same problem - wanting to provide multiple service
> implementations within a single url pattern. Something like "/service/test1"
> and "/service/test2".

I've added some dcoumentation here :
http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Customselectionbetweenmultipleresources

Note it is only supported in 2.2.5. Please register a custom resourceComparator impl.
>From the ClassResourceInfo you can get the name of the actual class using a getServiceClass() method. Given the service class names 
and the current request URI you can choose if you'd like to impose some custom ordering or not, 0 - if not.
I haven't had time to do a better documentation on this feature yet - but it should be quite straightforward to start using it. Ot 
does requirte some knowledge of the internal api, but to the minimum (ClassResourceInfo.getServiceClass plus new 
UriInfoImpl(message).getPath() and that is probably it).

cheers, Sergey



> Whichever one is listed first in the jaxrs:server is the one that matches.
> Creating multiple jaxrs:server elements didn't help (at least the way i did
> it.)
>
>
> Sergey Beryozkin wrote:
>>
>> Hi,
>>
>> See
>>
>> http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceComparator.java
>>
>> it can be registered as jaxrs:server/jaxrs:resourceComparator
>>
>> The custom implementation will be given a chance to select between
>> multiple matching class resources or resource methods
>>
>> thanks, Sergey
>>


Re: JAXRS: Multiple service beans problem

Posted by Rick Gordon <rg...@gmail.com>.
I have run into the same issue, coupled with the fact that this is my 2nd day
of trying to use cxf.
can you provide any sort of example as to how this would be used?
(I ran into the same problem - wanting to provide multiple service
implementations within a single url pattern. Something like "/service/test1"
and "/service/test2". 
Whichever one is listed first in the jaxrs:server is the one that matches.
Creating multiple jaxrs:server elements didn't help (at least the way i did
it.)


Sergey Beryozkin wrote:
> 
> Hi,
> 
> See 
> 
> http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ResourceComparator.java
> 
> it can be registered as jaxrs:server/jaxrs:resourceComparator
> 
> The custom implementation will be given a chance to select between
> multiple matching class resources or resource methods
> 
> thanks, Sergey
> 
> 
> Kynan Fraser wrote:
>> 
>> Done: https://issues.apache.org/jira/browse/CXF-2439
>> 
>> 
>> Sergey Beryozkin wrote:
>>> 
>>> Hi Kynan
>>> 
>>> No, not yet. Please open the JIRA for it (make it 'Fix for 2.3')
>>> 
>>> thanks, Sergey
>>> 
>>> 
>>> Kynan Fraser wrote:
>>>> 
>>>> Hi Sergey,
>>>> 
>>>> Was there a JIRA issue opened for this or has it been added as a
>>>> feature?
>>>> 
>>>> Regards,
>>>> Kynan
>>>> 
>>>> 
>>>> Sergey Beryozkin-2 wrote:
>>>>> 
>>>>> Hi
>>>>> 
>>>>> It's just a JAXRS selection algorithm that dictates it, or rather, it
>>>>> does not allow for selecting between multiple resource classes 
>>>>> which have the same Path value. Perhaps you may want to consider using
>>>>> Path values with custom regular expressions rather than 
>>>>> hardcoding unique values into each root class's Path values.
>>>>> I kind of like the idea of trying another resource class if the
>>>>> initially taken route through the initially chosen root class 
>>>>> produces no valid operation - I'll add it to the list...
>>>>> 
>>>>> Can you explain a bit more please about this issue :
>>>>> 
>>>>>>>> Not sure if it is related, but also ran into a similar problem,
>>>>>>>> where when
>>>>>>>> I have two service interfaces like below...where service A and B
>>>>>>>> both have a
>>>>>>>> common sub-path.  It seems that both /v3/authenticate and
>>>>>>>> /v4/authenticate
>>>>>>>> are available.  However, /v4/authenticate/validate is not
>>>>>>>> available.  No
>>>>>>>> sub-path for a method is available in v4 if v3 doesn't have the
>>>>>>>> same path.
>>>>>>>> If I remove the v3 bean, then both v4 methods are available.
>>>>>>>>
>>>>>>>> *Take the following from cxf_beans.xml where I define 2 service
>>>>>>>> beans:*
>>>>>>>>
>>>>>>>>   <jaxrs:server id="serviceServer" address="/">
>>>>>>>>     <jaxrs:serviceBeans>
>>>>>>>>       <ref bean="contactServiceImpl3" />
>>>>>>>>       <ref bean="contactServiceImpl4" />
>>>>>>>>     </jaxrs:serviceBeans>
>>>>>>>>
>>>>>>>> *Here are the service interfaces:*
>>>>>>>>
>>>>>>>> =====
>>>>>>>>
>>>>>>>> @Path("/v3")
>>>>>>>> public interface AuthenticationService {
>>>>>>>>     @GET
>>>>>>>>     @Path("/authenticate/{uid}:{pass}")
>>>>>>>>     public Response authenticate(@PathParam("uid") String username,
>>>>>>>> @PathParam("pass") String password);
>>>>>>>> }
>>>>>>>>
>>>>>>>> =====
>>>>>>>>
>>>>>>>> @Path("/v4")
>>>>>>>> public interface AuthenticationService {
>>>>>>>>     @GET
>>>>>>>>     @Path("/authenticate/{uid}:{pass}")
>>>>>>>>     public Response authenticate(@PathParam("uid") String username,
>>>>>>>> @PathParam("pass") String password);
>>>>>>>>
>>>>>>>>     @GET
>>>>>>>>     @Path("/authenticate/validate/{token}")
>>>>>>>>     public Response validate(@PathParam("token") String token);
>>>>>>>> }
>>>>>>>>
>>>>>>>> =====
>>>>> 
>>>>> I'm presuming those 2 AuthenticationService(s) are in different
>>>>> packages ?
>>>>> 
>>>>> So if you do "/v4/authenticate/validate/BTaaZUycRa" then no operation
>>>>> can be found unless you remove a bean which implements
>>>>> AuthenticationService with /v3 ?
>>>>> 
>>>>> 
>>>>> cheers, Sergey
>>>>> 
>>>>> ----- Original Message ----- 
>>>>> From: "David Castro" <ap...@entwash.org>
>>>>> To: <us...@cxf.apache.org>
>>>>> Sent: Thursday, April 16, 2009 1:59 AM
>>>>> Subject: Re: JAXRS: Multiple service beans problem
>>>>> 
>>>>> 
>>>>>> Have my own little conversation going here now ;)   So looking deeper
>>>>>> at
>>>>>> that other post, apparently you need to have a unique root path name
>>>>>> for
>>>>>> each service class for the matching to work right now.  Kind of a
>>>>>> bummer
>>>>>> that you can't have multiple classes with / for a root path and just
>>>>>> have
>>>>>> CXF search all / path classes for particular sub-resource locators.
>>>>>> But at
>>>>>> least I know how to get around the issue there.
>>>>>>
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/JAXRS%3A-Multiple-service-beans-problem-tp23069677p26424304.html
Sent from the cxf-user mailing list archive at Nabble.com.