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;
}
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);
}
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 */
}
}
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);
}
}
}
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);
}
}
Aggregations