mardi 24 mai 2016

how to return different http error code in soap response in java

I have a SOAP Web Service and while trying to validate the request (not the schema validation of the soap request) if any problem occurs i want to throw an HTTP 400 and 404 error responses alternatively.

but in the current scenario if a valid request is made and the internal logic of the code throws the exception(with @WebFault annotation) the response code returned is 200 OK.

but instead of this i want to throw my own error codes.

is it possible to return error codes in this way with internally thrown messages ?

if yes, please explain/mention ?

public MyResponse getMyResponse(
            MyRequest request) throws ServiceException {


        try {
            validate(request);
        }catch(Exception ex){
            log.error(ex.getMessage(), ex);
            throw new ServiceException(ex.getMessage());    // currently error response comes with HTTP response 200
        }                                                   // instead i want to return 400 or 4xx.

        MyResponse rep = calculate(request);
        return rep;
    }




Aucun commentaire:

Enregistrer un commentaire