2

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 :(

jamesmortensen
  • 33,636
  • 11
  • 99
  • 120
Michele
  • 6,126
  • 2
  • 41
  • 45
  • You're returning a List of Index objects. Is this class (Index) serializable, and marked with @XMLRootElement? – BWitched Mar 12 '12 at 18:11
  • @BWitched jep, i also tested the Method with void as returnvalue, still dont work :( – Michele Mar 12 '12 at 19:17
  • Maybe you've already tried but, have you captured the http package sent (o better, the one which arrives the server)? Just to make sure that it's 100% correct. Another idea, I've had some problems with Jersey that got solved adding a "/" at the begining of the path: @Path("/search") – BWitched Mar 13 '12 at 19:38
  • It look like you need to provide the correct content type for the server: `curl ... -H "Content-Type: application/xml"`. – dma_k Mar 13 '12 at 21:39
  • @dma_k i already send the ContentType in my curl statement at the end, +Bwitched tested it with /search, still nothing, i will continue to test with whireshark and see whats posted to the server. – Michele Mar 14 '12 at 07:36
  • Ah, sorry, haven't noticed that. I would suggest then to increase log level and see where it breaks. Maybe starting debugging from top servlet would be more efficient... – dma_k Mar 14 '12 at 10:35
  • Does anyone know how to get jersey to log meaningful messages about unmarshalling errors? That would probably be the best answer here. – Damon Smith Jan 06 '15 at 02:41

1 Answers1

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

Michele
  • 6,126
  • 2
  • 41
  • 45