Search in sources :

Example 16 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class EnhancedDebugger method addSentPacketToTable.

/**
     * Adds the sent stanza(/packet) detail to the messages table.
     *
     * @param dateFormatter the SimpleDateFormat to use to format Dates
     * @param packet        the sent stanza(/packet) to add to the table
     */
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            String messageType;
            Jid to = packet.getTo();
            String type = "";
            Icon packetTypeIcon;
            sentPackets++;
            if (packet instanceof IQ) {
                packetTypeIcon = iqPacketIcon;
                messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
                type = ((IQ) packet).getType().toString();
                sentIQPackets++;
            } else if (packet instanceof Message) {
                packetTypeIcon = messagePacketIcon;
                messageType = "Message Sent";
                type = ((Message) packet).getType().toString();
                sentMessagePackets++;
            } else if (packet instanceof Presence) {
                packetTypeIcon = presencePacketIcon;
                messageType = "Presence Sent";
                type = ((Presence) packet).getType().toString();
                sentPresencePackets++;
            } else {
                packetTypeIcon = unknownPacketTypeIcon;
                messageType = packet.getClass().getName() + " Sent";
                sentOtherPackets++;
            }
            // Check if we need to remove old rows from the table to keep memory consumption low
            if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                messagesTable.removeRow(0);
            }
            messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetSentIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, to, "" });
            // Update the statistics table
            updateStatistics();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Example 17 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class CarbonManager method setCarbonsEnabled.

/**
     * Notify server to change the carbons state. This method blocks
     * some time until the server replies to the IQ and returns true on
     * success.
     *
     * You should first check for support using isSupportedByServer().
     *
     * @param new_state whether carbons should be enabled or disabled
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     *
     */
public synchronized void setCarbonsEnabled(final boolean new_state) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (enabled_state == new_state)
        return;
    IQ setIQ = carbonsEnabledIQ(new_state);
    connection().createStanzaCollectorAndSend(setIQ).nextResultOrThrow();
    enabled_state = new_state;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 18 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class StanzaIdTest method testIqId.

@Test
public void testIqId() {
    IQ iq1 = new TestIQ();
    String iq1Id = iq1.getStanzaId();
    assertTrue(StringUtils.isNotEmpty(iq1Id));
    IQ iq2 = new TestIQ();
    String iq2Id = iq2.getStanzaId();
    assertTrue(StringUtils.isNotEmpty(iq2Id));
    assertFalse(iq1Id.equals(iq2Id));
}
Also used : TestIQ(org.jivesoftware.smack.packet.TestIQ) TestIQ(org.jivesoftware.smack.packet.TestIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 19 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class TransportNegotiator method receiveSessionInitiateAction.

/**
     *  @param jingle
     *  @param jingleTransport
     *  @return the iq
     * @throws SmackException 
     * @throws InterruptedException 
     */
private IQ receiveSessionInitiateAction(Jingle jingle) throws XMPPException, SmackException, InterruptedException {
    IQ response = null;
    // Parse the Jingle and get any proposed transport candidates
    //addRemoteCandidates(obtainCandidatesList(jin));
    // Start offering candidates
    sendTransportCandidatesOffer();
    // All these candidates will be checked asyncronously. Wait for some
    // time and check if we have a valid candidate to use...
    delayedCheckBestCandidate(session, jingle);
    // Set the next state
    setNegotiatorState(JingleNegotiatorState.PENDING);
    return response;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 20 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class TransportNegotiator method receiveTransportInfoAction.

/**
     *  @param jingle
     *  @param jingleTransport
     *  @return the iq
     */
private IQ receiveTransportInfoAction(Jingle jingle) {
    IQ response = null;
    // Parse the Jingle and get any proposed transport candidates
    //addRemoteCandidates(obtainCandidatesList(jin));
    //        // Start offering candidates
    //        sendTransportCandidatesOffer();
    //
    //        // All these candidates will be checked asyncronously. Wait for some
    //        // time and check if we have a valid candidate to use...
    //        delayedCheckBestCandidate(session, jingle);
    //
    //        // Set the next state
    //        setNegotiatorState(JingleNegotiatorState.PENDING);
    // Parse the Jingle and get any proposed transport candidates
    addRemoteCandidates(obtainCandidatesList(jingle));
    // Wait for some time and check if we have a valid candidate to
    // use...
    delayedCheckBestCandidate(session, jingle);
    response = session.createAck(jingle);
    return response;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)138 Test (org.junit.Test)57 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 InputStream (java.io.InputStream)11 StanzaListener (org.jivesoftware.smack.StanzaListener)10 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)8 XMPPError (org.jivesoftware.smack.packet.XMPPError)7 Jid (org.jxmpp.jid.Jid)7 NetworkException (com.xabber.android.data.NetworkException)6 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 IOException (java.io.IOException)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)6 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6