DeliverErrors extends AbstractBaseHandler { @Override protected InvocationResponse doProcessing(final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { final Collection<IErrorMessageEntity> errorSignals = procCtx.getReceivedErrors(); if (Utils.isNullOrEmpty(errorSignals)) return InvocationResponse.CONTINUE; StorageManager updateManager = HolodeckB2BCore.getStorageManager(); for(final IErrorMessageEntity errorSignal : errorSignals) { log.trace("Prepare Error Signal [" + errorSignal.getMessageId() + "] for delivery"); if(updateManager.setProcessingState(errorSignal, ProcessingState.READY_FOR_DELIVERY, ProcessingState.OUT_FOR_DELIVERY)) { log.debug("Start delivery of Error Signal [" + errorSignal.getMessageId() + "]"); boolean deliveredForAll = true; for(final IMessageUnitEntity msgInError : procCtx.getRefdMsgUnitByError(errorSignal)) deliveredForAll &= deliverError(errorSignal, msgInError, log); log.debug("Reported Error Signal for all referenced message units"); if (deliveredForAll) updateManager.setProcessingState(errorSignal, ProcessingState.DONE); else updateManager.setProcessingState(errorSignal, ProcessingState.WARNING, "Error could not be delivered for [all] referenced message units"); } else log.info("Error signal [" + errorSignal.getMessageId() + "] is already processed for delivery"); } log.debug("Processed all Error signals in message"); return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { PMode pmode = TestUtils.create1WaySendPushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); UserMessageFlow umFlow = new UserMessageFlow(); ErrorHandlingConfig errorHandlingConfig = new ErrorHandlingConfig(); errorHandlingConfig.setNotifyErrorToBusinessApplication(true); DeliveryConfiguration deliverySpecification = new DeliveryConfiguration(); deliverySpecification.setFactory(NullDeliveryMethod.class.getName()); deliverySpecification.setId("delivery_spec_id"); errorHandlingConfig.setErrorDelivery(deliverySpecification); umFlow.setErrorHandlingConfiguration(errorHandlingConfig); leg.setUserMessageFlow(umFlow); 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); mc.setServerSide(true); EbmsError ebmsError = new EbmsError(); ebmsError.setSeverity(IEbmsError.Severity.failure); ebmsError.setErrorCode("some_error_code"); ebmsError.setRefToMessageInError(userMessage.getMessageId()); ebmsError.setMessage("some error message"); ErrorMessage errorMessage = new ErrorMessage(ebmsError); errorMessage.setMessageId(T_MSG_ID); errorMessage.setPModeId(pmode.getId()); errorMessage.setRefToMessageId(userMessage.getMessageId()); StorageManager storageManager = HolodeckB2BCore.getStorageManager(); IMessageUnitEntity umEntity = storageManager.storeOutGoingMessageUnit(userMessage); IErrorMessageEntity errorMessageEntity = storageManager.storeIncomingMessageUnit(errorMessage); storageManager.setProcessingState(errorMessageEntity, ProcessingState.READY_FOR_DELIVERY); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.addReceivedError(errorMessageEntity); procCtx.addRefdMsgUnitByError(errorMessageEntity, Collections.singletonList(umEntity)); try { assertEquals(Handler.InvocationResponse.CONTINUE, new DeliverErrors().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } assertTrue(((NullDeliverer) HolodeckB2BCore.getMessageDeliverer(deliverySpecification)).wasDelivered(T_MSG_ID)); assertEquals(ProcessingState.DONE, errorMessageEntity.getCurrentProcessingState().getState()); }