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);
}
}
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;
}
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());
}
}
}
}
}
}
}
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);
}
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;
}
Aggregations