REST Service doesn't work after a simple change
I follow this tutorial to learn some REST services and AJAX calls: http://www.mkyong.com/webservices/jax-rs/integrate-jackson-with-resteasy/
I changed this endpoint:
@GET
@Path("/get")
@Produces("application/json")
public Product getProductInJSON() {
Product product = n开发者_StackOverflowew Product();
product.setName("iPad 3");
product.setQty(999);
return product;
}
to this one, in order to return the product in the jsonp format:
@GET
@Path("/get?callback={name}")
@Produces("application/javascript")
public String getProductInJSON(@PathParam("name") String callback){
Product product = new Product();
product.setName("iPad 3");
product.setQty(999);
String productString = callback + "({" + product.toString() + "})";
return productString;
}
with the toString() of product:
@Override
public String toString() {
return "name:" + name + "," + "qty:" + qty;
}
But now, when I check ir the URI works in the browser, with:
http://localhost:8080/restws/json/product/get?callback=process
i have this error message:
HTTP ERROR: 404
Could not find resource for relative : /json/product/get of full path: http://localhost:8080/restws/json/product/get?callback=process
RequestURI=/restws/json/product/get
Can somebody help me with understanding why it's giving me this error after this minor changing? Thanks
A query parameter isn't part of the @Path. You should handle them with @QueryParam as shown in the Jersey User Guide.
精彩评论