Java 类org.jivesoftware.smack.packet.ErrorIQ 实例源码

项目:Smack    文件:Socks5ClientForInitiatorTest.java   
/**
 * If the initiator can connect to a SOCKS5 proxy but activating the stream fails an exception
 * should be thrown.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldFailIfActivateSocks5ProxyFails() throws Exception {

    // build error response as reply to the stream activation
    XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
    IQ error = new ErrorIQ(xmppError);
    error.setFrom(proxyJID);
    error.setTo(initiatorJID);

    protocol.addResponse(error, Verification.correspondingSenderReceiver,
                    Verification.requestTypeSET);

    // start a local SOCKS5 proxy
    Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
    socks5Proxy.start();

    StreamHost streamHost = new StreamHost(proxyJID,
                    socks5Proxy.getAddress(), socks5Proxy.getPort());

    // create digest to get the socket opened by target
    String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

    Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
                    connection, sessionID, targetJID);

    try {

        socks5Client.getSocket(10000);

        fail("exception should be thrown");
    }
    catch (XMPPErrorException e) {
        assertTrue(XMPPError.Condition.internal_server_error.equals(e.getXMPPError().getCondition()));
        protocol.verifyAll();
    }

    socks5Proxy.stop();
}
项目:mangosta-android    文件:ChatActivity.java   
private void loadArchivedMessages() {
    mChat = getChatFromRealm();

    if (mChat == null || !mChat.isValid()) {

        if (loadMessagesSwipeRefreshLayout != null) {
            loadMessagesSwipeRefreshLayout.setRefreshing(false);
        }

        if (mErrorArchiveQuerySubscription != null) {
            mErrorArchiveQuerySubscription.unsubscribe();
        }

        if (mArchiveQuerySubscription != null) {
            mArchiveQuerySubscription.unsubscribe();
        }

        return;
    }

    mArchiveQuerySubscription = XMPPSession.getInstance().subscribeToArchiveQuery(new Action1<String>() {
        @Override
        public void call(String s) {
            mArchiveQuerySubscription.unsubscribe();

            if (mErrorArchiveQuerySubscription != null) {
                mErrorArchiveQuerySubscription.unsubscribe();
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (loadMessagesSwipeRefreshLayout != null) {
                        loadMessagesSwipeRefreshLayout.setRefreshing(false);
                    }
                }
            });
        }
    });

    mErrorArchiveQuerySubscription = XMPPSession.getInstance().subscribeToError(new Action1<ErrorIQ>() {
        @Override
        public void call(ErrorIQ errorIQ) {
            mErrorArchiveQuerySubscription.unsubscribe();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (loadMessagesSwipeRefreshLayout != null) {
                        loadMessagesSwipeRefreshLayout.setRefreshing(false);
                    }
                    Toast.makeText(ChatActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                }
            });
        }
    });

    mRoomManager.loadArchivedMessages(mChatJID, PAGES_TO_LOAD, ITEMS_PER_PAGE);
}
项目:mangosta-android    文件:XMPPSession.java   
public Subscription subscribeToError(Action1<ErrorIQ> subscriber) {
    return mErrorPublisher.subscribe(subscriber);
}
项目:Smack    文件:IBBPacketUtils.java   
/**
 * Returns an error IQ.
 * 
 * @param from the senders JID
 * @param to the recipients JID
 * @param xmppError the XMPP error
 * @return an error IQ
 */
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
    IQ errorIQ = new ErrorIQ(xmppError);
    errorIQ.setType(IQ.Type.error);
    errorIQ.setFrom(from);
    errorIQ.setTo(to);
    return errorIQ;
}