DetectDuplicateUserMessages extends AbstractUserMessageHandler { @Override protected InvocationResponse doProcessing(final IUserMessageEntity um, final IMessageProcessingContext procCtx, final Logger log) throws PersistenceException { log.trace("Check if duplicate check must be executed"); boolean detectDups = procCtx.eliminateDuplicates(); if (!detectDups) { ILeg leg = null; try { leg = PModeUtils.getLeg(um); } catch (IllegalStateException pmodeNotAvailable) { log.error("P-Mode " + um.getPModeId() + " not found in current P-Mode set!" + "Unable to determine if receipt is needed for message [msgId=" + um.getMessageId() + "]"); } if (leg != null) { final IReceptionAwareness raConfig = leg.getReceptionAwareness(); detectDups = raConfig != null ? raConfig.useDuplicateDetection() : false; } } if (!detectDups) { log.debug("Duplicate detection not enabled, skipping check."); return InvocationResponse.CONTINUE; } else { final String msgId = um.getMessageId(); log.trace("Duplicate detection enabled. Check if this Usermessage [msgId=" + msgId + "] has already been delivered"); boolean isDuplicate = false; isDuplicate = HolodeckB2BCore.getQueryManager().isAlreadyProcessed(um); if (isDuplicate) { log.debug("UserMessage [msgId=" + msgId + "] has already been processed"); duplicateLog.info("UserMessage [msgId=" + msgId + "] is a duplicate of an already processed message"); log.trace("Update processing state to duplicate"); HolodeckB2BCore.getStorageManager().setProcessingState(um, ProcessingState.DUPLICATE); HolodeckB2BCore.getEventProcessor().raiseEvent(new DuplicateReceivedEvent(um)); } return InvocationResponse.CONTINUE; } }  @Override void init(HandlerDescription handlerdesc);  }
@Test public void testDoProcessing() throws Exception { PMode pmode = TestUtils.create1WayReceivePushPMode(); Leg leg = pmode.getLeg(Label.REQUEST); ReceptionAwarenessConfig rac = new ReceptionAwarenessConfig(); rac.setDuplicateDetection(true); leg.setReceptionAwareness(rac); core.getPModeSet().add(pmode); UserMessage userMessage = new UserMessage(); userMessage.setMessageId(UUID.randomUUID().toString()); userMessage.setPModeId(pmode.getId()); StorageManager updateManager = HolodeckB2BCore.getStorageManager(); IUserMessageEntity userMessageEntity = updateManager.storeIncomingMessageUnit(userMessage); MessageContext mc = new MessageContext(); mc.setFLOW(MessageContext.IN_FLOW); IMessageProcessingContext procCtx = MessageProcessingContext.getFromMessageContext(mc); procCtx.setUserMessage(userMessageEntity); updateManager.setProcessingState(userMessageEntity, ProcessingState.DELIVERED); try { Handler.InvocationResponse invokeResp = handler.invoke(mc); assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp); } catch (Exception e) { fail(e.getMessage()); } assertEquals(ProcessingState.DUPLICATE, HolodeckB2BCoreInterface.getQueryManager() .getMessageUnitsWithId(userMessage.getMessageId()) .iterator().next().getCurrentProcessingState().getState()); }