Debugging Jersey Unmarshalling Error - Bad Request syntactically incorrect

邮差的信 提交于 2019-12-11 04:35:55

问题


I am building a REST Webservice with the help of Jersey on Glassfish. Now I am struggeling with my custom input Source for my searchQuerys.

If have a search Method:

@POST
@Path("search")
@Consumes({"application/xml", "application/json"})
@Produces({"application/xml", "application/json"})
public List<Index> search(SearchQuery searchqry) {
   ...
}

And the Class 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;
}

And my call:

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

I tried a restconsole to send the XML request, but I get the same error:

HTTP Status 400 - Bad Request


type Status report

messageBad Request

des criptionThe request sent by the client was syntactically incorrect (Bad Request).


GlassFish Server Open Source Edition 3.1.2

* Closing connection #0

I am missing something essentially or can somebody give me a hint how to debug the unmarshalling part inside the Application Server?

I followed the guide at http://xebee.xebia.in/2011/12/30/example-of-restful-webservice-with-xml-and-json-using-maven-jaxb-jersey-tomcat-and-curl/ and tested varius combination of Annotations but no sucess :(


回答1:


FINALLY found the real reason for my problem: SearchQuery is mapped to "searchQuery" inside XML

TESTClass is mapped to tESTClass inside the XML Entity



来源:https://stackoverflow.com/questions/9660311/debugging-jersey-unmarshalling-error-bad-request-syntactically-incorrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!