Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of @Produces, @GET, @Path and @QueryParam before function definition

Tags:

java

eclipse

I am new to java. I was looking the below code.

@Produces("text/xml")
@GET
@Path("/xml/search")
public Object searchXML(@QueryParam("query") String query,
        @QueryParam("granularity") String granularity) {
    return search(query, granularity);
}

I couldn't understand the uses of @Produces, @GET, @Path and @QueryParam before function definition in above code. Can anybody put some light on this. Thanks

like image 440
piku Avatar asked Jan 11 '13 04:01

piku


1 Answers

Those anotations are defined by JAX-RS, a Standard for RESTful Web Services.

In the example above, it mean the method will handle a:

  • GET request

  • on path "/xml/search"

  • and map the query argument "query" to String query argument,

  • as well as the "granularity" to granularity

  • the resulting content-type will be "text/xml"

(and it will probably call a custom marshaller for this)

(see this page for a reference)

like image 184
aldrinleal Avatar answered Sep 17 '22 05:09

aldrinleal