org.jivesoftware.smack.packet.StreamError Java Examples

The following examples show how to use org.jivesoftware.smack.packet.StreamError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReconnectionManager.java    From AndroidPNClient with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #2
Source File: AbstractXMPPConnection.java    From Smack with Apache License 2.0 6 votes vote down vote up
private 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);
        }
    }
}
 
Example #3
Source File: MessengerService.java    From KlyphMessenger with MIT License 6 votes vote down vote up
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();
	}
}
 
Example #4
Source File: ConnectionHandler.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private ErrorType getExceptionType(Exception error) {
  // TODO logic copied from eclipse, change after smack 4 update

  if (!(error instanceof XMPPException)
      || !(lastConnectionState == ConnectionState.CONNECTED
          || lastConnectionState == ConnectionState.CONNECTING)) {
    return ErrorType.CONNECTION_LOST;
  }

  XMPPError xmppError = ((XMPPException) error).getXMPPError();
  StreamError streamError = ((XMPPException) error).getStreamError();

  // see http://xmpp.org/rfcs/rfc3921.html chapter 3

  if (lastConnectionState == ConnectionState.CONNECTED
      && (streamError == null || !"conflict".equalsIgnoreCase(streamError.getCode()))) {
    return ErrorType.CONNECTION_LOST;
  }

  if (lastConnectionState == ConnectionState.CONNECTING
      && (xmppError == null || xmppError.getCode() != 409)) {
    return ErrorType.CONNECTION_LOST;
  }

  return ErrorType.RESOURCE_CONFLICT;
}
 
Example #5
Source File: PacketParserUtils.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static StreamError parseStreamError(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
    return parseStreamError(parser, null);
}
 
Example #6
Source File: PacketParserUtils.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * Parses stream error packets.
 *
 * @param parser the XML parser.
 * @param outerXmlEnvironment the outer XML environment (optional).
 * @return an stream error packet.
 * @throws IOException if an I/O error occurred.
 * @throws XmlPullParserException if an error in the XML parser occurred.
 * @throws SmackParsingException if the Smack parser (provider) encountered invalid input.
 */
public static StreamError parseStreamError(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    final int initialDepth = parser.getDepth();
    List<ExtensionElement> extensions = new ArrayList<>();
    Map<String, String> descriptiveTexts = null;
    StreamError.Condition condition = null;
    String conditionText = null;
    XmlEnvironment streamErrorXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            String namespace = parser.getNamespace();
            switch (namespace) {
            case StreamError.NAMESPACE:
                switch (name) {
                case "text":
                    descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
                    break;
                default:
                    // If it's not a text element, that is qualified by the StreamError.NAMESPACE,
                    // then it has to be the stream error code
                    condition = StreamError.Condition.fromString(name);
                    conditionText = parser.nextText();
                    if (conditionText.isEmpty()) {
                        conditionText = null;
                    }
                    break;
                }
                break;
            default:
                PacketParserUtils.addExtensionElement(extensions, parser, name, namespace, streamErrorXmlEnvironment);
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
            break;
        }
    }
    return new StreamError(condition, conditionText, descriptiveTexts, extensions);
}
 
Example #7
Source File: ModularXmppClientToServerConnection.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected void parseAndProcessElement(String element) {
    try {
        XmlPullParser parser = PacketParserUtils.getParserFor(element);

        // Skip the enclosing stream open what is guaranteed to be there.
        parser.next();

        XmlPullParser.Event event = parser.getEventType();
        outerloop: while (true) {
            switch (event) {
            case START_ELEMENT:
                final String name = parser.getName();
                // Note that we don't handle "stream" here as it's done in the splitter.
                switch (name) {
                case Message.ELEMENT:
                case IQ.IQ_ELEMENT:
                case Presence.ELEMENT:
                    try {
                        parseAndProcessStanza(parser);
                    } finally {
                        // TODO: Here would be the following stream management code.
                        // clientHandledStanzasCount = SMUtils.incrementHeight(clientHandledStanzasCount);
                    }
                    break;
                case "error":
                    StreamError streamError = PacketParserUtils.parseStreamError(parser, null);
                    StreamErrorException streamErrorException = new StreamErrorException(streamError);
                    currentXmppException = streamErrorException;
                    notifyWaitingThreads();
                    throw streamErrorException;
                case "features":
                    parseFeatures(parser);
                    afterFeaturesReceived();
                    break;
                default:
                    parseAndProcessNonza(parser);
                    break;
                }
                break;
            case END_DOCUMENT:
                break outerloop;
            default: // fall out
            }
            event = parser.next();
        }
    } catch (XmlPullParserException | IOException | InterruptedException | StreamErrorException
                    | SmackParsingException e) {
        notifyConnectionError(e);
    }
}
 
Example #8
Source File: XMPPException.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Cretaes 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
 * TCP connection will be closed by the server.
 *
 * @param streamError the root cause of the exception.
 */
public XMPPException(StreamError streamError) {
    super();
    this.streamError = streamError;
}
 
Example #10
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the StreamError asscociated with this exception, or <tt>null</tt> if there
 * isn't one. The underlying TCP connection is closed by the server after sending the
 * stream error to the client.
 *
 * @return the StreamError asscociated with this exception.
 */
public StreamError getStreamError() {
    return streamError;
}
 
Example #11
Source File: XMPPException.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the StreamError associated with this exception. The underlying TCP connection is
 * closed by the server after sending the stream error to the client.
 *
 * @return the StreamError associated with this exception.
 */
public StreamError getStreamError() {
    return streamError;
}