本文介绍了如何在Apache CXF - Java中抛出403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于拦截器的以下代码。当检查返回true时,我想抛出一个403错误:

I am using the following code based on having an interceptor. When check returns true I want to throw a 403 error:

    @Override
    public void handleMessage(Message arg0) throws Fault {


        HttpServletRequest request = context.getHttpServletRequest();
        if(check(request)){
        // currently not working
                throw "Fault";
        }

我想抛出一个403错误。我从这种情况怎么做呢?

I want to throw a 403 error. How do I go about doing that from this situation?

我对抛出错误有什么困惑。

I am a little confused about how "throws fault" works.

任何帮助都将被欣赏

推荐答案

CXF将默认状态代码到500的错误,但您可以使用。例如

CXF will default the status code to 500 for a Fault, but you can set it with Fault.setStatusCode. For example

Fault fault = new Fault(new Exception("Exception message"));
fault.setStatusCode(403);
throw fault;

这篇关于如何在Apache CXF - Java中抛出403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 16:54