![](/img/trans.png)
[英]jaxws and apache cxf and glassfish 5 error: java.lang.IllegalStateException: The lifecycle method [finalizeConfig] must not throw a checked exception
[英]how to throw a 403 error in Apache CXF - Java
我正在使用以下基于拦截器的代码。 当check返回true时,我想抛出403错误:
@Override
public void handleMessage(Message arg0) throws Fault {
HttpServletRequest request = context.getHttpServletRequest();
if(check(request)){
// currently not working
throw "Fault";
}
我想抛出403错误。 我如何从这种情况中做到这一点?
关于“抛出错误”是如何工作的我有点困惑。
任何帮助表示赞赏
对于故障,CXF会将状态代码默认为500,但您可以使用Fault.setStatusCode进行设置。 例如
Fault fault = new Fault(new Exception("Exception message"));
fault.setStatusCode(403);
throw fault;
你考虑过投掷:
throw new javax.ws.rs.ForbiddenException();
它返回http 403。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.