Java Code Examples for org.jivesoftware.smack.XMPPConnection#sendStanza()

The following examples show how to use org.jivesoftware.smack.XMPPConnection#sendStanza() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmemoService.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Send an empty OMEMO message to contactsDevice in order to forward the ratchet.
 *
 * @param managerGuard OMEMO manager
 * @param contactsDevice contacts OMEMO device
 *
 * @throws CorruptedOmemoKeyException if our or their OMEMO key is corrupted.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 * @throws NoSuchAlgorithmException if AES encryption fails
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws CryptoFailedException if encryption fails (should not happen though, but who knows...)
 * @throws CannotEstablishOmemoSessionException if we cannot establish a session with contactsDevice.
 * @throws IOException if an I/O error occurred.
 */
private void sendRatchetUpdate(OmemoManager.LoggedInOmemoManager managerGuard, OmemoDevice contactsDevice)
        throws CorruptedOmemoKeyException, InterruptedException, SmackException.NoResponseException,
        NoSuchAlgorithmException, SmackException.NotConnectedException, CryptoFailedException,
        CannotEstablishOmemoSessionException, IOException {

    OmemoManager manager = managerGuard.get();
    OmemoElement ratchetUpdate = createRatchetUpdateElement(managerGuard, contactsDevice);

    XMPPConnection connection = manager.getConnection();
    Message message = connection.getStanzaFactory().buildMessageStanza()
            .to(contactsDevice.getJid())
            .addExtension(ratchetUpdate)
            .build();
    connection.sendStanza(message);
}
 
Example 2
Source File: Socks5ByteStreamTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Target should respond with not-acceptable error if no listeners for incoming Socks5
 * bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
                    initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
    bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);

    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(
                    bytestreamInitiation.getStanzaId()));
    initiatorConnection.sendStanza(bytestreamInitiation);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
Example 3
Source File: InBandBytestreamTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Target should respond with not-acceptable error if no listeners for incoming In-Band
 * Bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());

    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(
                    open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
Example 4
Source File: InBandBytestreamRequest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Accepts the In-Band Bytestream open request and returns the session to
 * send/receive data.
 *
 * @return the session to send/receive data
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
@Override
public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException {
    XMPPConnection connection = this.manager.getConnection();

    // create In-Band Bytestream session and store it
    InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection,
                    this.byteStreamRequest, this.byteStreamRequest.getFrom());
    this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession);

    // acknowledge request
    IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
    connection.sendStanza(resultIQ);

    return ibbSession;
}
 
Example 5
Source File: AgentRoster.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new AgentRoster.
 *
 * @param connection an XMPP connection.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
AgentRoster(XMPPConnection connection, EntityBareJid workgroupJID) throws NotConnectedException, InterruptedException {
    this.connection = connection;
    this.workgroupJID = workgroupJID;
    // Listen for any roster packets.
    StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class);
    connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter);
    // Listen for any presence packets.
    connection.addAsyncStanzaListener(new PresencePacketListener(),
            new StanzaTypeFilter(Presence.class));

    // Send request for roster.
    AgentStatusRequest request = new AgentStatusRequest();
    request.setTo(workgroupJID);
    connection.sendStanza(request);
}
 
Example 6
Source File: RosterExchangeManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a roster group to userID. All the entries of the group will be sent to the
 * target user.
 *
 * @param rosterGroup the roster group to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();

    // Create a new message to send the roster
    MessageBuilder msg = connection.getStanzaFactory().buildMessageStanza().to(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    for (RosterEntry entry : rosterGroup.getEntries()) {
        rosterExchange.addRosterEntry(entry);
    }
    msg.addExtension(rosterExchange);

    // Send the message that contains the roster
    connection.sendStanza(msg.build());
}
 
