use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.
the class StreamManagementTest method testStreamManagement.
@SmackIntegrationTest
public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException {
final String body1 = "Hi, what's up? " + testRunId;
final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId;
final String body3 = "Hi, what's up? I've been just resumed" + testRunId;
final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter(MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser())));
try {
send(body1, conOne, conTwo);
assertMessageWithBodyReceived(body1, collector);
conOne.instantShutdown();
send(body2, conOne, conTwo);
// Reconnect with xep198
conOne.connect().login();
assertMessageWithBodyReceived(body2, collector);
send(body3, conOne, conTwo);
assertMessageWithBodyReceived(body3, collector);
} finally {
collector.cancel();
}
}
use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.
the class EntityCapsTest method testPreventDiscoInfo.
/**
* Test if entity caps actually prevent a disco info request and reply.
*
* @throws XMPPException
* @throws InterruptedException
* @throws NotConnectedException
* @throws NoResponseException
*
*/
@SmackIntegrationTest
public void testPreventDiscoInfo() throws XMPPException, NoResponseException, NotConnectedException, InterruptedException {
final String dummyFeature = getNewDummyFeature();
conOne.addPacketSendingListener(new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
discoInfoSend = true;
}
}, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
// add a bogus feature so that con1 ver won't match con0's
sdmTwo.addFeature(dummyFeature);
dropCapsCache();
// discover that
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery should cause a disco#info
assertTrue(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
discoInfoSend = false;
// discover that
info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery shouldn't cause a disco#info
assertFalse(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
}
use of org.jivesoftware.smack.filter.AndFilter in project camel by apache.
the class XmppConsumer method doStart.
@Override
protected void doStart() throws Exception {
try {
connection = endpoint.createConnection();
} catch (SmackException e) {
if (endpoint.isTestConnectionOnStartup()) {
throw new RuntimeException("Could not connect to XMPP server.", e);
} else {
LOG.warn(e.getMessage());
if (getExceptionHandler() != null) {
getExceptionHandler().handleException(e.getMessage(), e);
}
scheduleDelayedStart();
return;
}
}
chatManager = ChatManager.getInstanceFor(connection);
chatManager.addChatListener(this);
OrFilter pubsubPacketFilter = new OrFilter();
if (endpoint.isPubsub()) {
//xep-0060: pubsub#notification_type can be 'headline' or 'normal'
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
connection.addPacketListener(this, pubsubPacketFilter);
}
if (endpoint.getRoom() == null) {
privateChat = chatManager.getThreadChat(endpoint.getChatId());
if (privateChat != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
}
privateChat.addMessageListener(this);
} else {
privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
if (LOG.isDebugEnabled()) {
LOG.debug("Opening private chat to " + privateChat.getParticipant());
}
}
} else {
// add the presence packet listener to the connection so we only get packets that concerns us
// we must add the listener before creating the muc
final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
connection.addPacketListener(this, packetFilter);
muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
muc.addMessageListener(this);
DiscussionHistory history = new DiscussionHistory();
// we do not want any historical messages
history.setMaxChars(0);
muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
if (LOG.isInfoEnabled()) {
LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
}
}
this.startRobustConnectionMonitor();
super.doStart();
}
use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.
the class CarbonManager method addCarbonsListener.
private void addCarbonsListener(XMPPConnection connection) {
EntityFullJid localAddress = connection.getUser();
if (localAddress == null) {
// carbons securely. Abort here. The ConnectionListener above will eventually setup the carbons listener.
return;
}
// XEP-0280 ยง 11. Security Considerations "Any forwarded copies received by a Carbons-enabled client MUST be
// from that user's bare JID; any copies that do not meet this requirement MUST be ignored." Otherwise, if
// those copies do not get ignored, malicious users may be able to impersonate other users. That is why the
// 'from' matcher is important here.
connection.addSyncStanzaListener(carbonsListener, new AndFilter(CARBON_EXTENSION_FILTER, FromMatchesFilter.createBare(localAddress)));
}
use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.
the class MultiUserChat method changeSubject.
/**
* Changes the subject within the room. As a default, only users with a role of "moderator"
* are allowed to change the subject in a room. Although some rooms may be configured to
* allow a mere participant or even a visitor to change the subject.
*
* @param subject the new room's subject to set.
* @throws XMPPErrorException if someone without appropriate privileges attempts to change the
* room subject will throw an error with code 403 (i.e. Forbidden)
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeSubject(final String subject) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Message message = createMessage();
message.setSubject(subject);
// Wait for an error or confirmation message back from the server.
StanzaFilter responseFilter = new AndFilter(fromRoomGroupchatFilter, new StanzaFilter() {
@Override
public boolean accept(Stanza packet) {
Message msg = (Message) packet;
return subject.equals(msg.getSubject());
}
});
StanzaCollector response = connection.createStanzaCollectorAndSend(responseFilter, message);
// Wait up to a certain number of seconds for a reply.
response.nextResultOrThrow();
}
Aggregations