Jersey的新功能 - 在资源中获取不受支持的媒体类型

时间:2011-06-17 05:33:36

标签: json rest jax-ws jersey

我是泽西和REST的新手所以请原谅我的问题是否过于愚蠢。我有一个名为Places的简单资源,它应该支持GET操作,该操作根据输入变量返回一些感兴趣的点。这是输入字符串和类:

错误:

HTTP 415 - Unsupported Media Type

输入网址:

http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food

类别:

@Path("/places")
public class Places {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public JSONObject getPlaces(@QueryParam("latitude") double latitude,
            @QueryParam("longitude") double longitude,
            @QueryParam("radius") int radius,
            @QueryParam("types") String types,
            @DefaultValue("true") boolean sensor) {
        GooglePlacesClient google = new GooglePlacesClient();
        JSONObject json = null;

        try {
            String response = google.performPlacesSearch(latitude, longitude, radius, types, sensor);
            json = new JSONObject(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}

2 个答案:

答案 0 :(得分:5)

如果没有@DefaultValue

@QueryParam无效。尝试将@QueryParam注释添加到sensor - 参数(请参阅DefaultValue javadoc

答案 1 :(得分:0)

请确保[url]的其余部分映射到您的web.xml

http://localhost:8080/RESTGO/**`*rest*`**/places