@Override protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) { buf.append(" sessionID=\"") .append(sessionID) .append("\">"); for (Stanza packet : packets) { buf.append(packet.toXML(null)); } return buf; } }
private static void sendToIndividualRecipients(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc) throws NotConnectedException, InterruptedException { if (to != null) { for (Jid jid : to) { packet.setTo(jid); connection.sendStanza(new PacketCopy(packet.toXML(null))); } } if (cc != null) { for (Jid jid : cc) { packet.setTo(jid); connection.sendStanza(new PacketCopy(packet.toXML(null))); } } if (bcc != null) { for (Jid jid : bcc) { packet.setTo(jid); connection.sendStanza(new PacketCopy(packet.toXML(null))); } } }
@Override public XmlStringBuilder toXML(String enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); xml.rightAngleBracket(); xml.optElement(getDelayInformation()); xml.append(forwardedPacket.toXML(NAMESPACE)); xml.closeElement(this); return xml; }
@Test public void verifyForm() throws Exception { FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection); try { fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10); } catch (NoResponseException e) { // We do not expect an answer. This unit test only checks the request sent. } Stanza packet = connection.getSentPacket(); String xml = packet.toXML(null).toString(); assertTrue(xml.indexOf("var='stream-method' type='list-single'") != -1); } }
@Test public void multipleMessageBodiesParsingTest() throws Exception { String control = XMLBuilder.create("message") .namespace(StreamOpen.CLIENT_NAMESPACE) .a("from", "romeo@montague.lit/orchard") .a("to", "juliet@capulet.lit/balcony") .a("id", "zid615d9") .a("type", "chat") .a("xml:lang", "en") .e("body") // TODO: Remove the following xml:lang once Smack's serialization toXml() API is aware of a potential // scoping xml:lang value. The out message stanza already declares an xml:lang with the exact same // value, hence this statement is redundant. .a("xml:lang", "en") .t("This is a test of the emergency broadcast system, 1.") .up() .e("body") .a("xml:lang", "ru") .t("This is a test of the emergency broadcast system, 2.") .up() .e("body") .a("xml:lang", "sp") .t("This is a test of the emergency broadcast system, 3.") .asString(outputProperties); Stanza message = PacketParserUtils.parseStanza(control); XmlUnitUtils.assertSimilar(control, message.toXML(null)); }
@Override public void processPacket(Stanza packet) throws SmackException.NotConnectedException { JSONObject jsonObj = XML.toJSONObject(packet.toXML()); String json = jsonObj.toString(); //foo
@Override public void processStanza(Stanza stanza) { logger.trace("{}>>> {}", prefix, stanza.toXML().toString().replaceAll("\n", "")); } }, ForEveryStanza.INSTANCE);
@Override public void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException { logger.trace("<<<{} {}", prefix, stanza.toXML().toString().replaceAll("\n", "")); } }, ForEveryStanza.INSTANCE);
@Override public void processStanza(Stanza packet) { logger.trace(prefix + packet.toXML()); } }
/** * {@inheritDoc} */ @Override public void sendStanza(Stanza packet) { Objects.requireNonNull(packet, "packet"); try { connection.sendStanza(packet); } catch (NotConnectedException e) { logger.error("No connection - unable to send packet: " + packet.toXML(), e); } catch (InterruptedException e) { logger.error("Failed to send packet: " + packet.toXML().toString(), e); } }
logger.info("Processing packet in thread {} - {}", Thread.currentThread().getName(), Thread.currentThread().getId()); logger.info("Received: {}", packet.toXML(null)); final FcmPacketExtension fcmPacket = (FcmPacketExtension) packet.getExtension(Util.FCM_NAMESPACE); final String json = fcmPacket.getJson();
/** * Sends an ACK to FCM with back off strategy * * @param jsonRequest */ public void sendAck(String jsonRequest) { logger.info("Sending ack."); final Stanza packet = new FcmPacketExtension(jsonRequest).toPacket(); final BackOffStrategy backoff = new BackOffStrategy(); while (backoff.shouldRetry()) { try { xmppConn.sendStanza(packet); backoff.doNotRetry(); } catch (NotConnectedException | InterruptedException e) { logger.info("The packet could not be sent due to a connection problem. Backing off the packet: {}", packet.toXML(null)); backoff.errorOccured(); } } }
/** * Sends a downstream message to FCM with back off strategy */ private void sendDownstreamMessageInternal(String messageId, String jsonRequest) { final Stanza request = new FcmPacketExtension(jsonRequest).toPacket(); final BackOffStrategy backoff = new BackOffStrategy(); while (backoff.shouldRetry()) { try { xmppConn.sendStanza(request); backoff.doNotRetry(); } catch (NotConnectedException | InterruptedException e) { logger.info("The packet could not be sent due to a connection problem. Backing off the packet: {}", request.toXML(null)); try { backoff.errorOccured2(); } catch (Exception e2) { // all the attempts failed removeMessageFromSyncMessages(messageId); pendingMessages.put(messageId, Message.from(jsonRequest)); } } } }
xmppConn.addStanzaInterceptor(stanza -> logger.info("Sent: {}", stanza.toXML(null)), ForEveryStanza.INSTANCE);
System.out.println("Sending presence packet with ssrc: " + presencePacketWithSSRC.toXML()); connection.sendStanza(presencePacketWithSSRC);