@Override public void handleMessage(SoapMessage soapMessage) throws Fault { String headerSecret = parseSecret(soapMessage); if (headerSecret == null || !headerSecret.equals(secret)) { logger.info("Unable to verify header secret " + headerSecret + ", expected " + secret); Fault fault = new Fault(new SecurityException("Unable to verify header")); fault.setStatusCode(401); // access denied throw fault; } }
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) public void handleMessage(Message message) throws Fault { handleMessageCalled = true; Exception ex = message.getContent(Exception.class); if (ex == null) { throw new RuntimeException("Exception is expected"); } Fault fault = (Fault) ex; final Throwable t = fault.getCause(); final int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String requestId = UUID.randomUUID().toString(); final ErrorMessage error = new ErrorMessage(ERROR_TEXT, requestId); logger.error("Caught unhandled exception! This may be a bug. " + "RequestID: " + requestId, t); HttpServletResponse response = (HttpServletResponse) message.getExchange().getInMessage().get(AbstractHTTPDestination.HTTP_RESPONSE); this.responseUtil.sendServletError(response, error, status); message.getInterceptorChain().abort(); }
private void runInterceptorAndValidate( String document, Map<String, String> prefixes, List<XPathExpression> xpaths, boolean pass) throws Exception { final Document doc = this.readDocument(document); final SoapMessage msg = this.getSoapMessageForDom(doc); final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths); final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor(); wss4jInInterceptor.handleMessage(msg); try { checker.handleMessage(msg); if (!pass) { fail("Passed interceptor erroneously."); } } catch (Fault e) { if (pass) { fail("Failed interceptor erroneously."); } assertTrue(e.getMessage().contains("element found matching XPath")); } }