SOAPHeaderHandler implements SOAPHandler<SOAPMessageContext> { @Override public boolean handleMessage(SOAPMessageContext messageContext) { LOG.debug("Entering SOAPHeaderHandler.handleMessage"); Boolean isOutboundMessage = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); try { SOAPMessage oMessage = messageContext.getMessage(); SOAPHeader oHeader = oMessage.getSOAPHeader(); if (isOutboundMessage && !messageContext.containsKey(MESSAGE_ID_CONTEXT)) { adjustMessageId(messageContext, oHeader); } else { LOG.debug("Will not adjust messageID on inbound request"); } if (isOutboundMessage) { addMustUnderstandAttribute(oHeader); } } catch (SOAPException e) { LOG.error("Unable to handle message: {}", e.getLocalizedMessage()); LOG.trace("Unable to handle message: {}", e.getLocalizedMessage(), e); } return true; }  @Override Set<QName> getHeaders(); @Override boolean handleMessage(SOAPMessageContext messageContext); @Override boolean handleFault(SOAPMessageContext messageContext); @Override void close(MessageContext context);  }
@Test public void testHandleMessage_HeaderHasMessageId() throws SOAPException { SOAPHeaderHandler headerHandler = new SOAPHeaderHandler(); when(messageContext.get(MESSAGE_ID_CONTEXT)).thenReturn(MESSAGE_ID_VALUE); when(soapHeader.hasChildNodes()).thenReturn(true); SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement element = soapFactory.createElement(MESSAGE_ID, "blah", WSA_NS); Iterator<SOAPElement> iterator = mock(Iterator.class); when(soapHeader.getChildElements(any(QName.class))).thenReturn(iterator); when(iterator.hasNext()).thenReturn(true); when(iterator.next()).thenReturn(element); assertTrue(headerHandler.handleMessage(messageContext)); assertEquals(element.getTextContent(), MESSAGE_ID_VALUE); }