I’m using Jersey to create RESTful API resources, and ResponseBuilder to generate the response.
Example code for the RESTful resource:
public class infoResource{
@GET
@Path("service/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getCompany(@PathParam("id")String id) {
//company is just a POJO.
Company company = getCompany(id);
return Response.status(200).entity(company).build();
}
}
In the response, it’s returning chunked transfer encoding in the response headers. What is the proper way in the “Jersey world” to have it return the Content-Length header instead of the Transfer-Encoding: chunked header in the response headers?
Selecting
Content-LengthorTransfer-Encodingis just those Containers choice. It’s really a matter of buffer size.One possible solution is providing a
SevletFilterwhich buffers all those marshalled bytes and setsContent-Lengthheader value.See this page.