Search in sources :

Example 61 with IQ

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

the class StreamNegotiator method initiateIncomingStream.

protected final IQ initiateIncomingStream(final XMPPConnection connection, StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException {
    final StreamInitiation response = createInitiationAccept(initiation, getNamespaces());
    newStreamInitiation(initiation.getFrom(), initiation.getSessionID());
    final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID();
    IQ streamMethodInitiation;
    try {
        streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getReplyTimeout(), new Callback<NotConnectedException>() {

            @Override
            public void action() throws NotConnectedException {
                try {
                    connection.sendStanza(response);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
        });
    } catch (InterruptedException e) {
        // TODO remove this try/catch once merged into 4.2's master branch
        throw new IllegalStateException(e);
    }
    if (streamMethodInitiation == null) {
        throw NoResponseException.newWith(connection, "stream initiation");
    }
    XMPPErrorException.ifHasErrorThenThrow(streamMethodInitiation);
    return streamMethodInitiation;
}
Also used : StreamInitiation(org.jivesoftware.smackx.si.packet.StreamInitiation) Callback(org.jivesoftware.smack.util.EventManger.Callback) IQ(org.jivesoftware.smack.packet.IQ)

Example 62 with IQ

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

the class FaultTolerantNegotiator method createIncomingStream.

@Override
public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException {
    // This could be either an xep47 ibb 'open' iq or an xep65 streamhost iq
    IQ initationSet = initiateIncomingStream(connection, initiation);
    StreamNegotiator streamNegotiator = determineNegotiator(initationSet);
    return streamNegotiator.negotiateIncomingStream(initationSet);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 63 with IQ

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

the class InBandBytestreamManager method replyRejectPacket.

/**
     * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream is
     * not accepted.
     * 
     * @param request IQ stanza(/packet) that should be answered with a not-acceptable error
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
protected void replyRejectPacket(IQ request) throws NotConnectedException, InterruptedException {
    IQ error = IQ.createErrorResponse(request, XMPPError.Condition.not_acceptable);
    this.connection.sendStanza(error);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 64 with IQ

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

the class InBandBytestreamManager method replyResourceConstraintPacket.

/**
     * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream open
     * request is rejected because its block size is greater than the maximum allowed block size.
     * 
     * @param request IQ stanza(/packet) that should be answered with a resource-constraint error
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
protected void replyResourceConstraintPacket(IQ request) throws NotConnectedException, InterruptedException {
    IQ error = IQ.createErrorResponse(request, XMPPError.Condition.resource_constraint);
    this.connection.sendStanza(error);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 65 with IQ

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

the class LastActivityTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    XMLBuilder xml = XMLBuilder.create("iq");
    xml.a("from", "romeo@montague.net/orchard").a("id", "last2").a("to", "juliet@capulet.com/balcony").a("type", "get").e("query").namespace(LastActivity.NAMESPACE);
    DummyConnection c = new DummyConnection();
    c.connect();
    IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
    assertTrue(lastRequest instanceof LastActivity);
    c.processStanza(lastRequest);
    Stanza reply = c.getSentPacket();
    assertTrue(reply instanceof LastActivity);
    LastActivity l = (LastActivity) reply;
    assertEquals("last2", l.getStanzaId());
    assertEquals(IQ.Type.result, l.getType());
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) XMLBuilder(com.jamesmurty.utils.XMLBuilder) LastActivity(org.jivesoftware.smackx.iqlast.packet.LastActivity) Test(org.junit.Test)

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