Java Reference
In-Depth Information
http://localhost:8080/actionbazaar/bidService/list/14235/cars
This assumes that the application was deployed under ActionBazaar context. This service
could easily be tested from the web browser.
Using the @QueryParam annotation
The @javax.ws.rs.QueryParam annotation enables you to extract query parameters
and map them to parameters on a method. The annotation is defined as follows:
@Target(value = {ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface QueryParam {
public String value();
}
The following example demonstrates the use of this annotation:
@Path("/bidService")
@Stateless(name="BidService")
public class BidServiceBean {
@GET @Produces("text/plain")
@Path("/list/{userId}/{category}")
public String listBids(
@PathParam("category")String category,
@PathParam("userId")long userId,
@QueryParam("startDate") String startDate,
@QueryParam("endDate") String endDate
) {
...
}
}
This service can be invoked with the following URL from the web browser: ht-
tp://localhost:8080/wse/bidService/list/3232/
cars?startDate=10252012&endDate=10302012. The query parameters startDate and
endDate will be mapped to the start and end date method parameters.
Type conversions
You might have noticed in this sample code that the start and end dates were passed in as
java.lang.Strings . There's no compatible constructor on the java.util.Date
Search WWH ::




Custom Search