Reputation: 251
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.
Upvotes: 1
Views: 2000
Reputation: 3000
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.
Upvotes: 1