Example 7
Source File: OmemoManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Send a ratchet update message. This can be used to advance the ratchet of a session in order to maintain forward
 * secrecy.
 *
 * @param recipient recipient
 *
 * @throws CorruptedOmemoKeyException           When the used identityKeys are corrupted
 * @throws CryptoFailedException                When something fails with the crypto
 * @throws CannotEstablishOmemoSessionException When we can't establish a session with the recipient
 * @throws SmackException.NotLoggedInException if the XMPP connection is not authenticated.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 * @throws NoSuchAlgorithmException if no such algorithm is available.
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws IOException if an I/O error occurred.
 */
public synchronized void sendRatchetUpdateMessage(OmemoDevice recipient)
        throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
        SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException,
        CryptoFailedException, CannotEstablishOmemoSessionException, IOException {
    XMPPConnection connection = connection();
    MessageBuilder message = connection.getStanzaFactory()
            .buildMessageStanza()
            .to(recipient.getJid());

    OmemoElement element = getOmemoService().createRatchetUpdateElement(new LoggedInOmemoManager(this), recipient);
    message.addExtension(element);

    // Set MAM Storage hint
    StoreHint.set(message);
    connection.sendStanza(message.build());
}
 
Example 8
Source File: RosterExchangeManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a roster entry to userID.
 *
 * @param rosterEntry the roster entry to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(RosterEntry rosterEntry, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();

    // Create a new message to send the roster
    MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    rosterExchange.addRosterEntry(rosterEntry);
    messageBuilder.addExtension(rosterExchange);

    // Send the message that contains the roster
    connection.sendStanza(messageBuilder.build());
}
 
Example 9
Source File: RosterExchangeManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a roster to userID. All the entries of the roster will be sent to the
 * target user.
 *
 * @param roster the roster to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(Roster roster, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();

    // Create a new message to send the roster
    MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange(roster);
    messageBuilder.addExtension(rosterExchange);

    // Send the message that contains the roster
    connection.sendStanza(messageBuilder.build());
}
 
Example 10
Source File: MessageEventManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the notification that the message was delivered to the sender of the original message.
 *
 * @param to the recipient of the notification.
 * @param packetID the id of the message to send.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendDeliveredNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException {
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setDelivered(true);
    messageEvent.setStanzaId(packetID);

    XMPPConnection connection = connection();
    Message msg = connection.getStanzaFactory().buildMessageStanza()
            .to(to)
            .addExtension(messageEvent)
            .build();
    // Send the packet
    connection.sendStanza(msg);
}
 
Example 11
Source File: MessageEventManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the notification that the receiver of the message is composing a reply.
 *
 * @param to the recipient of the notification.
 * @param packetID the id of the message to send.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendComposingNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException {
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setComposing(true);
    messageEvent.setStanzaId(packetID);

    XMPPConnection connection = connection();
    Message msg = connection.getStanzaFactory().buildMessageStanza()
            .to(to)
            .addExtension(messageEvent)
            .build();
    // Send the packet
    connection.sendStanza(msg);
}
 
Example 12
Source File: OmemoMamDecryptionTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SmackIntegrationTest
public void mamDecryptionTest() throws XMPPException.XMPPErrorException, SmackException.NotLoggedInException,
        SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException,
        CryptoFailedException, UndecidedOmemoIdentityException, IOException {
    // Make sure, Bobs server stores messages in the archive
    MamManager bobsMamManager = MamManager.getInstanceFor(bob.getConnection());
    bobsMamManager.enableMamForAllMessages();
    bobsMamManager.setDefaultBehavior(MamPrefsIQ.DefaultBehavior.always);

    // Prevent bob from automatically decrypting MAM messages.
    bob.stopStanzaAndPEPListeners();

    String body = "This message will be stored in MAM!";
    OmemoMessage.Sent encrypted = alice.encrypt(bob.getOwnJid(), body);

    XMPPConnection alicesConnection = alice.getConnection();
    MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(encrypted.buildMessage(messageBuilder, bob.getOwnJid()));

    MamManager.MamQuery query = bobsMamManager.queryArchive(MamManager.MamQueryArgs.builder().limitResultsToJid(alice.getOwnJid()).build());
    assertEquals(1, query.getMessageCount());

    List<MessageOrOmemoMessage> decryptedMamQuery = bob.decryptMamQueryResult(query);

    assertEquals(1, decryptedMamQuery.size());
    assertEquals(body, decryptedMamQuery.get(decryptedMamQuery.size() - 1).getOmemoMessage().getBody());
}
 
