On Mar 10, 2009, at 6:03 PM, Jaka Jančar wrote:
> You could just add paramA and paramB to a single @GET-annotated
> method, then call the appropriate private method.
>
Right.
It is only possible to match based on the URI path and what media type
is produced and/or consumed.
JAX-RS does not perform matching and method selection for query
parameters, as this encourages an RPC-centric approach to the design
of the application, in addition to potential ambiguities (what if
multiple values are present, what if query param A and B are present,
what if default values are required in absence, does the order of
query parameters in the URI matter?)
Paul.
> But maybe instead of returning the correct response depending on the
> query param you should consider the path instead?
>
> Something like:
> @GET @Path("/paramA") public String getParamA() {...};
> @GET @Path("/paramB") public String getParamB() {...};
>
> Depends on what "paramA" actually is.
>
> Jaka
>
> On 10. Mar 2009, at 17:51, Javi Moran wrote:
>
>> Hello,
>>
>> I am a newcomer to the jersey project, I am playing with the
>> resources
>> and I have the following question/problem.
>>
>> I have a class which is a resource and I added to it two methods with
>> the annotation @GET. I wanted one of them was the one invoked when in
>> the http request URL I had a paramater paramA and a second method
>> to be
>> invoked when the http request I received had a parameter paramB. The
>> code is:
>>
>> "
>> @GET
>> public String getParamA(@QueryParam("paramA") String paramA) {
>>
>> if (paramA == null) {
>> throw new
>> WebApplicationException(Response.Status.PRECONDITION_FAILED);
>> }
>>
>> return "Echo " + paramA;
>> }
>>
>> @GET
>> public String getParamB(@QueryParam("paramB") String paramB) {
>>
>>
>> if (paramB == null) {
>> throw new
>> WebApplicationException(Response.Status.PRECONDITION_FAILED);
>> }
>> return "Echo " + paramB;
>>
>> }
>> "
>>
>> When I run this I get the runtime error:
>>
>> GRAVE: A resource, class org.masterswl.rest.HelloWorldResource, has
>> ambiguous resource method for HTTP method GET and output mime-type:
>> text/plain. The problematic mime-type sets (as defined by @Produces
>> annotation at Java methods getParamA and getParamB) are [text/
>> plain] and
>> [text/plain]
>> 10-mar-2009 17:40:47
>> com.sun.jersey.server.impl.application.WebApplicationImpl
>> newResourceClass
>>
>> com.sun.jersey.api.container.ContainerException: Fatal issues found
>> at
>> class org.masterswl.rest.HelloWorldResource. See logs for more
>> details.
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.newResourceClass(WebApplicationImpl.java:286)
>>
>> So, the question is ?
>>
>> (*) Is there an error in jersey or in my installation or isn't
>> there ?
>> (*) If there isn't an error, cannot you design the things in the
>> way
>> I did ?
>>
>> ---
>> Javier Moran Rua
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>