RESTful produz arquivo binário
Sou novo em usar CXF e Spring para fazer serviços da web RESTfu
Este é o meu problema: quero criar um serviço que produza "qualquer" tipo de arquivo (pode ser imagem, documento, txt ou até pdf) e também um XML. Até agora eu recebi este código:
@Path("/download/")
@GET
@Produces({"application/*"})
public CustomXML getFile() throws Exception;
Não sei exatamente por onde começar, por isso seja pacient
EDITAR
Código completo do Bryant Luk (obrigado!)
@Path("/download/")
@GET
public javax.ws.rs.core.Response getFile() throws Exception {
if (/* want the pdf file */) {
File file = new File("...");
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename =" + file.getName())
.build();
}
/* default to xml file */
return Response.ok(new FileInputStream("custom.xml")).type("application/xml").build();
}