Example 13
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Pre-approve user presence subscription.
 *
 * @param user the user. (e.g. [email protected])
 * @throws NotLoggedInException if not logged in.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws FeatureNotSupportedException if pre-approving is not supported.
 * @since 4.2
 */
public void preApprove(BareJid user) throws NotLoggedInException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
    final XMPPConnection connection = connection();
    if (!isSubscriptionPreApprovalSupported()) {
        throw new FeatureNotSupportedException("Pre-approving");
    }

    Presence presencePacket = connection.getStanzaFactory().buildPresenceStanza()
        .ofType(Presence.Type.subscribed)
        .to(user)
        .build();
    connection.sendStanza(presencePacket);
}
 
Example 14
Source File: Roster.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();

    // Create a presence subscription packet and send.
    Presence presencePacket = connection.getStanzaFactory().buildPresenceStanza()
            .ofType(Presence.Type.subscribe)
            .to(jid)
            .build();
    connection.sendStanza(presencePacket);
}
 
Example 15
Source File: IoTProvisioningManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void unfriend(Jid friend) throws NotConnectedException, InterruptedException {
    if (isMyFriend(friend)) {
        XMPPConnection connection = connection();
        Presence presence = connection.getStanzaFactory().buildPresenceStanza()
                .ofType(Presence.Type.unsubscribed)
                .to(friend)
                .build();
        connection.sendStanza(presence);
    }
}
 
Example 16
Source File: MultipleRecipientManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the specified stanza to the collection of specified recipients using the specified
 * connection. If the server has support for XEP-33 then only one stanza is going to be sent to
 * the server with the multiple recipient instructions. However, if XEP-33 is not supported by
 * the server then the client is going to send the stanza to each recipient.
 *
 * @param connection the connection to use to send the packet.
 * @param packet the stanza to send to the list of recipients.
 * @param to the collection of JIDs to include in the TO list or <code>null</code> if no TO list exists.
 * @param cc the collection of JIDs to include in the CC list or <code>null</code> if no CC list exists.
 * @param bcc the collection of JIDs to include in the BCC list or <code>null</code> if no BCC list
 *        exists.
 * @param replyTo address to which all replies are requested to be sent or <code>null</code>
 *        indicating that they can reply to any address.
 * @param replyRoom JID of a MUC room to which responses should be sent or <code>null</code>
 *        indicating that they can reply to any address.
 * @param noReply true means that receivers should not reply to the message.
 * @throws XMPPErrorException if server does not support XEP-33: Extended Stanza Addressing and
 *         some XEP-33 specific features were requested.
 * @throws NoResponseException if there was no response from the server.
 * @throws FeatureNotSupportedException if special XEP-33 features where requested, but the
 *         server does not support them.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc,
        Jid replyTo, Jid replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException {
    // Check if *only* 'to' is set and contains just *one* entry, in this case extended stanzas addressing is not
    // required at all and we can send it just as normal stanza without needing to add the extension element
    if (to != null && to.size() == 1 && (cc == null || cc.isEmpty()) && (bcc == null || bcc.isEmpty()) && !noReply
                    && StringUtils.isNullOrEmpty(replyTo) && StringUtils.isNullOrEmpty(replyRoom)) {
        Jid toJid = to.iterator().next();
        packet.setTo(toJid);
        connection.sendStanza(packet);
        return;
    }
    DomainBareJid serviceAddress = getMultipleRecipientServiceAddress(connection);
    if (serviceAddress != null) {
        // Send packet to target users using multiple recipient service provided by the server
        sendThroughService(connection, packet, to, cc, bcc, replyTo, replyRoom, noReply,
                serviceAddress);
    }
    else {
        // Server does not support XEP-33 so try to send the packet to each recipient
        if (noReply || replyTo != null ||
                replyRoom != null) {
            // Some specified XEP-33 features were requested so throw an exception alerting
            // the user that this features are not available
            throw new FeatureNotSupportedException("Extended Stanza Addressing");
        }
        // Send the packet to each individual recipient
        sendToIndividualRecipients(connection, packet, to, cc, bcc);
    }
}
 
