[英]How to abort REST request inside a Jax-RS WriterInterceptor?
I am using a javax.ws.rs.ext.WriterInterceptor on my server as shown below to modify the REST responses generated by the server before they are sent out to the client. 我在服务器上使用javax.ws.rs.ext.WriterInterceptor,如下所示,在将服务器生成的REST响应发送到客户端之前,先对其进行修改。 This works as intended but is there a way to abort the request from within aroundWriteTo?
这按预期工作,但是有没有办法从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);
}
}
I'm using JBoss EAS 6.4.7 GA, RestEasy 3.0.9. 我正在使用JBoss EAS 6.4.7 GA,RestEasy 3.0.9。
The request can be aborted with an exception. 该请求可以异常中止。 Here is the example code : ContentMD5Writer.java
这是示例代码: ContentMD5Writer.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.