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