@Test public void test_stanzabroker_substitution_chaining() throws ProtocolException { StanzaBroker secondStanzaBroker = mock(StanzaBroker.class); StanzaBroker thirdStanzaBroker = mock(StanzaBroker.class); InterceptorMock firstInterceptor = new InterceptorMock().replaceStanzaBroker(secondStanzaBroker); InterceptorMock secondInterceptor = new InterceptorMock().replaceStanzaBroker(thirdStanzaBroker); List<StanzaHandlerInterceptor> interceptors = new ArrayList<>(); interceptors.add(firstInterceptor); interceptors.add(secondInterceptor); new SimpleStanzaHandlerInterceptorChain(stanzaHandler, interceptors).intercept(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, firstStanzaBroker); assertEquals(firstStanzaBroker, firstInterceptor.receivedStanzaBroker); assertEquals(secondStanzaBroker, secondInterceptor.receivedStanzaBroker); verify(stanzaHandler).execute(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder, thirdStanzaBroker); }
@Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker) throws ProtocolException { StanzaHandlerInterceptor interceptor = interceptors.poll(); if (interceptor == null) { LOG.debug("No more interceptor to execute. Executing stanza handler {}.", stanzaHandler); stanzaHandler.execute(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker); return; } LOG.debug("Executing interceptor {}", interceptor); interceptor.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker, this); }
SimpleStanzaHandlerInterceptorChain implements StanzaHandlerInterceptorChain { @Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker) throws ProtocolException { StanzaHandlerInterceptor interceptor = interceptors.poll(); if (interceptor == null) { LOG.debug("No more interceptor to execute. Executing stanza handler {}.", stanzaHandler); stanzaHandler.execute(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker); return; } LOG.debug("Executing interceptor {}", interceptor); interceptor.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker, this); } }
SimpleStanzaHandlerInterceptorChain implements StanzaHandlerInterceptorChain { @Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker) throws ProtocolException { StanzaHandlerInterceptor interceptor = interceptors.poll(); if (interceptor == null) { LOG.debug("No more interceptor to execute. Executing stanza handler {}.", stanzaHandler); stanzaHandler.execute(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker); return; } LOG.debug("Executing interceptor {}", interceptor); interceptor.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker, this); } SimpleStanzaHandlerInterceptorChain(StanzaHandler stanzaHandler,
            List<StanzaHandlerInterceptor> interceptors); }
SimpleStanzaHandlerInterceptorChain implements StanzaHandlerInterceptorChain { @Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker) throws ProtocolException { StanzaHandlerInterceptor interceptor = interceptors.poll(); if (interceptor == null) { LOG.debug("No more interceptor to execute. Executing stanza handler {}.", stanzaHandler); stanzaHandler.execute(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker); return; } LOG.debug("Executing interceptor {}", interceptor); interceptor.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker, this); } SimpleStanzaHandlerInterceptorChain(StanzaHandler stanzaHandler,
            List<StanzaHandlerInterceptor> interceptors); @Override void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
            SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker); }
SimpleStanzaHandlerInterceptorChain implements StanzaHandlerInterceptorChain { @Override public void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker) throws ProtocolException { StanzaHandlerInterceptor interceptor = interceptors.poll(); if (interceptor == null) { LOG.debug("No more interceptor to execute. Executing stanza handler {}.", stanzaHandler); stanzaHandler.execute(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker); return; } LOG.debug("Executing interceptor {}", interceptor); interceptor.intercept(stanza, serverRuntimeContext, isOutboundStanza, sessionContext, sessionStateHolder, stanzaBroker, this); } SimpleStanzaHandlerInterceptorChain(StanzaHandler stanzaHandler,
            List<StanzaHandlerInterceptor> interceptors); @Override void intercept(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
            SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker);  }