### Question:
StaxCryptoCoverageChecker extends AbstractPhaseInterceptor<SoapMessage> { public final void setSignBody(boolean signBody) { this.signBody = signBody; } StaxCryptoCoverageChecker(); @Override void handleMessage(SoapMessage soapMessage); boolean isSignBody(); final void setSignBody(boolean signBody); boolean isSignTimestamp(); final void setSignTimestamp(boolean signTimestamp); boolean isEncryptBody(); final void setEncryptBody(boolean encryptBody); boolean isSignAddressingHeaders(); final void setSignAddressingHeaders(boolean signAddressingHeaders); boolean isSignUsernameToken(); void setSignUsernameToken(boolean signUsernameToken); boolean isEncryptUsernameToken(); final void setEncryptUsernameToken(boolean encryptUsernameToken); static final String SOAP_NS; static final String SOAP12_NS; static final String WSU_NS; static final String WSSE_NS; static final String WSA_NS; }### Answer:
@Test public void testEncryptedBody() throws Exception { Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); inProperties.setCallbackHandler(new TestPwdCallback()); Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader()); inProperties.setDecryptionCryptoProperties(cryptoProperties); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); service.getInInterceptors().add(inhandler); StaxCryptoCoverageChecker checker = new StaxCryptoCoverageChecker(); service.getInInterceptors().add(checker); Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); WSSSecurityProperties properties = new WSSSecurityProperties(); List<WSSConstants.Action> actions = new ArrayList<>(); actions.add(XMLSecurityConstants.ENCRYPTION); properties.setActions(actions); properties.setEncryptionUser("myalias"); properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128); Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader()); properties.setEncryptionCryptoProperties(outCryptoProperties); properties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties); client.getOutInterceptors().add(ohandler); try { echo.echo("test"); fail("Failure expected as SOAP Body isn't signed"); } catch (javax.xml.ws.soap.SOAPFaultException ex) { } checker.setSignBody(false); assertEquals("test", echo.echo("test")); }