PackageErrorSignals extends AbstractBaseHandler { @Override protected InvocationResponse doProcessing(final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { final Collection<IErrorMessageEntity> errors = procCtx.getSendingErrors(); if (Utils.isNullOrEmpty(errors)) return InvocationResponse.CONTINUE; log.debug("Adding " + errors.size() + " error signal(s) to the message"); log.trace("Get the eb:Messaging header from the message"); final SOAPHeaderBlock messaging = Messaging.getElement(procCtx.getParentContext().getEnvelope()); boolean addSOAPFault = false; for(final IErrorMessageEntity e : errors) { log.trace("Make sure that all meta-data on the error is loaded"); if (!e.isLoadedCompletely()) { log.trace("Not all meta-data is available, load now"); HolodeckB2BCore.getQueryManager().ensureCompletelyLoaded(e); } log.trace("Add eb:SignalMessage element to the existing eb:Messaging header"); ErrorSignalElement.createElement(messaging, e); log.debug("eb:SignalMessage element for Error Signal [msgId=" + e.getMessageId() + "] succesfully added to header"); addSOAPFault |= e.shouldHaveSOAPFault(); } if(addSOAPFault) { log.debug("A SOAPFaults should be added to message, check if possible due to UserMessage with body payload"); if (procCtx.getSendingMessageUnits().parallelStream().allMatch(m -> m instanceof IErrorMessage)) { log.trace("SOAPFault can be added to message"); addSOAPFault(procCtx.getParentContext().getEnvelope()); log.trace("SOAPFault added to message"); } } return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12); SOAPHeaderBlock messaging = Messaging.createElement(env); MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.OUT_FLOW); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); try { mc.setEnvelope(env); } catch (AxisFault axisFault) { fail(axisFault.getMessage()); } EbmsError ebmsError = new EbmsError(); ebmsError.setSeverity(IEbmsError.Severity.failure); ebmsError.setErrorCode("some_error_code"); ErrorMessage errorMessage = new ErrorMessage(ebmsError); errorMessage.setMessageId(MessageIdUtils.createMessageId()); StorageManager updateManager = HolodeckB2BCore.getStorageManager(); IErrorMessageEntity errorMessageEntity = updateManager.storeOutGoingMessageUnit(errorMessage); procCtx.addSendingError(errorMessageEntity); try { assertEquals(Handler.InvocationResponse.CONTINUE, new PackageErrorSignals().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } assertTrue(messaging.getChildElements().hasNext()); OMElement signalElem = (OMElement) messaging.getChildElements().next(); assertEquals("SignalMessage", signalElem.getLocalName()); assertEquals(EbMSConstants.EBMS3_NS_URI, signalElem.getNamespaceURI()); assertNotNull(signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "Error"))); OMElement msgInfoElem = signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageInfo")); assertNotNull(msgInfoElem); assertEquals(errorMessage.getMessageId(), msgInfoElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageId")).getText()); }