简体   繁体   English

如何在ClientErrorException中向HTTP响应添加标头?

[英]How to add headers to HTTP response within ClientErrorException?

I have a custom ClientErrorException and I want to add some specific headers to the response when this exception is thrown. 我有一个自定义的ClientErrorException并且想在引发此异常时向响应中添加一些特定的标头。

For example, I can specify status of the response in the constructor: 例如,我可以在构造函数中指定响应的状态:

public ClientErrorException(String message, Response.Status status) {
...
}

But how to specify headers? 但是如何指定标题呢? What the proper way to do that? 正确的方法是什么?

You can use an ExceptionMapper for jax-rs to return a custom response when an exception is thrown. 您可以对jax-rs使用ExceptionMapper ,以在抛出异常时返回自定义响应。

There is a nice example in here 有一个很好的例子在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM