/** * Process IQ stanza. * @param data * @throws NotConnectedException * @throws InterruptedException * @throws NotLoggedInException */ public void processIQPacket(Data data) throws NotConnectedException, InterruptedException, NotLoggedInException { inputStream.dataPacketListener.processStanza(data); }
@Test public void testInboundAdapterUsageWithHeaderMapper() throws NotConnectedException { XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class); ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class); Field xmppConnectionField = ReflectionUtils.findField(ChatMessageListeningEndpoint.class, "xmppConnection"); xmppConnectionField.setAccessible(true); ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection); StanzaListener stanzaListener = TestUtils.getPropertyValue(adapter, "stanzaListener", StanzaListener.class); Message message = new Message(); message.setBody("hello"); message.setTo("oleg"); JivePropertiesManager.addProperty(message, "foo", "foo"); JivePropertiesManager.addProperty(message, "bar", "bar"); stanzaListener.processPacket(message); org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0); assertEquals("foo", siMessage.getHeaders().get("foo")); assertEquals("oleg", siMessage.getHeaders().get("xmpp_to")); }
@Test public void testWithErrorChannel() throws NotConnectedException { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XMPPConnection connection = mock(XMPPConnection.class); bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(); DirectChannel outChannel = new DirectChannel(); outChannel.subscribe(new MessageHandler() { @Override public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException { throw new RuntimeException("ooops"); } }); PollableChannel errorChannel = new QueueChannel(); endpoint.setBeanFactory(bf); endpoint.setOutputChannel(outChannel); endpoint.setErrorChannel(errorChannel); endpoint.afterPropertiesSet(); StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener"); Message smackMessage = new Message("kermit@frog.com"); smackMessage.setBody("hello"); smackMessage.setThread("1234"); listener.processPacket(smackMessage); ErrorMessage msg = (ErrorMessage) errorChannel.receive(); assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload()); }
@Override public void run() { try { listener.processStanza(packet); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception in async packet listener", e); } } });
@Override public void run() { for (StanzaListener listener : listenersToNotify) { try { listener.processStanza(packet); } catch (Exception e) { LOGGER.log(Level.WARNING, "Sending listener threw exception", e); continue; } } } });
@Override public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException { try { callback.processStanza(packet); } finally { removeSyncStanzaListener(this); } } };
@Override public void run() { // As listeners are able to remove themselves and because the timepoint where it is decided to invoke a // listener is a different timepoint where the listener is actually invoked (here), we have to check // again if the listener is still active. Iterator<StanzaListener> it = listenersToNotify.iterator(); synchronized (syncRecvListeners) { while (it.hasNext()) { StanzaListener stanzaListener = it.next(); if (!syncRecvListeners.containsKey(stanzaListener)) { // The listener was removed from syncRecvListener, also remove him from listenersToNotify. it.remove(); } } } for (StanzaListener listener : listenersToNotify) { try { listener.processStanza(packet); } catch (NotConnectedException e) { LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e); break; } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception in packet listener", e); } } } });
@Override public void run() { for (Stanza ackedStanza : ackedStanzas) { for (StanzaListener listener : stanzaAcknowledgedListeners) { try { listener.processStanza(ackedStanza); } catch (InterruptedException | NotConnectedException | NotLoggedInException e) { LOGGER.log(Level.FINER, "Received exception", e); } } String id = ackedStanza.getStanzaId(); if (StringUtils.isNullOrEmpty(id)) { continue; } StanzaListener listener = stanzaIdAcknowledgedListeners.remove(id); if (listener != null) { try { listener.processStanza(ackedStanza); } catch (InterruptedException | NotConnectedException | NotLoggedInException e) { LOGGER.log(Level.FINER, "Received exception", e); } } } } });
/** * Process interceptors. Interceptors may modify the stanza that is about to be sent. * Since the thread that requested to send the stanza will invoke all interceptors, it * is important that interceptors perform their work as soon as possible so that the * thread does not remain blocked for a long period. * * @param packet the stanza that is going to be sent to the server */ private void firePacketInterceptors(Stanza packet) { List<StanzaListener> interceptorsToInvoke = new LinkedList<>(); synchronized (interceptors) { for (InterceptorWrapper interceptorWrapper : interceptors.values()) { if (interceptorWrapper.filterMatches(packet)) { interceptorsToInvoke.add(interceptorWrapper.getInterceptor()); } } } for (StanzaListener interceptor : interceptorsToInvoke) { try { interceptor.processStanza(packet); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", e); } } }
listener.processStanza(data);
listener.processStanza(data);
DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data); Data data = new Data(dpe); listener.processStanza(data);
Message dataMessage = new Message(); dataMessage.addExtension(dpe); listener.processStanza(dataMessage);
Message dataMessage = new Message(); dataMessage.addExtension(dpe); listener.processStanza(dataMessage);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); listener.processStanza(data);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); listener.processStanza(data);
listener.processStanza(dataMessage);
listener.processStanza(data1); listener.processStanza(data2);
listener.processStanza(data);
/** * Valid data packets should be confirmed. * * @throws Exception should not happen */ @Test public void shouldConfirmReceivedDataPacket() throws Exception { // verify data packet confirmation is of type RESULT protocol.addResponse(null, Verification.requestTypeRESULT); InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); InputStream inputStream = session.getInputStream(); StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class); String base64Data = Base64.encode("Data"); DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data); Data data = new Data(dpe); listener.processStanza(data); protocol.verifyAll(); }