DeliverReceipts extends AbstractBaseHandler { @Override protected InvocationResponse doProcessing(final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { final Collection<IReceiptEntity> rcptSignals = procCtx.getReceivedReceipts(); if (Utils.isNullOrEmpty(rcptSignals)) return InvocationResponse.CONTINUE; final StorageManager updateManager = HolodeckB2BCore.getStorageManager(); for(final IReceiptEntity receipt : rcptSignals) { log.trace("Prepare message [" + receipt.getMessageId() + "] for delivery"); if(updateManager.setProcessingState(receipt, ProcessingState.READY_FOR_DELIVERY, ProcessingState.OUT_FOR_DELIVERY)) { try { deliverReceipt(receipt, log); updateManager.setProcessingState(receipt, ProcessingState.DONE); } catch (final MessageDeliveryException ex) { log.warn("Could not deliver Receipt Signal (msgId=" + receipt.getMessageId() + "]) to application! Error details: " + ex.getMessage()); updateManager.setProcessingState(receipt, ProcessingState.DELIVERY_FAILED); HolodeckB2BCoreInterface.getEventProcessor() .raiseEvent(new MessageDeliveryFailure(receipt, ex)); } } else { log.warn("Receipt signal [" + receipt.getMessageId() + "] is already processed for delivery"); } } log.debug("Processed all Receipt signals in message"); return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { PMode pmode = TestUtils.create1WaySendPushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); DeliveryConfiguration deliverySpecification = new DeliveryConfiguration(); deliverySpecification.setFactory(NullDeliveryMethod.class.getName()); deliverySpecification.setId("delivery_spec_id"); leg.setDefaultDelivery(deliverySpecification); ReceiptConfiguration rcptCfg = new ReceiptConfiguration(); rcptCfg.setNotifyReceiptToBusinessApplication(true); leg.setReceiptConfiguration(rcptCfg); HolodeckB2BCore.getPModeSet().add(pmode); UserMessage userMessage = new UserMessage(); userMessage.setMessageId(MessageIdUtils.createMessageId()); userMessage.setPModeId(pmode.getId()); MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.IN_FLOW); Receipt receipt = new Receipt(); OMElement receiptChildElement = OMAbstractFactory.getOMFactory().createOMElement(RECEIPT_CHILD_ELEMENT_NAME); ArrayList<OMElement> content = new ArrayList<>(); content.add(receiptChildElement); receipt.setContent(content); receipt.setMessageId(MessageIdUtils.createMessageId()); receipt.setPModeId(pmode.getId()); receipt.setRefToMessageId(userMessage.getMessageId()); StorageManager storageManager = HolodeckB2BCore.getStorageManager(); IMessageUnitEntity umEntity = storageManager.storeOutGoingMessageUnit(userMessage); IReceiptEntity rcptMessageEntity = storageManager.storeIncomingMessageUnit(receipt); storageManager.setProcessingState(rcptMessageEntity, ProcessingState.READY_FOR_DELIVERY); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.addReceivedReceipt(rcptMessageEntity); try { assertEquals(Handler.InvocationResponse.CONTINUE, new DeliverReceipts().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } assertTrue(((NullDeliverer) HolodeckB2BCore.getMessageDeliverer(deliverySpecification)) .wasDelivered(receipt.getMessageId())); assertEquals(ProcessingState.DONE, rcptMessageEntity.getCurrentProcessingState().getState()); }