/** * Sends out a notification that there was an error with the connection * and closes the connection. Also prints the stack trace of the given exception * * @param e the exception that causes the connection close event. */ private synchronized void notifyConnectionError(Exception e) { // Listeners were already notified of the exception, return right here. if ((packetReader == null || packetReader.done) && (packetWriter == null || packetWriter.done())) return; // Closes the connection temporary. A reconnection is possible // Note that a connection listener of XMPPTCPConnection will drop the SM state in // case the Exception is a StreamErrorException. instantShutdown(); // Notify connection listeners of the error. callConnectionClosedOnErrorListener(e); }
@SmackIntegrationTest public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException { final String body1 = "Hi, what's up? " + testRunId; final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId; final String body3 = "Hi, what's up? I've been just resumed" + testRunId; final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter( MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser()))); try { send(body1, conOne, conTwo); assertMessageWithBodyReceived(body1, collector); conOne.instantShutdown(); send(body2, conOne, conTwo); // Reconnect with xep198 conOne.connect().login(); assertMessageWithBodyReceived(body2, collector); send(body3, conOne, conTwo); assertMessageWithBodyReceived(body3, collector); } finally { collector.cancel(); } }