Search in sources :

Example 6 with AndFilter

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();
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 7 with AndFilter

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));
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 8 with AndFilter

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();
}
Also used : MessageTypeFilter(org.jivesoftware.smack.filter.MessageTypeFilter) AndFilter(org.jivesoftware.smack.filter.AndFilter) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DiscussionHistory(org.jivesoftware.smackx.muc.DiscussionHistory) SmackException(org.jivesoftware.smack.SmackException) Presence(org.jivesoftware.smack.packet.Presence) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter)

Example 9 with AndFilter

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)));
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 10 with AndFilter

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();
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Message(org.jivesoftware.smack.packet.Message) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Aggregations

AndFilter (org.jivesoftware.smack.filter.AndFilter)16 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)7 Presence (org.jivesoftware.smack.packet.Presence)7 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)5 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)4 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)3 Message (org.jivesoftware.smack.packet.Message)3 Stanza (org.jivesoftware.smack.packet.Stanza)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 OrFilter (org.jivesoftware.smack.filter.OrFilter)2 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)2 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)2 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)2 MetaData (org.jivesoftware.smackx.workgroup.MetaData)2 EntityFullJid (org.jxmpp.jid.EntityFullJid)2 ArrayList (java.util.ArrayList)1