return new StreamError(condition, conditionText, descriptiveTexts, extensions);
/** * 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 XmlStringBuilder toXML(String enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(); xml.openElement(ELEMENT); xml.halfOpenElement(condition.toString()).xmlnsAttribute(NAMESPACE).closeEmptyElement(); addDescriptiveTextsAndExtensions(xml); xml.closeElement(ELEMENT); return xml; }
@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); }
@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()); }
public String getMessage() { String msg = super.getMessage(); // If the message was not set, but there is an XMPPError, return the // XMPPError as the message. if (msg == null && error != null) { return error.toString(); } else if (msg == null && streamError != null) { return streamError.toString(); } return msg; }
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); } } }
public void connectionClosedOnError(Exception e) { done = false; if (e instanceof XMPPException) { XMPPException xmppEx = (XMPPException) e; StreamError error = xmppEx.getStreamError(); // Make sure the error is not null if (error != null) { String reason = error.getCode(); if ("conflict".equals(reason)) { return; } } } if (this.isReconnectionAllowed()) { this.reconnect(); } }
switch (xmppEx.getStreamError().getCondition()) errorMessage = Res.getString("message.general.error", xmppEx.getStreamError().getConditionText()); break;
@Override public String toString() { return toXML(null).toString(); }
public String getMessage() { String msg = super.getMessage(); // If the message was not set, but there is an XMPPError, return the // XMPPError as the message. if (msg == null && error != null) { return error.toString(); } else if (msg == null && streamError != null) { return streamError.toString(); } return msg; }
@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 e) { done = false; if (e instanceof XMPPException) { XMPPException xmppEx = (XMPPException) e; StreamError error = xmppEx.getStreamError(); // Make sure the error is not null if (error != null) { String reason = error.getCode(); if ("conflict".equals(reason)) { return; } } } if (this.isReconnectionAllowed()) { this.reconnect(); } }
@Override public String toString() { return toXML(null).toString(); }
private StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException { StreamError streamError = null; boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { streamError = new StreamError(parser.getName()); } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("error")) { done = true; } } } return streamError; }
/** * 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; }
public String getMessage() { String msg = super.getMessage(); // If the message was not set, but there is an XMPPError, return the // XMPPError as the message. if (msg == null && error != null) { return error.toString(); } else if (msg == null && streamError != null) { return streamError.toString(); } return msg; }
@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()); }
public void connectionClosedOnError(Exception e) { done = false; if (e instanceof XMPPException) { XMPPException xmppEx = (XMPPException) e; StreamError error = xmppEx.getStreamError(); // Make sure the error is not null if (error != null) { String reason = error.getCode(); if ("conflict".equals(reason)) { return; } } } if (this.isReconnectionAllowed()) { this.reconnect(); } }
@Override public XmlStringBuilder toXML(String enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(); xml.openElement(ELEMENT); xml.halfOpenElement(condition.toString()).xmlnsAttribute(NAMESPACE).closeEmptyElement(); addDescriptiveTextsAndExtensions(xml); xml.closeElement(ELEMENT); return xml; }