Hi
On 31/10/12 15:04, janb wrote:
Hi all,

is it possible with CXF to have two (or more) methods in a single class that
share the same REST URL (@Path annotation) and also the same HTTP Operation
(e.g. @POST) and only differ in Type of a method parameter?

Example:

@Path("user")
public class UserController {

        @POST
        @Path("/search")
        public List<User>  searchUser(SearchType complexSearch) {
                . . .
        }

        @POST
        @Path("/search")
        public List<User>  searchUser(AnotherSearchType anotherSearch) {
                . . .
        }

        . . .
}


No, this option is not supported in JAX-RS. I think there could be few options to get this limitation bypassed:

- Have a single method accepting JAXP Source - assuming it is XML
- Consider introducing a catch-all MultivaluedMap or query bean, assuming it is a form payload, or may be queries.

I guess it also makes sense to use @GET for searching.

Can you provide some more context please ?

Actually, a CXF specific extension may help, called ResourceComparator. You can use it to help the runtime to choose between two equal candidates, such as the two methods above. It can work if the request URI or some headers can provide the extra context, which can help with figuring out if it is SearchType or AnotherSearchType that is 'coming in'

You may also want to have a look at http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-FIQLsearchqueries, may be for the future ref, this is what I'm prioritizing upon...

HTH, Sergey



--
View this message in context: 
http://cxf.547215.n5.nabble.com/JAX-RS-Method-overloading-tp5717638.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