use of com.googlecode.asmack.connection.XmppTransportException in project AsmackService by rtreffer.
the class FeatureNegotiationEngine method startCompress.
/**
* Start compression on top of the current stream.
* @throws XmppException In case of a XMPP/XML related error.
* @throws IOException In case of a IOException on the underlying stream.
*/
private void startCompress() throws XmppException, IOException {
xmppOutput.sendUnchecked("<compress xmlns='http://jabber.org/protocol/compress'>" + "<method>zlib</method>" + "</compress>");
boolean startCompression = XMLUtils.isInstance(xmppInput.nextStanza().getDocumentNode(), "http://jabber.org/protocol/compress", "compressed");
if (startCompression) {
xmppOutput.detach();
xmppInput.detach();
try {
outputStream = new ZLibOutputStream(outputStream);
} catch (NoSuchAlgorithmException e) {
// FAIL!
throw new XmppTransportException("Can't create compressed stream", e);
}
xmppOutput.attach(outputStream, true, false);
inputStream = new ZLibInputStream(inputStream);
xmppInput.attach(inputStream);
compressed = true;
}
}
use of com.googlecode.asmack.connection.XmppTransportException 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.connection.XmppTransportException 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.connection.XmppTransportException in project AsmackService by rtreffer.
the class XmppOutputStream method attach.
/**
* Attach this stream to a new OutputStream. This method is usually needed
* during feature negotiation, as some features like compression or tls
* require a stream reset.
* @param out OutputStream The new underlying output stream.
* @param sendDeclaration boolean True if a <code><?xml></code> header
* should be send.
* @param sendBOM boolean False to suppress the utf-8 byte order marker.
* This is usually what you want as BOM is poorly
* tested in the xmpp world and discourged by the
* unicode spec (at least for utf-8).
* @throws IOException In case of a transport error.
* @throws XmlPullParserException In case of a xml error.
*/
public void attach(OutputStream out, boolean sendDeclaration, boolean sendBOM) throws IOException, XmppTransportException {
if (sendBOM) {
Log.d(TAG, "BOM");
out.write(0xEF);
out.write(0xBB);
out.write(0xBF);
}
if (sendDeclaration) {
Log.d(TAG, "open stream");
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>".getBytes());
}
if (sendBOM || sendDeclaration) {
Log.d(TAG, "flush()");
out.flush();
}
outputStream = out;
try {
xmlSerializer = XMLUtils.getXMLSerializer();
} catch (XmlPullParserException e) {
throw new XmppTransportException("Can't initialize the pull parser", e);
}
Log.d(TAG, "set output");
xmlSerializer.setOutput(outputStream, "UTF-8");
}
Aggregations