ReportSignatureInterceptor extends AbstractSoapInterceptor { @Override public void handleMessage(SoapMessage message) { if (properties.isReportSignatureEnabled()) { SOAPMessage soapMessage = message.getContent(SOAPMessage.class); try { if (soapMessage != null) { SOAPBody responseBody = soapMessage.getSOAPPart().getEnvelope().getBody(); SOAPBody requestBody = message.getExchange().getInMessage().getContent(SOAPMessage.class).getSOAPPart().getEnvelope().getBody(); if (reportTypeIsDetailed(requestBody)) { LOGGER.debug("Starting to create report signature"); byte[] validationReportBytes = getValidationReportContent(responseBody); byte[] validationReportSignature = signatureService.getSignature(validationReportBytes, "validationReport.xml", "application/xml"); addValidationReportSignature(responseBody, validationReportSignature); LOGGER.debug("Finished creating report signature"); } } } catch (Exception e) { LOGGER.error("Error producing report signature", e); } } } ReportSignatureInterceptor(); @Override void handleMessage(SoapMessage message); void setSignatureService(SignatureService signatureService); void setProperties(ReportConfigurationProperties properties);  }
@Test public void whenDetailedReportTypeInRequest_thenReportSignatureIsAdded() throws Exception { mockSoapMessage("Detailed"); reportSignatureInterceptor.handleMessage(message); ByteArrayOutputStream stream = new ByteArrayOutputStream(); responseSoapMessage.writeTo(stream); assertTrue(new String(stream.toByteArray()).contains(Base64.encodeBase64String(getRawSignatureMock()))); }
@Test public void whenSimpleReportTypeInRequest_thenReportSignatureIsNotAdded() throws Exception { mockSoapMessage("Simple"); reportSignatureInterceptor.handleMessage(message); ByteArrayOutputStream stream = new ByteArrayOutputStream(); responseSoapMessage.writeTo(stream); assertFalse(new String(stream.toByteArray()).contains(Base64.encodeBase64String(getRawSignatureMock()))); }
@Test public void whenDiagnosticReportTypeInRequest_thenReportSignatureIsNotAdded() throws Exception { mockSoapMessage("Diagnostic"); reportSignatureInterceptor.handleMessage(message); ByteArrayOutputStream stream = new ByteArrayOutputStream(); responseSoapMessage.writeTo(stream); assertFalse(new String(stream.toByteArray()).contains(Base64.encodeBase64String(getRawSignatureMock()))); }