[英]Return HTTP codes from jersey Chunked response when in error
我有三個服務,比如在澤西文檔中用chunked response描述的服務: https : //jersey.java.net/documentation/latest/async.html
但是我必須添加用戶訪問控制並相應地響應403錯誤代碼,但是沒有辦法在響應中添加狀態或者像返回實體主體類型的服務那樣構建錯誤響應。
有任何想法嗎?
您可以返回Response
而不是ChunkedOutPut
,然后在您的Response
對象中包裝ChunkedOutPut
或錯誤消息,如下所示。
@GET
public Response getChunkedResponse() throws IOException {
// Check access here
if (!authorized()) {
Response.status(403).entity("No Access").build();
} else {
final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);
new Thread() {
public void run() {
// Your operation which returns chunked output.
}
}.start();
return Response.ok(output).build();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.