/** * Process IQ stanza. * @param data * @throws NotConnectedException * @throws InterruptedException * @throws NotLoggedInException */ public void processIQPacket(Data data) throws NotConnectedException, InterruptedException, NotLoggedInException { inputStream.dataPacketListener.processStanza(data); }
@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(); }
/** * If the data stanza contains invalid Base64 encoding an 'bad-request' error should be * returned. See XEP-0047 Section 2.2. * * @throws Exception should not happen */ @Test public void shouldReplyWithErrorIfDataIsInvalid() throws Exception { // verify reply to invalid data packet is an error protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() { @Override public void verify(IQ request, IQ response) { assertEquals(StanzaError.Condition.bad_request, request.getError().getCondition()); } }); // get IBB sessions data packet listener InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); InputStream inputStream = session.getInputStream(); StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class); // build data packets DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, "AA=BB"); Data data = new Data(dpe); // notify listener listener.processStanza(data); protocol.verifyAll(); }
@Test public void testInboundAdapterUsageWithHeaderMapper() throws Exception { 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(JidCreate.from("oleg")); JivePropertiesManager.addProperty(message, "foo", "foo"); JivePropertiesManager.addProperty(message, "bar", "bar"); stanzaListener.processStanza(message); org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0); assertEquals("foo", siMessage.getHeaders().get("foo")); assertEquals("oleg", siMessage.getHeaders().get("xmpp_to")); }