ReportSignatureInterceptor implements ResponseBodyAdvice<Object> { @Override public Object beforeBodyWrite(Object responseObject, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { if (properties.isReportSignatureEnabled()) { try { if (responseObject instanceof ValidationResponse && ((ValidationResponse) responseObject).getValidationReport() instanceof DetailedReport) { LOGGER.debug("Starting to create report signature"); ValidationResponse validationResponse = (ValidationResponse) responseObject; String validationReportJsonString = jacksonObjectMapper.writeValueAsString(validationResponse.getValidationReport()); byte[] reportSignatureBytes = signatureService.getSignature(validationReportJsonString.getBytes(), "validationReport.json", "application/json"); validationResponse.setValidationReportSignature(Base64.encodeBase64String(reportSignatureBytes)); LOGGER.debug("Finished creating report signature"); return validationResponse; } } catch (Exception e) { LOGGER.error("Error producing report signature", e); return responseObject; } } return responseObject; }  @Override boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType); @Override Object beforeBodyWrite(Object responseObject, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response); void setJacksonObjectMapper(ObjectMapper jacksonObjectMapper); void setSignatureService(SignatureService signatureService); void setProperties(ReportConfigurationProperties properties);  }
@Test public void test() throws IOException { ValidationResponse validationResponse = (ValidationResponse) reportSignatureInterceptor.beforeBodyWrite(getValidationResponseMock(), null, null, null, null,null); assertArrayEquals(getRawSignatureMock(), Base64.decodeBase64(validationResponse.getValidationReportSignature())); }