Search in sources :

Example 51 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class OutgoingMessageListenerIntegrationTest method outgoingMessageListenerTest.

@SmackIntegrationTest
public void outgoingMessageListenerTest() throws Exception {
    final String body = StringUtils.randomString(16);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    final OutgoingChatMessageListener listener = new OutgoingChatMessageListener() {

        @Override
        public void newOutgoingMessage(EntityBareJid to, MessageBuilder messageBuilder, Chat chat) {
            Message message = messageBuilder.build();
            if (message.getBody().equals(body)) {
                syncPoint.signal();
            }
        }
    };
    EntityBareJid peer = conTwo.getUser().asEntityBareJid();
    try {
        chatManagerOne.addOutgoingListener(listener);
        Chat chat = chatManagerOne.chatWith(peer);
        chat.send(body);
        syncPoint.waitForResult(timeout);
    } finally {
        chatManagerOne.removeOutgoingListener(listener);
    }
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 52 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class ParserUtils method getEntityJidAttribute.

public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
    final String jidString = parser.getAttributeValue("", name);
    if (jidString == null) {
        return null;
    }
    Jid jid = JidCreate.from(jidString);
    if (!jid.hasLocalpart())
        return null;
    EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
    if (fullJid != null) {
        return fullJid;
    }
    EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
    return bareJid;
}
Also used : Jid(org.jxmpp.jid.Jid) EntityJid(org.jxmpp.jid.EntityJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 53 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class AgentRoster method addListener.

/**
 * Adds a listener to this roster. The listener will be fired anytime one or more
 * changes to the roster are pushed from the server.
 *
 * @param listener an agent roster listener.
 */
public void addListener(AgentRosterListener listener) {
    synchronized (listeners) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
            // Fire events for the existing entries and presences in the roster
            for (EntityBareJid jid : getAgents()) {
                // but possible)
                if (entries.contains(jid)) {
                    // Fire the agent added event
                    listener.agentAdded(jid);
                    Jid j;
                    try {
                        j = JidCreate.from(jid);
                    } catch (XmppStringprepException e) {
                        throw new IllegalStateException(e);
                    }
                    Map<Resourcepart, Presence> userPresences = presenceMap.get(j);
                    if (userPresences != null) {
                        Iterator<Presence> presences = userPresences.values().iterator();
                        while (presences.hasNext()) {
                            // Fire the presence changed event
                            listener.presenceChanged(presences.next());
                        }
                    }
                }
            }
        }
    }
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Presence(org.jivesoftware.smack.packet.Presence) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 54 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class DigestMd5SaslTest method runTest.

protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException {
    EntityBareJid authzid = null;
    if (useAuthzid) {
        authzid = JidCreate.entityBareFrom("shazbat@xmpp.org");
    }
    saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
    byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
    String responseString = new String(response, StandardCharsets.UTF_8);
    String[] responseParts = responseString.split(",");
    Map<String, String> responsePairs = new HashMap<String, String>();
    for (String part : responseParts) {
        String[] keyValue = part.split("=", 2);
        String key = keyValue[0];
        String value = keyValue[1].replace("\"", "");
        responsePairs.put(key, value);
    }
    if (useAuthzid) {
        assertMapValue("authzid", "shazbat@xmpp.org", responsePairs);
    } else {
        assertTrue(!responsePairs.containsKey("authzid"));
    }
    assertMapValue("username", "florian", responsePairs);
    assertMapValue("realm", "xmpp.org", responsePairs);
    assertMapValue("digest-uri", "xmpp/xmpp.org", responsePairs);
    assertMapValue("qop", "auth", responsePairs);
}
Also used : HashMap(java.util.HashMap) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 55 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatManager method getJoinedRooms.

/**
 * Returns a List of the rooms where the requested user has joined. The Iterator will contain Strings where each
 * String represents a room (e.g. room@muc.jabber.org).
 *
 * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
 * @return a List of the rooms where the requested user has joined.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<EntityBareJid> getJoinedRooms(EntityFullJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Send the disco packet to the user
    DiscoverItems result = serviceDiscoveryManager.discoverItems(user, DISCO_NODE);
    List<DiscoverItems.Item> items = result.getItems();
    List<EntityBareJid> answer = new ArrayList<>(items.size());
    // Collect the entityID for each returned item
    for (DiscoverItems.Item item : items) {
        EntityBareJid muc = item.getEntityID().asEntityBareJidIfPossible();
        if (muc == null) {
            LOGGER.warning("Not a bare JID: " + item.getEntityID());
            continue;
        }
        answer.add(muc);
    }
    return answer;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)56 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)30 XMPPException (org.jivesoftware.smack.XMPPException)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)21 SmackException (org.jivesoftware.smack.SmackException)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)15 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 Presence (org.jivesoftware.smack.packet.Presence)6 Jid (org.jxmpp.jid.Jid)6 Message (org.jivesoftware.smack.packet.Message)5 ArrayList (java.util.ArrayList)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)4 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)4 UserJid (com.xabber.android.data.entity.UserJid)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2