泽西岛新手 - 在资源中获取不支持的媒体类型
我是泽西岛和 REST 的新手,所以如果我的问题太愚蠢,请原谅。我有一个名为 Places 的简单资源,它应该支持 GET 操作,该操作根据输入变量返回一些兴趣点。以下是输入字符串和类:
错误:
HTTP 415 - Unsupported Media Type
输入 URL:
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;
}
}
I'm new to Jersey and REST so please pardon if my question is too stupid. I have a simple resource called Places, and it should support a GET
operation which returns some point of interest based on the input variable. Here are the input string and the class:
Error:
HTTP 415 - Unsupported Media Type
Input URL:
http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food
Class:
@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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有
@QueryParam
,@DefaultValue
将无法工作。尝试将@QueryParam
注释添加到sensor
参数(请参阅 DefaultValue javadoc)@DefaultValue
does not work without@QueryParam
. Try adding the@QueryParam
annotation to thesensor
-argument (see DefaultValue javadoc)请确保 [url] 的其余部分已映射到您的 web.xml 中
please make sure rest [of the url] is mapped in your web.xml