PackageReceiptSignal extends AbstractBaseHandler { @Override protected InvocationResponse doProcessing(final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { Collection<IReceiptEntity> receipts = procCtx.getSendingReceipts(); if (Utils.isNullOrEmpty(receipts)) return InvocationResponse.CONTINUE; log.trace("Adding receipt signal(s) to the message"); final SOAPHeaderBlock messaging = Messaging.getElement(procCtx.getParentContext().getEnvelope()); for(final IReceiptEntity r : receipts) { log.trace("Make sure that all meta-data on the Receipt is loaded"); if (!r.isLoadedCompletely()) { log.trace("Not all meta-data is available, load now"); HolodeckB2BCore.getQueryManager().ensureCompletelyLoaded(r); } log.trace("Add eb:SignalMessage element to the existing eb:Messaging header"); ReceiptElement.createElement(messaging, r); log.debug("eb:SignalMessage element for Receipt [msgId=" + r.getMessageId() + "] succesfully added to header"); } 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()); } StorageManager updateManager = HolodeckB2BCore.getStorageManager(); Receipt rcpt1 = new Receipt(); rcpt1.setMessageId(MessageIdUtils.createMessageId()); rcpt1.addElementToContent(OMAbstractFactory.getOMFactory().createOMElement(RECEIPT_CHILD_ELEMENT_NAME)); procCtx.addSendingReceipt(updateManager.storeOutGoingMessageUnit(rcpt1)); Receipt rcpt2 = new Receipt(); rcpt2.setMessageId(MessageIdUtils.createMessageId()); rcpt2.addElementToContent(OMAbstractFactory.getOMFactory().createOMElement(RECEIPT_CHILD_ELEMENT_NAME)); procCtx.addSendingReceipt(updateManager.storeOutGoingMessageUnit(rcpt2)); try { assertEquals(Handler.InvocationResponse.CONTINUE, new PackageReceiptSignal().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } Iterator<OMElement> signals = messaging.getChildElements(); assertTrue(signals.hasNext()); OMElement signalElem = signals.next(); assertEquals("SignalMessage", signalElem.getLocalName()); assertEquals(EbMSConstants.EBMS3_NS_URI, signalElem.getNamespaceURI()); assertNotNull(signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "Receipt"))); OMElement msgInfoElem = signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageInfo")); assertNotNull(msgInfoElem); assertEquals(rcpt1.getMessageId(), msgInfoElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageId")).getText()); assertTrue(signals.hasNext()); signalElem = signals.next(); assertEquals("SignalMessage", signalElem.getLocalName()); assertEquals(EbMSConstants.EBMS3_NS_URI, signalElem.getNamespaceURI()); assertNotNull(signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "Receipt"))); msgInfoElem = signalElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageInfo")); assertNotNull(msgInfoElem); assertEquals(rcpt2.getMessageId(), msgInfoElem.getFirstChildWithName(new QName(EbMSConstants.EBMS3_NS_URI, "MessageId")).getText()); }