Hi
On 29/07/13 11:52, John Baker wrote:
Hello
I'm having trouble with CXF's JAX-RS implementation. The service is
struggling to match the correct method defined on an interface. Please
consider:
@Path("/update")
public interface MyService {
@PUT
@Path("/{id}")
public void updateFruit(@QueryParam("id") String id, Banana banana);
@PUT
@Path("/{id}")
public void updateAnimal(@QueryParam("id") String id, Dog dog);
}
where both Banana and Dog extend a common object. When making a call to
updateFruit from a jax-rs client, it calls updateAnimal. I've traced the
problem into JAXRSUtils and I'm wondering if there's any solution, or do
these methods need unique paths?
JAX-RS selection algorithm sees these 2 methods as equal candidates.
IMHO having unique paths for different type of resources (from the
client's POV, not from the Java hierarchy perspective) is reasonable
IMHO, but if you prefer or *have to* use the same method signatures, then
use CXF ResourceComparator,
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources
Another approach is to do Subresource locators:
@Path("/update")
public interface MyService {
@Path("/{id}")
public void update(@PathParam("id") String id, @QueryParam("type")
String type) {
if ("banana".equals(type)) {
return new Bananaresource(id);
}
...
}
public class BananaResource {
private String id;
@PUT
public void update(Banana b) {
}
etc
Sergey
Thanks
John