Java Code Examples for org.jivesoftware.smack.packet.XMPPError#getCode()

The following examples show how to use org.jivesoftware.smack.packet.XMPPError#getCode() . 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: 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 2
Source File: ConnectionHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private static String generateConnectingFailureErrorMessage(
    XMPPAccount account, Exception exception) {
  if (!(exception instanceof XMPPException)) {
    return MessageFormat.format(
        CoreMessages.ConnectingFailureHandler_unknown_error_message,
        account,
        exception.getMessage());
  }

  XMPPException xmppException = (XMPPException) exception;
  XMPPError error = xmppException.getXMPPError();

  if (error != null && error.getCode() == 504) {
    return MessageFormat.format(
        CoreMessages.ConnectingFailureHandler_server_not_found,
        account.getDomain(),
        error,
        xmppException.getMessage());
  } else if (error != null && error.getCode() == 502) {
    return MessageFormat.format(
        CoreMessages.ConnectingFailureHandler_server_not_connect,
        account.getDomain(),
        (account.getPort() != 0 ? (":" + account.getPort()) : ""),
        error,
        xmppException.getMessage());
  }

  String errorMessage = xmppException.getMessage();

  if (errorMessage != null) {
    if (errorMessage
            .toLowerCase()
            .contains("invalid-authzid") // jabber.org got it wrong ... //$NON-NLS-1$
        || errorMessage.toLowerCase().contains("not-authorized") // SASL //$NON-NLS-1$
        || errorMessage.toLowerCase().contains("403") // non SASL //$NON-NLS-1$
        || errorMessage.toLowerCase().contains("401")) { // non SASL //$NON-NLS-1$

      return MessageFormat.format(
          CoreMessages.ConnectingFailureHandler_invalid_username_password_message,
          account.getUsername(),
          account.getDomain());

    } else if (errorMessage.toLowerCase().contains("503")) { // $NON-NLS-1$
      return CoreMessages.ConnectingFailureHandler_only_sasl_allowed;
    }
  }

  return MessageFormat.format(
      CoreMessages.ConnectingFailureHandler_unknown_error_message, account, xmppException);
}