JBoss (Wildfly) max-post-size handle response in Java Spring SOAP Webservice

Viewed 391

I have a https-listener with max-post-size set in standalone.xml of JBoss (Wildfly):

<https-listener name="https" socket-binding="https" max-post-size="50000000" security-realm="ApplicationRealm" verify-client="REQUESTED" enable-http2="true" />

I have a JSON @RestController, where I can use a @ControllerAdvice with:

@ExceptionHandler(MaxUploadSizeExceededException.class)

It handles the event of uploading a too large file nicely.

However I also have a SOAP-XML @Endpoint:

@PayloadRoot(namespace = "http://service.upload.com/", localPart = "upload")
@ResponsePayload
public JAXBElement<UploadResponse> upload(@RequestPayload Upload upload) throws UploadException {
    return service.process(upload);
}

This reponds with an ugly HTML.

I would like to know how to "advice" the SOAP interface to handle exceptions of too large requests.

1 Answers

I think you could use a controller advice to handle the exceptions.

I work with the Spring Framework, and when dealing with soap exceptions treatment, i usually do something like this:

@ControllerAdvice
@RequiredArgsConstructor
public class ControllerAdvice extends ResponseEntityExceptionHandler {

    private final ObjectMapper objectMapper;

    @ExceptionHandler(SoapFaultClientException.class)
    public ResponseEntity<Object> handleSoapFaultClient(SoapFaultClientException ex) throws IOException {
        Erro erro = objectMapper.readValue(ex.getMessage(), Erro.class);
        return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(erro);
    }

    @ExceptionHandler(WebServiceIOException.class)
    public ResponseEntity<Object> handleWebServiceIOException(WebServiceIOException ex) throws IOException {
        Erro erro = objectMapper.readValue(String.format(MESSAGE_TEMPLATE, ex.getMessage()), Erro.class);
        return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(erro);
    }
    ...
}
Related