use of com.googlecode.asmack.XmppMalformedException in project AsmackService by rtreffer.
the class TcpConnection method connect.
/**
* Start the tcp connection to a given ip/port pair.
* @param addresse InetAddress The target internet address.
* @param port int The target port.
* @throws XmppException In case of a lower level exception.
*/
protected void connect(InetAddress addresse, int port) throws XmppException {
SocketFactory socketFactory = SocketFactory.getDefault();
try {
socket = socketFactory.createSocket(addresse, port);
socket.setKeepAlive(false);
socket.setSoTimeout(3 * 60 * 1000);
socket.setTcpNoDelay(true);
} catch (IOException e) {
close();
throw new XmppTransportException("Can't connect", e);
}
FeatureNegotiationEngine engine;
try {
engine = new FeatureNegotiationEngine(socket);
} catch (XmlPullParserException e) {
close();
throw new XmppMalformedException("Can't connect", e);
} catch (IOException e) {
close();
throw new XmppTransportException("Can't connect", e);
}
engine.open(account);
resourceJid = engine.bind(account.getResource());
if (resourceJid == null) {
close();
throw new XmppTransportException("Can't bind");
}
Log.d(TAG, "Bound as " + resourceJid);
xmppInput = engine.getXmppInputStream();
xmppOutput = engine.getXmppOutputStream();
}
use of com.googlecode.asmack.XmppMalformedException 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;
}
use of com.googlecode.asmack.XmppMalformedException in project AsmackService by rtreffer.
the class PresenceBroadcastReceiver method onReceive.
/**
* Receive a single stanza intent, check for xmpp <presence/> and
* store it to the database.
* @param Context The current application context.
* @param intent The event Intent.
*/
@Override
public void onReceive(Context context, Intent intent) {
Stanza stanza = intent.getParcelableExtra("stanza");
if (!"presence".equals(stanza.getName())) {
return;
}
String accountJid = XMPPUtils.getBareJid(stanza.getVia());
String jid = XMPPUtils.getBareJid(stanza.getAttribute("from").getValue());
StatusUpdate update = null;
if (stanza.getAttribute("type") != null) {
if ("unavailable".equals(stanza.getAttribute("type").getValue())) {
update = mapper.getStatusUpdate(accountJid, jid);
update.setPresence(Presence.OFFLINE);
mapper.persist(update);
}
}
try {
update = mapper.getStatusUpdate(accountJid, jid);
update.setPresence(Presence.AVAILABLE);
Node node = stanza.getDocumentNode();
Node show = XMLUtils.getFirstChild(node, null, "show");
if (show != null) {
String presence = show.getTextContent();
if ("away".equals(presence)) {
update.setPresence(Presence.AWAY);
}
if ("dnd".equals(presence)) {
update.setPresence(Presence.DO_NOT_DISTURB);
}
}
Node status = XMLUtils.getFirstChild(node, null, "status");
if (status != null) {
update.setStatus(status.getTextContent());
}
mapper.persist(update);
} catch (XmppMalformedException e) {
e.printStackTrace();
}
}
Aggregations