能否在JAX-RS资源的一部分中创建PNG图像并直接将其输出到浏览器?
类似于这样:
@Path("img/{externalId}")
@Stateless
@Produces({"image/png"})
public class MyImgResource {
@GET
public Response (@PathParam("externalId") String externalId) {
// create image, write to buffered output stream
return Response.ok().entity(stream).build();
}
}
这个方案可行吗?我需要注意正确的头信息(Content-Type),还是由@Produces
注解完成?能够将图像作为Response
输出吗?我能否从流中构建一个Response
?
return new BufferedInputStream(new FileInputStream("source.png"));
- Socrates