Set a Response Body in JAX-RS
Read JSON directly
@POST
@Path("listwrapper/")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String getListViaWrapperHTTPRequest(List<String> list) {
System.out.println("getListViaWrapperHTTPRequest");
for(String param: list){
System.out.println("
param
=" + param);
}
return "SOME_RESPONSE";
}
Read HTTP request body
@POST
@Path("listraw/")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String getListViaRawHTTPRequest(@Context HttpServletRequest request, byte[] bodyBytes) {
System.out.println("getListViaRawHTTPRequest");
System.out.println("Content-Type: " + request.getContentType().toString());
String body = new String(bodyBytes);
System.out.println("body=" + body);
return "SOME_RESPONSE";
}