[英]How to abort REST request inside a Jax-RS WriterInterceptor?
我在服務器上使用javax.ws.rs.ext.WriterInterceptor,如下所示,在將服務器生成的REST響應發送到客戶端之前,先對其進行修改。 這按預期工作,但是有沒有辦法從aroundWriteTo中止請求?
@Provider
@ServerInterceptor
public class MyInterceptor implements WriterInterceptor {
@Override
public void aroundWriteTo (WriterInterceptorContext context) {
final ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();
final OutputStream originalStream = context.getOutputStream();
context.setOutputStream(bufferStream);
context.proceed();
final String originalMsg = bufferStream.toString(Charset.defaultCharset().name());
try {
// not important for this example what modify does
final String modifiedMsg = modify(originalMsg);
} catch (Exception e) {
//How to abort request with HTTP status 500 at this point?
}
originalStream.write(modifiedMsg.getBytes(Charset.defaultCharset()));
context.setOutputStream(originalStream);
}
}
我正在使用JBoss EAS 6.4.7 GA,RestEasy 3.0.9。
該請求可以異常中止。 這是示例代碼: ContentMD5Writer.java
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.