単純なJAX-RSサーバーアプリケーションがあります。
@GET
@Path("/getImage/{key}")
@Produces("image/jpeg")
public final BufferedImage getImageResource(@PathParam("key") String key) {
final File file = new File(key); // the key will be "cat.jpeg" e.t.c.
final BufferedImage image = ImageIO.read(new FileInputStream(file));
return image;
}
WARファイルをTomcatサーバー(6.0)にデプロイした後、次の手順を実行します。
http://localhost:8080/resource-service/getImage/cat.png
問題:
1)新しいファイル(キー)では、Tomcatルートディレクトリに移動します。クラス周辺のプロジェクトディレクトリ内のリソース用のデフォルトのルートフォルダのようなものが欲しいのですが。
2)私が理解しているようにBufferedImageを返すことは許可されていません、私は500エラーメッセージを受け取ります:
HTTP Status 500 - Could not find MessageBodyWriter for response object of type: java.awt.image.BufferedImage of media type: image/jpeg
アドバイスやリンクをいただければ幸いです。前もって感謝します!