Example 17
Source File: OfferConfirmation.java    From Smack with Apache License 2.0 4 votes vote down vote up
public void notifyService(XMPPConnection con, Jid workgroup, String createdRoomName) throws NotConnectedException, InterruptedException {
    NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName);
    con.sendStanza(packet);
}
 
Example 18
Source File: SessionRenegotiationIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("SynchronizeOnNonFinalField")
@SmackIntegrationTest
public void sessionRenegotiationTest() throws Exception {

    boolean prevRepairProperty = OmemoConfiguration.getRepairBrokenSessionsWithPreKeyMessages();
    OmemoConfiguration.setRepairBrokenSessionsWithPrekeyMessages(true);
    boolean prevCompleteSessionProperty = OmemoConfiguration.getCompleteSessionWithEmptyMessage();
    OmemoConfiguration.setCompleteSessionWithEmptyMessage(false);

    // send PreKeyMessage -> Success
    final String body1 = "P = NP is true for all N,P from the set of complex numbers, where P is equal to 0";
    AbstractOmemoMessageListener.PreKeyMessageListener listener1 =
            new AbstractOmemoMessageListener.PreKeyMessageListener(body1);
    OmemoMessage.Sent e1 = alice.encrypt(bob.getOwnJid(), body1);
    bob.addOmemoMessageListener(listener1);

    XMPPConnection alicesConnection = alice.getConnection();
    MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(e1.buildMessage(messageBuilder, bob.getOwnJid()));
    listener1.getSyncPoint().waitForResult(10 * 1000);
    bob.removeOmemoMessageListener(listener1);

    // Remove the session on Bobs side.
    synchronized (bob) {
        bob.getOmemoService().getOmemoStoreBackend().removeRawSession(bob.getOwnDevice(), alice.getOwnDevice());
    }

    // Send normal message -> fail, bob repairs session with preKeyMessage
    final String body2 = "P = NP is also true for all N,P from the set of complex numbers, where N is equal to 1.";
    AbstractOmemoMessageListener.PreKeyKeyTransportListener listener2 =
            new AbstractOmemoMessageListener.PreKeyKeyTransportListener();
    OmemoMessage.Sent e2 = alice.encrypt(bob.getOwnJid(), body2);
    alice.addOmemoMessageListener(listener2);

    messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(e2.buildMessage(messageBuilder, bob.getOwnJid()));
    listener2.getSyncPoint().waitForResult(10 * 1000);
    alice.removeOmemoMessageListener(listener2);

    // Send normal message -> success
    final String body3 = "P = NP would be a disaster for the world of cryptography.";
    AbstractOmemoMessageListener.MessageListener listener3 = new AbstractOmemoMessageListener.MessageListener(body3);
    OmemoMessage.Sent e3 = alice.encrypt(bob.getOwnJid(), body3);
    bob.addOmemoMessageListener(listener3);

    messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(e3.buildMessage(messageBuilder, bob.getOwnJid()));
    listener3.getSyncPoint().waitForResult(10 * 1000);
    bob.removeOmemoMessageListener(listener3);

    OmemoConfiguration.setRepairBrokenSessionsWithPrekeyMessages(prevRepairProperty);
    OmemoConfiguration.setCompleteSessionWithEmptyMessage(prevCompleteSessionProperty);
}
 
