use of com.googlecode.asmack.Stanza 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.Stanza 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.Stanza 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);
}
}
use of com.googlecode.asmack.Stanza in project AsmackService by rtreffer.
the class FeatureNegotiationEngine method bind.
/**
* Bind a given resource, probably resuming an old session.
* @param resource String The preferred resource string.
* @return String The actual resource string.
* @throws XmppException On Error.
*/
public String bind(String resource) throws XmppException {
try {
if (!TextUtils.isEmpty(resource)) {
xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>" + resource + "</resource>" + "</bind>" + "</iq>");
} else {
xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "</bind>" + "</iq>");
}
Stanza stanza = xmppInput.nextStanza();
Node node = XMLUtils.getDocumentNode(stanza.getXml());
Node bind = XMLUtils.getFirstChild(node, "urn:ietf:params:xml:ns:xmpp-bind", "bind");
Node jid = XMLUtils.getFirstChild(bind, null, "jid");
if (sessionsSupported) {
startSession();
}
return jid.getTextContent();
} catch (IllegalArgumentException e) {
throw new XmppMalformedException("bind malformed", e);
} catch (IllegalStateException e) {
throw new XmppMalformedException("bind malformed", e);
} catch (SAXException e) {
throw new XmppMalformedException("bind malformed", e);
}
}
use of com.googlecode.asmack.Stanza in project AsmackService by rtreffer.
the class XmppInputStream method nextStanza.
/**
* Pull the next stanza from the stream, throwing a XmppException on error.
* @return Stanza The next stream stanza.
* @throws XmppException In case of a xmpp error.
*/
public Stanza nextStanza() throws XmppException {
Stanza stanza = null;
try {
stanza = XMLUtils.readStanza(parser);
} catch (IllegalArgumentException e) {
throw new XmppMalformedException("can't parse stanza", e);
} catch (IllegalStateException e) {
throw new XmppMalformedException("can't parse stanza", e);
} catch (XmlPullParserException e) {
throw new XmppMalformedException("can't parse stanza", e);
} catch (IOException e) {
throw new XmppTransportException("error during stanza read", e);
} catch (ArrayIndexOutOfBoundsException e) {
throw new XmppTransportException("XML reader b0rked", e);
}
if (debugEnabled) {
Log.d(TAG, "Stanza: " + stanza.getXml());
}
lastReceiveTime = System.currentTimeMillis();
return stanza;
}
Aggregations