![](/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.