Search in sources :

Example 1 with XmppException

use of com.googlecode.asmack.XmppException in project AsmackService by rtreffer.

the class XmppTransportService method send.

/**
     * Send a stanza via the first matching connection.
     * @param stanza The stanza to send.
     * @return True on success.
     */
public boolean send(Stanza stanza) {
    Log.d(TAG, "Sending stanza " + stanza.getName() + " via " + stanza.getVia());
    String via = stanza.getVia();
    if (via == null) {
        Log.w(TAG, "Sending stanza without via");
        return false;
    }
    if ("iq".equals(stanza.getName())) {
        Attribute id = stanza.getAttribute("id");
        if (id == null) {
            Log.w(TAG, "Sending iq without id");
            return false;
        }
    }
    Connection connection = getConnectionForJid(via);
    if (connection == null) {
        Log.w(TAG, "No connection for " + via);
        return false;
    }
    try {
        connection.send(stanza);
        return true;
    } catch (XmppException e) {
        Log.e(TAG, "Connection failed, dropping...", e);
        try {
            connection.close();
        } catch (XmppException e1) {
            Log.d(TAG, "Closing a broken connection failed.", e);
        }
    }
    Log.e(TAG, "No stream for " + via);
    return false;
}
Also used : Attribute(com.googlecode.asmack.Attribute) XmppException(com.googlecode.asmack.XmppException)

Example 2 with XmppException

use of com.googlecode.asmack.XmppException in project AsmackService by rtreffer.

the class AccountConnection method connectionSuccess.

/**
     * Mark the connection as connected, unless the connection is connected.
     * @param loginThread The initial login thread.
     * @param connection The new connection.
     */
public synchronized void connectionSuccess(LoginThread loginThread, Connection connection) {
    Connection oldConnection = null;
    if (currentState == State.Connected) {
        Log.w(TAG, "TWO CONNECTIONS RUNNING");
        oldConnection = this.connection;
    }
    // Try to send an initial stanza
    Stanza stanza = new Stanza("presence", "", null, "<presence />", null);
    try {
        connection.send(stanza);
    } catch (XmppException e) {
        // Initial stanza failed
        try {
            connection.close();
        } catch (XmppException e1) {
        /* IGNORE */
        }
        if (oldConnection == null || oldConnection.isClosed()) {
            // Only fail if the old connection is invalid
            transition(State.Failed);
        }
        return;
    }
    if (loginThread != null && loginThread != this.loginThread) {
        // concurrent login attempt
        loginThread.interrupt();
    }
    this.loginThread = null;
    if (oldConnection != null) {
        try {
            oldConnection.close();
        } catch (XmppException e) {
        /* IGNORE */
        }
    }
    this.connection = connection;
    transition(State.Connected);
}
Also used : XmppException(com.googlecode.asmack.XmppException) Stanza(com.googlecode.asmack.Stanza)

Example 3 with XmppException

use of com.googlecode.asmack.XmppException in project AsmackService by rtreffer.

the class PresenceRunnable method run.

/**
     * Execute the presence update.
     */
@Override
public void run() {
    String payload = "<presence />";
    if (verification != null) {
        payload = "<presence><c xmlns='http://jabber.org/protocol/caps' " + "hash='sha-1' " + "node='http://github.com/rtreffer/AsmackService' " + "ver='" + verification + "'" + "/></presence>";
    }
    Stanza stanza = new Stanza("presence", "", "", payload, null);
    try {
        connection.send(stanza);
    } catch (XmppException e) {
    /* PING is non critical */
    }
}
Also used : XmppException(com.googlecode.asmack.XmppException) Stanza(com.googlecode.asmack.Stanza)

Example 4 with XmppException

use of com.googlecode.asmack.XmppException in project AsmackService by rtreffer.

the class XmppTransportService method sendFromAllResources.

/**
     * Send a stanza via this service, through all resource jids.
     * @param stanza The stanza to send.
     */
public void sendFromAllResources(Stanza stanza) {
    Log.d(TAG, "Sending stanza " + stanza.getName() + " via *");
    for (AccountConnection state : connections.values()) {
        if (state.getCurrentState() != State.Connected) {
            continue;
        }
        Connection connection = state.getConnection();
        stanza.addAttribute(new Attribute("from", "", connection.getResourceJid()));
        try {
            state.getConnection().send(stanza);
        } catch (XmppException e) {
            Log.w(TAG, "Problem sending staza " + stanza.getName(), e);
        }
    }
}
Also used : Attribute(com.googlecode.asmack.Attribute) XmppException(com.googlecode.asmack.XmppException)

Example 5 with XmppException

use of com.googlecode.asmack.XmppException in project AsmackService by rtreffer.

the class ConncetionPullToSinkPushThread method run.

/**
     * <p>Run the main pull/push loop.</p>
     * <p>The {@link XmppInputStream#nextStanza()} to
     * {@link StanzaSink#receive(Stanza)} will run until a
     * {@link XmppException} is received.</p>
     */
@Override
public void run() {
    String resourceJid = connection.getResourceJid();
    try {
        while (true) {
            Stanza stanza = xmppInput.nextStanza();
            stanza.setVia(resourceJid);
            sink.receive(stanza);
        }
    } catch (XmppException e) {
        try {
            connection.close();
        } catch (Exception ex) {
        // we just try to clean up, ignore problems
        }
        Log.e(TAG, "Connection aborted", e);
        sink.connectionFailed(connection, e);
    }
}
Also used : XmppException(com.googlecode.asmack.XmppException) Stanza(com.googlecode.asmack.Stanza) XmppException(com.googlecode.asmack.XmppException)

Aggregations

XmppException (com.googlecode.asmack.XmppException)6 Attribute (com.googlecode.asmack.Attribute)3 Stanza (com.googlecode.asmack.Stanza)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1 XmlSerializer (org.xmlpull.v1.XmlSerializer)1