Hi,
I'm writing my first MessageBodyWriter, one that produces PDFs. Our PDFs can be localized to various languages, so I want to use the HTTP Accept-Language header to determine the language that the PDF should be generated in.
The MessageBodyWriter.writeTo() method has an HttpHeaders parameter, but it is the outbound headers, not the inbound ones.
The only think I can think of is to set the Content-Language header in my annotated GET method, and then read the outbound header in my writeTo() method. It changes my resource code from this though:
@GET
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
public JAXBElement<InvoiceType> retrieveInvoice(@PathParam("id") Long id) {
InvoiceType invoice = findInvoice(id);
return OBJECT_FACTORY.createInvoice(invoice);
}
to:
@Context
protected HttpServletRequest httpRequest;
...
@GET
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON, "application/pdf"})
public Response retrieveInvoice(@PathParam("id") Long id) {
InvoiceType invoice = findInvoice(id);
GenericEntity<JAXBElement<InvoiceType>> entity = new GenericEntity<JAXBElement<InvoiceType>>(
invoice) {
};
return Response.status(Status.OK).entity(entity).header(HttpHeaders.CONTENT_LANGUAGE, determineContentLanguage(httpRequest).build();
}
I'm hoping I'm missing something, and that I can keep my first method, only having to change the @Produces.
I'm using Jersey 1.5.1.1.
Any help or thoughts appreciated in advance.
Thanks,
Charles