protected void callConnectionClosedOnErrorListener(Exception e) { boolean logWarning = true; if (e instanceof StreamErrorException) { StreamErrorException see = (StreamErrorException) e; if (see.getStreamError().getCondition() == StreamError.Condition.not_authorized && wasAuthenticated) { logWarning = false; LOGGER.log(Level.FINE, "Connection closed with not-authorized stream error after it was already authenticated. The account was likely deleted/unregistered on the server"); } } if (logWarning) { LOGGER.log(Level.WARNING, "Connection " + this + " closed with error", e); } for (ConnectionListener listener : connectionListeners) { try { listener.connectionClosedOnError(e); } catch (Exception e2) { // Catch and print any exception so we can recover // from a faulty listener LOGGER.log(Level.SEVERE, "Error in listener while closing connection", e2); } } }
switch (xmppEx.getStreamError().getCondition())
/** * Creates a new XMPPException with the stream error that was the root case of the * exception. When a stream error is received from the server then the underlying connection * will be closed by the server. * * @param streamError the root cause of the exception. */ public StreamErrorException(StreamError streamError) { super(streamError.getCondition().toString() + " You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions\n" + streamError.toString()); this.streamError = streamError; }
@Override public void connectionClosedOnError(Exception e) { done = false; if (!isAutomaticReconnectEnabled()) { return; } if (e instanceof StreamErrorException) { StreamErrorException xmppEx = (StreamErrorException) e; StreamError error = xmppEx.getStreamError(); if (StreamError.Condition.conflict == error.getCondition()) { return; } } reconnect(); } };
@Test public void testParsingOfSimpleStreamError() { StreamError error = null; final String xml = // Usually the stream:stream element has more attributes (to, version, ...) // We omit those, since they are not relevant for testing "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' /> +" + "</stream:error>" + "</stream:stream>"; try { XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error"); error = PacketParserUtils.parseStreamError(parser); } catch (Exception e) { fail(e.getMessage()); } assertNotNull(error); assertEquals(Condition.conflict, error.getCondition()); }
@Test public void testStreamErrorXmlNotWellFormed() { StreamError error = null; final String xml = // Usually the stream:stream element has more attributes (to, version, ...) // We omit those, since they are not relevant for testing "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>" + "</stream:stream>"; try { XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error"); error = PacketParserUtils.parseStreamError(parser); } catch (Exception e) { fail(e.getMessage()); } assertNotNull(error); assertEquals(Condition.not_well_formed, error.getCondition()); } }
@Test public void testParsingOfStreamErrorWithText() { StreamError error = null; final String xml = // Usually the stream:stream element has more attributes (to, version, ...) // We omit those, since they are not relevant for testing "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' />" + "<text xml:lang='' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" + "Replaced by new connection" + "</text>" + "</stream:error>" + "</stream:stream>"; try { XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error"); error = PacketParserUtils.parseStreamError(parser); } catch (Exception e) { fail(e.getMessage()); } assertNotNull(error); assertEquals(Condition.conflict, error.getCondition()); assertEquals("Replaced by new connection", error.getDescriptiveText()); }
@Test public void testParsingOfStreamErrorWithTextAndOptionalElement() { StreamError error = null; final String xml = // Usually the stream:stream element has more attributes (to, version, ...) // We omit those, since they are not relevant for testing "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' />" + "<text xml:lang='' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" + "Replaced by new connection" + "</text>" + "<appSpecificElement xmlns='myns'>" + "Text contents of application-specific condition element: Foo Bar" + "</appSpecificElement>" + "</stream:error>" + "</stream:stream>"; try { XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error"); error = PacketParserUtils.parseStreamError(parser); } catch (Exception e) { fail(e.getMessage()); } assertNotNull(error); assertEquals(Condition.conflict, error.getCondition()); assertEquals("Replaced by new connection", error.getDescriptiveText()); ExtensionElement appSpecificElement = error.getExtension("appSpecificElement", "myns"); assertNotNull(appSpecificElement); }
protected void callConnectionClosedOnErrorListener(Exception e) { boolean logWarning = true; if (e instanceof StreamErrorException) { StreamErrorException see = (StreamErrorException) e; if (see.getStreamError().getCondition() == StreamError.Condition.not_authorized && wasAuthenticated) { logWarning = false; LOGGER.log(Level.FINE, "Connection closed with not-authorized stream error after it was already authenticated. The account was likely deleted/unregistered on the server"); } } if (logWarning) { LOGGER.log(Level.WARNING, "Connection " + this + " closed with error", e); } for (ConnectionListener listener : connectionListeners) { try { listener.connectionClosedOnError(e); } catch (Exception e2) { // Catch and print any exception so we can recover // from a faulty listener LOGGER.log(Level.SEVERE, "Error in listener while closing connection", e2); } } }
/** * Creates a new XMPPException with the stream error that was the root case of the * exception. When a stream error is received from the server then the underlying connection * will be closed by the server. * * @param streamError the root cause of the exception. */ public StreamErrorException(StreamError streamError) { super(streamError.getCondition().toString() + " You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions\n" + streamError.toString()); this.streamError = streamError; }
@Override public void connectionClosedOnError(Exception e) { done = false; if (!isAutomaticReconnectEnabled()) { return; } if (e instanceof StreamErrorException) { StreamErrorException xmppEx = (StreamErrorException) e; StreamError error = xmppEx.getStreamError(); if (StreamError.Condition.conflict == error.getCondition()) { return; } } reconnect(); } };
public void connectionClosedOnError(Exception ex) { handleDisconnect(); String message = Res.getString("message.disconnected.error"); if (ex instanceof XMPPException.StreamErrorException && ((XMPPException.StreamErrorException) ex).getStreamError().getCondition() == StreamError.Condition.conflict ) { message = Res.getString("message.disconnected.conflict.error"); } getTranscriptWindow().insertNotificationMessage(message, ChatManager.ERROR_COLOR); }