Content-Type
CXF (v2.6.3) 内で独自のレンダリングを行う場合、 の設定に問題があります@WebMethod
。
次のパターンは正常に機能します。
@Path("/foo")
@WebService
public class FooService {
@Path("/bar")
@Produces({ "text/plain" })
@GET
@WebMethod
public String bar() {
return "hi";
}
これは、私が期待"hi"
するヘッダーで http-client に戻ります。Content-Type: Content-Type: text/plain
ただし、 response を使用して独自のレンダリングを実行しようとすると、OutputStream
適切"hi"
に返されますが、@Produces
注釈は無視され、デフォルトのtext/xml
コンテンツ タイプが返されます。これは私が自分自身を呼んでも真実ですsetContentType(...)
。
@Path("/heartbeat2")
@Produces({ "text/plain" })
@WebMethod
@Get
public void heartbeat2() {
HttpServletResponse response = messageCtx.getHttpServletResponse();
response.getOutputStream().write("hi".getBytes());
// fails with or without this line
response.setContentType("text/plain");
}
出力は次のとおりです。
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: 2
Connection: keep-alive
Server: Jetty(8.1.9.v20130131)
hi
自分の出力を出力ストリームに直接レンダリングし、コンテンツタイプを適切に設定する方法はありますか? 前もって感謝します。