MAMStanzaHandlerInterceptor implements StanzaHandlerInterceptor { @Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker, StanzaHandlerInterceptorChain interceptorChain) throws ProtocolException { StanzaBroker stanzaBrokerToUse; if (isCandidateForArchiving(stanza)) { stanzaBrokerToUse = stanzaBrokerProviders.stream() .filter(mamStanzaBrokerProvider -> mamStanzaBrokerProvider.supports(stanza, serverRuntimeContext)) .map(mamStanzaBrokerProvider -> mamStanzaBrokerProvider.proxy(stanzaBroker, serverRuntimeContext, sessionContext, isOutboundStanza, isArchivingForced(stanza))) .findFirst().orElse(stanzaBroker); } else { stanzaBrokerToUse = stanzaBroker; } interceptorChain.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBrokerToUse); } MAMStanzaHandlerInterceptor();   MAMStanzaHandlerInterceptor(List<MAMStanzaBrokerProvider> stanzaBrokerProviders); @Override void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
            SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker,
            StanzaHandlerInterceptorChain interceptorChain);  }
@Test public void stanzaWithHintNoStoreShouldNotBeStored() throws ProtocolException { Stanza stanza = StanzaBuilder.createMessageStanza(ALICE, BOB, "en", null) .startInnerElement("no-store", NamespaceURIs.XEP0334_MESSAGE_PROCESSING_HINTS).endInnerElement() .build(); tested.intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker, interceptorChain); verify(interceptorChain).intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker); }
@Test public void stanzaWithHintNoPermanentStoreShouldNotBeStored() throws ProtocolException { Stanza stanza = StanzaBuilder.createMessageStanza(ALICE, BOB, "en", null) .startInnerElement("no-permanent-store", NamespaceURIs.XEP0334_MESSAGE_PROCESSING_HINTS) .endInnerElement().build(); tested.intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker, interceptorChain); verify(interceptorChain).intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker); }
@Test public void stanzaWithHintStoreShouldBeStored() throws ProtocolException { Stanza stanza = StanzaBuilder.createMessageStanza(ALICE, BOB, "en", null) .startInnerElement("store", NamespaceURIs.XEP0334_MESSAGE_PROCESSING_HINTS).endInnerElement().build(); tested.intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker, interceptorChain); verify(interceptorChain).intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, archivingStanzaBroker); assertTrue(mamStanzaBrokerProvider.archivingForced); }
@Test public void stanzaWithoutHintShouldBeStored() throws ProtocolException { Stanza stanza = StanzaBuilder.createMessageStanza(ALICE, BOB, "en", null).build(); tested.intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, nonArchivingStanzaBroker, interceptorChain); verify(interceptorChain).intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, archivingStanzaBroker); assertFalse(mamStanzaBrokerProvider.archivingForced); }