Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to throw a 403 error in Apache CXF - Java

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";
        }

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.

Any help is appreciated

like image 668
Tai Avatar asked Jun 07 '26 11:06

Tai


1 Answers

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;
like image 151
Patrick Avatar answered Jun 10 '26 06:06

Patrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!