I have been working on a RESTful webservice using Jersey. I have created my first service and now I am attempting to send requests. Here is my single POST method:
@POST
@Path("getQuote")
@Consumes(MediaType.WILDCARD )
@Produces(MediaType.APPLICATION_XML)
public Response getQuote(
@FormParam("effectiveTime") String effectiveTime,
@FormParam("responseType") String responseType,
@FormParam("transform") String transform,
@FormParam("data") String data,
@FormParam("dataType") String dataType,
@FormParam("source") String source) {
String output = "";
try {
Map<String, String> formParams = new HashMap<String, String>();
formParams.put("effectiveTime",effectiveTime);
formParams.put("responseType",responseType);
formParams.put("transform",transform);
formParams.put("data",data);
formParams.put("dataType",dataType);
formParams.put("source",source);
//do stuff
} catch (Exception e) {
System.out.println(e);
output = "Error";
}
return Response.status(200).entity(output).build();
}
I have a HTML test form I can use to send data, and have checked the content type is correct using a RequestBin. Here are some of the headers from the request:
Host: requestb.in
Content-Length: 16176
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0
Content-Type: application/x-www-form-urlencoded
I have tried the following content types with no luck:
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Consumes("application/x-www-form-urlencoded")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Consumes(MediaType.APPLICATION_XML)
@Consumes(MediaType.WILDCARD )
& unspecified (no @Consumes annotation)
I am unsure how to debug this request. I have tried using curl to test as well with the following params:
curl --data "effectiveTime=1o1o1&dataType=lolo&data=lololol&transform=&responseType=lolol" http://localhost:8080/services/ahrdi/getQuote
with the same result.
eclipse was re using the original war without any alterations as I had not refreshed my project after running mvn compile war:war
I ran mvn clean, refreshed my project in the project browser, ran mvn compile war:war and my restarted the server and requests are now accepted.