I have seen an example of this where you can iterate over the class methods
to see if there is a match and if there is not indicate so in the
ResourceComparator.  However, I have probably vastly oversimplified this as
we have a 1/2 dozen methods on the SEI,   I don't want to have to and
 reinvent the wheel apply all the CXF matching rules to each method.   Is
there a Utility class somewhere to help with this?

In the comparator I want to take the request URI and compare it to each of
the methods, taking into account all of the path variables just as CXF
does. if there is no match have CXF move onto the next class.


On Thu, Jun 27, 2013 at 4:35 AM, Sergey Beryozkin <[email protected]>wrote:

> Hi
>
> On 27/06/13 02:37, Bill Smith wrote:
>
>> I think I have what is a fairly common problem.
>>
>> I have two classes with the same mapping
>>
>>
>> @Path("\")
>> interface class1{
>>   @Path("\method1")
>>    public void method1
>>
>> }
>>
>> @Path("\")
>> interface class2{
>>   @Path("\method2")
>>    public void method2
>>
>> }
>>
>> When calling \class2 I get an error that the resource can not be located.
>>
>>
>> The CXF Documentation describes this problem :
>>
>> "However, in some cases, users have reported the algorithm being somewhat
>> restrictive in the way multiple resource classes are selected. For
>> example,
>> by default, after a given resource class has been matched and if this
>> class
>> has no matching resource method, then the algorithm stops executing,
>> without attempting to check the remaining matching resource classes."
>>
>> and suggests using a ResourceComparator.
>>
>> I need to find an example of how to use this.  My understanding is that
>> the
>> comparator will be invoked and a decision will be made if the class is a
>> good match.  However in my case both classes are a good match and the
>> method comparison will fail.  As described in the CXF docs, how do I get
>> CXF to check the remaining matching resource classes?
>>
>>  FYI, this case is supported on the trunk with JAX-RS 2.0 allowing for
> the proper selection of methods when multiple root resource have exactly
> the same path expression.
>
> By indeed, ResourceComparator can always be used to adjust the way the
> selection is made. In your case, you'd need to override
>
> int compare(ClassResourceInfo cri1,
>             ClassResourceInfo cri2,
>             Message message);
>
> method, do "message.get(Message.REQUEST_**URI);", check if the returned
> property has "method1" or "method2", and based on chat order 'cr1' & 'cr2'
> as needed. Use ClassResourceInfo.**getServiceClass() to find out which
> root Class a given ClassResourceInfo represents.
>
> HTH, Sergey
>

Reply via email to