我正在 Glassfish 上的 Jersey 的帮助下构建 REST Web 服务。现在我正在为我的搜索查询的自定义输入源而苦苦挣扎。
如果有搜索方法:
@POST
@Path("search")
@Consumes({"application/xml", "application/json"})
@Produces({"application/xml", "application/json"})
public List<Index> search(SearchQuery searchqry) {
...
}
和类 SearchQuery:
@XmlRootElement
public class SearchQuery implements Serializable {
private static final long serialVersionUID = 1L;
public SearchQuery() {
}
public SearchQuery(float lat, float lng) {
this.lat = lat;
this.lng = lng;
}
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLng() {
return lng;
}
public void setLng(float lng) {
this.lng = lng;
}
private float lat;
private float lng;
}
我的电话:
curl -v -X POST --data-binary "<SearchQuery><lat>3.3</lat><lng>5.4</lng></SearchQuery>" -H "Content-Type: application/xml" -H "Accept: application/xml" http://localhost:8080/WebApplication1/resources/index/search
我尝试使用 Restconsole 发送 XML 请求,但收到相同的错误:
HTTP 状态 400 - 错误请求
type地位
报告
message错误的请求
描述这
客户端发送的请求语法不正确(Bad
要求)。
GlassFish 服务器开源版
3.1.2
* Closing connection #0
我本质上遗漏了一些东西,或者有人可以给我提示如何调试应用程序服务器内的解组部分吗?
我按照指南进行操作http://xebee.xebia.in/2011/12/30/example-of-restful-webservice-with-xml-and-json-using-maven-jaxb-jersey-tomcat-and-curl/ http://xebee.xebia.in/2011/12/30/example-of-restful-webservice-with-xml-and-json-using-maven-jaxb-jersey-tomcat-and-curl/并测试了注释的各种组合但没有成功:(