Hi Jan
On 27/11/12 10:12, janb wrote:
Hi @all,

I'm wondering about the selection strategy in CXF for different Query
Parameter. The documentation [1] does not cover this at all.

A simple system-test provided the impression to me, that CXF has no valid
selection strategy in place for handling different query parameters. Is this
assumption correct? Should I create a Jira ticket for a better support?

Here is my sample code. No matter which parameter have been provided within
my URL, only and always the first method was selected by CXF.

@Path("/paramTest")
public class MySimpleService {

     @GET
     public String getFoo(@QueryParam("foo") String foo){
         return "foo:" + foo;
     }

     @GET
     public String getFooBar(@QueryParam("foo") String foo,
@QueryParam("bar") String bar){
         return "foo:" + foo + " bar:" + bar;
     }

     @GET
     public String getTest(@QueryParam("test") String test){
         return "test:" + test;
     }
}

[1]
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Overviewoftheselectionalgorithm.


Only URI path segment, HTTP method and in/out media types are taken into consideration when selecting the candidates. If you prefer to have individual methods having the same HTTP Method/Uri Path/Media Types but with specific query parameters then the only way to get it managed is to use a CXF ResourceComparator where, in this case, you can affect the ordering of specific resource methods by checking the current Message.QUERY_STRING available on the CXF Message

A simpler alternative is to have a single method and work with UriInfo, say

@Context
private UriInfo ui;

@GET
public String getFooOrBar() {
    MultivaluedMap<String, String> params = ui.getQueryParameters();
    String foo = params.getFirst("foo");
    String bar = params.getFirst("foo");
    // etc
}

HTH, Sergey



--
View this message in context: 
http://cxf.547215.n5.nabble.com/REST-Method-selection-for-different-QueryParam-s-tp5719187.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to