org.jivesoftware.smack.packet.XMPPError Java Examples

The following examples show how to use org.jivesoftware.smack.packet.XMPPError. 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: MultiUserSubscriptionUseCases.java    From Smack with Apache License 2.0 6 votes vote down vote up
public void testGetItemsWithMultiSubscription() throws XMPPException
{
	LeafNode node = getRandomPubnode(getManager(0), true, false);
	node.send((Item)null);
	node.send((Item)null);
	node.send((Item)null);
	node.send((Item)null);
	node.send((Item)null);

	LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
	Subscription sub1 = user2Node.subscribe(getBareJID(1));

	Subscription sub2 = user2Node.subscribe(getBareJID(1));

	try
	{
		user2Node.getItems();
	}
	catch (XMPPException exc)
	{
		assertEquals("bad-request", exc.getStanzaError().getCondition());
		assertEquals(XMPPError.Type.MODIFY, exc.getStanzaError().getType());
	}
	List<Item> items = user2Node.getItems(sub1.getId());
	assertTrue(items.size() == 5);
}
 
Example #2
Source File: InBandBytestreamTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Target should respond with not-acceptable error if no listeners for incoming In-Band
 * Bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());

    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(
                    open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
Example #3
Source File: Socks5ByteStreamTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Target should respond with not-acceptable error if no listeners for incoming Socks5
 * bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
                    initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
    bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);

    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(
                    bytestreamInitiation.getStanzaId()));
    initiatorConnection.sendStanza(bytestreamInitiation);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
 
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: CustomPresence.java    From League-of-Legends-XMPP-Chat-Library with MIT License 5 votes vote down vote up
@Override
public XmlStringBuilder toXML() {
	final XmlStringBuilder buf = new XmlStringBuilder();
	buf.halfOpenElement("presence");
	buf.xmlnsAttribute(getXmlns());
	buf.xmllangAttribute(getLanguage());
	addCommonAttributes(buf);
	if (invisible) {
		buf.attribute("type", "invisible");
	} else if (getType() != Type.available) {
		buf.attribute("type", getType());
	}
	buf.rightAngelBracket();

	buf.optElement("status", getStatus());
	if (getPriority() != Integer.MIN_VALUE) {
		buf.element("priority", Integer.toString(getPriority()));
	}
	if (getMode() != null && getMode() != Mode.available) {
		buf.element("show", getMode());
	}
	buf.append(getExtensionsXML());

	// Add the error sub-packet, if there is one.
	final XMPPError error = getError();
	if (error != null) {
		buf.append(error.toXML());
	}
	buf.closeElement("presence");

	return buf;
}
 
Example #6
Source File: PacketReader.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
private void parseFeatures(XmlPullParser parser) throws Exception {
    boolean startTLSReceived = false;
    boolean startTLSRequired = false;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();

        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("starttls")) {
                startTLSReceived = true;
            }
            else if (parser.getName().equals("mechanisms")) {
                // The server is reporting available SASL mechanisms. Store this information
                // which will be used later while logging (i.e. authenticating) into
                // the server
                connection.getSASLAuthentication()
                        .setAvailableSASLMethods(PacketParserUtils.parseMechanisms(parser));
            }
            else if (parser.getName().equals("bind")) {
                // The server requires the client to bind a resource to the stream
                connection.getSASLAuthentication().bindingRequired();
            }
            else if(parser.getName().equals("ver")){
            	connection.getConfiguration().setRosterVersioningAvailable(true);
            }
            else if(parser.getName().equals("c")){
            	String node = parser.getAttributeValue(null, "node");
            	String ver = parser.getAttributeValue(null, "ver");
            	String capsNode = node+"#"+ver;
            	connection.getConfiguration().setCapsNode(capsNode);
            }
            else if (parser.getName().equals("session")) {
                // The server supports sessions
                connection.getSASLAuthentication().sessionsSupported();
            }
            else if (parser.getName().equals("compression")) {
                // The server supports stream compression
                connection.setAvailableCompressionMethods(PacketParserUtils.parseCompressionMethods(parser));
            }
            else if (parser.getName().equals("register")) {
                connection.getAccountManager().setSupportsAccountCreation(true);
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("starttls")) {
                // Confirm the server that we want to use TLS
                connection.startTLSReceived(startTLSRequired);
            }
            else if (parser.getName().equals("required") && startTLSReceived) {
                startTLSRequired = true;
            }
            else if (parser.getName().equals("features")) {
                done = true;
            }
        }
    }

    // If TLS is required but the server doesn't offer it, disconnect
    // from the server and throw an error. First check if we've already negotiated TLS
    // and are secure, however (features get parsed a second time after TLS is established).
    if (!connection.isSecureConnection()) {
        if (!startTLSReceived && connection.getConfiguration().getSecurityMode() ==
                ConnectionConfiguration.SecurityMode.required)
        {
            throw new XMPPException("Server does not support security (TLS), " +
                    "but security required by connection configuration.",
                    new XMPPError(XMPPError.Condition.forbidden));
        }
    }
    
    // Release the lock after TLS has been negotiated or we are not insterested in TLS
    if (!startTLSReceived || connection.getConfiguration().getSecurityMode() ==
            ConnectionConfiguration.SecurityMode.disabled)
    {
        releaseConnectionIDLock();
    }
}
 
Example #7
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);
}
 
Example #8
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Cretaes a new XMPPException with the XMPPError that was the root case of the
 * exception.
 *
 * @param error the root cause of the exception.
 */
public XMPPException(XMPPError error) {
    super();
    this.error = error;
}
 
Example #9
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new XMPPException with a description of the exception, an XMPPError,
 * and the Throwable that was the root cause of the exception.
 *
 * @param message a description of the exception.
 * @param error the root cause of the exception.
 * @param wrappedThrowable the root cause of the exception.
 */
public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) {
    super(message);
    this.error = error;
    this.wrappedThrowable = wrappedThrowable;
}
 
Example #10
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new XMPPException with a description of the exception and the
 * XMPPException that was the root cause of the exception.
 *
 * @param message a description of the exception.
 * @param error the root cause of the exception.
 */
public XMPPException(String message, XMPPError error) {
    super(message);
    this.error = error;
}
 
Example #11
Source File: XMPPException.java    From AndroidPNClient with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the XMPPError asscociated with this exception, or <tt>null</tt> if there
 * isn't one.
 *
 * @return the XMPPError asscociated with this exception.
 */
public XMPPError getXMPPError() {
    return error;
}