DeliverUserMessage extends AbstractUserMessageHandler { @Override protected InvocationResponse doProcessing(final IUserMessageEntity um, final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { StorageManager updateManager = HolodeckB2BCore.getStorageManager(); log.trace("Prepare message [" + um.getMessageId() + "] for delivery"); if(updateManager.setProcessingState(um, ProcessingState.READY_FOR_DELIVERY, ProcessingState.OUT_FOR_DELIVERY)) { log.trace("Start delivery of user message"); MessageDeliveryException failure = null; try { final IDeliverySpecification deliveryMethod = PModeUtils.getLeg(um).getDefaultDelivery(); final IMessageDeliverer deliverer = HolodeckB2BCore.getMessageDeliverer(deliveryMethod); try { log.debug("Delivering the message using delivery specification: " + deliveryMethod.getId()); deliverer.deliver(um); } catch (final MessageDeliveryException ex) { throw ex; } catch (final Throwable t) { log.warn(deliverer.getClass().getSimpleName() + " threw " + t.getClass().getSimpleName() + " instead of MessageDeliveryException!"); throw new MessageDeliveryException("Unhandled exception during message delivery", t); } log.info("Successfully delivered user message [msgId=" + um.getMessageId() +"]"); updateManager.setProcessingState(um, ProcessingState.DELIVERED); } catch (final MessageDeliveryException ex) { failure = ex; log.error("Could not deliver the user message [msgId=" + um.getMessageId() + "] using specified delivery method!" + "\n\tError details: " + ex.getMessage()); updateManager.setProcessingState(um, ProcessingState.DELIVERY_FAILED); if (ex.isPermanent()) { updateManager.setProcessingState(um, ProcessingState.FAILURE); procCtx.addGeneratedError( new OtherContentError("Message delivery impossible!", um.getMessageId())); } } HolodeckB2BCore.getEventProcessor().raiseEvent(failure == null ? new MessageDelivered(um) : new MessageDeliveryFailure(um, failure)); } else { log.warn("Usermessage [" + um.getMessageId() + "] is already being delivered!"); } return InvocationResponse.CONTINUE; }    }
@Test public void testDoProcessing() throws Exception { PMode pmode = TestUtils.create1WayReceivePushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); DeliveryConfiguration deliverySpecification = new DeliveryConfiguration(); deliverySpecification.setFactory(NullDeliveryMethod.class.getName()); deliverySpecification.setId("delivery_spec_id"); leg.setDefaultDelivery(deliverySpecification); HolodeckB2BCore.getPModeSet().add(pmode); MessageContext mc = new MessageContext(); mc.setServerSide(true); mc.setFLOW(MessageContext.IN_FLOW); UserMessage userMessage = new UserMessage(); userMessage.setMessageId(MessageIdUtils.createMessageId()); userMessage.setPModeId(pmode.getId()); StorageManager storageManager = HolodeckB2BCore.getStorageManager(); IUserMessageEntity umEntity = storageManager.storeIncomingMessageUnit(userMessage); storageManager.setProcessingState(umEntity, ProcessingState.READY_FOR_DELIVERY); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.setUserMessage(umEntity); try { assertEquals(Handler.InvocationResponse.CONTINUE, new DeliverUserMessage().invoke(mc)); } catch (Exception e) { fail(e.getMessage()); } assertTrue(((NullDeliverer) HolodeckB2BCore.getMessageDeliverer(deliverySpecification)) .wasDelivered(userMessage.getMessageId())); assertEquals(ProcessingState.DELIVERED, umEntity.getCurrentProcessingState().getState()); TestEventProcessor eventProc = (TestEventProcessor) HolodeckB2BCoreInterface.getEventProcessor(); assertTrue(eventProc.events.size() == 1); assertTrue(eventProc.events.get(0) instanceof IMessageDelivered); }