1

I am trying to implement GET method in Resteasy. I couldn't use QueryParam because there are many search parameters including a complex type. So I thought of using XML. In the code below, both request and response are JAXB classes generated from schema. My question is how the client can pass the request xml?

@GET
@Path("search")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public SearchResponse searchTasks(SearchRequest searchReq)
{

Here's a sample client I created with Jersey. When I make a call, I am getting "415 Unsupported Media Type". Am I passing the XML right? Is it possible to send XML parameter to GET method?

    webResource.accept(MediaType.APPLICATION_XML);
    webResource.type(MediaType.APPLICATION_XML);

    webResource.entity(req,MediaType.APPLICATION_XML);

    SearchResponse return1 = webResource.get(SearchResponse.class); 

I am deploying this in Tomcat.

Thanks for looking into this.

Arav Vijay
  • 251
  • 5
  • 13
  • Your question was already answered in [Jersey client API WebResource accept() not setting MIME header correctly](http://stackoverflow.com/a/7435940/267197). – dma_k Jan 28 '12 at 12:40

1 Answers1

1

The error is caused because you are not setting the Content-Type header when you are making the request. Make sure it is set to Content-Type: application/xml.

On a side note, GET requests usually don't have a request body, although it is possible. I suggest against including one, and using a POST method instead.

Community
  • 1
  • 1
Nick Garvey
  • 2,980
  • 24
  • 31
  • Thanks for the response. But doesn't the following set the content type? - webResource.type(MediaType.APPLICATION_XML); – Arav Vijay Jan 27 '12 at 15:33
  • 2
    **Arav** is right: he made an attempt to set the accepted content type, but did it not in a right way: `webResource.accept()` is actually returning a `Builder` which should be further used. – dma_k Jan 28 '12 at 12:42