Example 19
Source File: MessageEncryptionIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * This test checks whether the following actions are performed.
 *
 * Alice publishes bundle A1
 * Bob publishes bundle B1
 *
 * Alice sends message to Bob (preKeyMessage)
 * Bob publishes bundle B2
 * Alice still has A1
 *
 * Bob responds to Alice (normal message)
 * Alice still has A1
 * Bob still has B2
 * @throws Exception if an exception occurs.
 */
@SuppressWarnings("SynchronizeOnNonFinalField")
@SmackIntegrationTest
public void messageTest() throws Exception {
    OmemoBundleElement a1 = alice.getOmemoService().getOmemoStoreBackend().packOmemoBundle(alice.getOwnDevice());
    OmemoBundleElement b1 = bob.getOmemoService().getOmemoStoreBackend().packOmemoBundle(bob.getOwnDevice());

    // Alice sends message(s) to bob
    // PreKeyMessage A -> B
    final String body1 = "One is greater than zero (for small values of zero).";
    AbstractOmemoMessageListener.PreKeyMessageListener listener1 =
            new AbstractOmemoMessageListener.PreKeyMessageListener(body1);
    bob.addOmemoMessageListener(listener1);
    OmemoMessage.Sent e1 = alice.encrypt(bob.getOwnJid(), body1);

    XMPPConnection alicesConnection = alice.getConnection();
    MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
    alicesConnection.sendStanza(e1.buildMessage(messageBuilder, bob.getOwnJid()));
    listener1.getSyncPoint().waitForResult(10 * 1000);
    bob.removeOmemoMessageListener(listener1);

    OmemoBundleElement a1_ = alice.getOmemoService().getOmemoStoreBackend().packOmemoBundle(alice.getOwnDevice());
    OmemoBundleElement b2;

    synchronized (bob) { // Circumvent race condition where bundle gets replenished after getting stored in b2
        b2 = bob.getOmemoService().getOmemoStoreBackend().packOmemoBundle(bob.getOwnDevice());
    }

    assertEquals(a1, a1_, "Alice sent bob a preKeyMessage, so her bundle MUST still be the same.");
    assertNotEquals(b1, b2, "Bob just received a preKeyMessage from alice, so his bundle must have changed.");

    // Message B -> A
    final String body3 = "The german words for 'leek' and 'wimp' are the same.";
    AbstractOmemoMessageListener.MessageListener listener3 =
            new AbstractOmemoMessageListener.MessageListener(body3);
    alice.addOmemoMessageListener(listener3);
    OmemoMessage.Sent e3 = bob.encrypt(alice.getOwnJid(), body3);
    XMPPConnection bobsConnection = bob.getConnection();
    messageBuilder = bobsConnection.getStanzaFactory().buildMessageStanza();
    bobsConnection.sendStanza(e3.buildMessage(messageBuilder, alice.getOwnJid()));
    listener3.getSyncPoint().waitForResult(10 * 1000);
    alice.removeOmemoMessageListener(listener3);

    OmemoBundleElement a1__ = alice.getOmemoService().getOmemoStoreBackend().packOmemoBundle(alice.getOwnDevice());
    OmemoBundleElement b2_ = bob.getOmemoService().getOmemoStoreBackend().packOmemoBundle(bob.getOwnDevice());

    assertEquals(a1_, a1__, "Since alice initiated the session with bob, at no time he sent a preKeyMessage, " +
            "so her bundle MUST still be the same.");
    assertEquals(b2, b2_, "Bob changed his bundle earlier, but at this point his bundle must be equal to " +
            "after the first change.");
}
 
Example 20
Source File: GeoLocationManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
public void sendGeoLocationToJid(GeoLocation geoLocation, Jid jid) throws InterruptedException,
                NotConnectedException {

    final XMPPConnection connection = connection();

    Message geoLocationMessage = connection.getStanzaFactory().buildMessageStanza()
            .to(jid)
            .addExtension(geoLocation)
            .build();

    connection.sendStanza(geoLocationMessage);

}