mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Merge branch '4.3'
This commit is contained in:
commit
ce4f3352a2
33 changed files with 119 additions and 77 deletions
|
@ -120,7 +120,7 @@ public class LoginTest extends SmackTestCase {
|
|||
conn.getAccountManager().createAccount("user_1", "user_1", getAccountCreationParameters());
|
||||
} catch (XMPPException e) {
|
||||
// Do nothing if the account already exists
|
||||
if (e.getXMPPError().getCode() != 409) {
|
||||
if (e.getStanzaError().getCode() != 409) {
|
||||
throw e;
|
||||
}
|
||||
// Else recreate the connection, ins case the server closed it as
|
||||
|
@ -141,8 +141,8 @@ public class LoginTest extends SmackTestCase {
|
|||
}
|
||||
|
||||
} catch (XMPPException e) {
|
||||
if (e.getXMPPError() != null) {
|
||||
assertEquals("Wrong error code returned", 406, e.getXMPPError().getCode());
|
||||
if (e.getStanzaError() != null) {
|
||||
assertEquals("Wrong error code returned", 406, e.getStanzaError().getCode());
|
||||
} else {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ public class PrivacyTest extends SmackTestCase {
|
|||
// The list should not exist and an error will be raised
|
||||
privacyManager.getDefaultList();
|
||||
} catch (XMPPException xmppException) {
|
||||
assertEquals(404, xmppException.getXMPPError().getCode());
|
||||
assertEquals(404, xmppException.getStanzaError().getCode());
|
||||
}
|
||||
|
||||
assertEquals(null, null);
|
||||
|
@ -255,7 +255,7 @@ public class PrivacyTest extends SmackTestCase {
|
|||
// The list should not exist and an error will be raised
|
||||
privacyManager.getActiveList();
|
||||
} catch (XMPPException xmppException) {
|
||||
assertEquals(404, xmppException.getXMPPError().getCode());
|
||||
assertEquals(404, xmppException.getStanzaError().getCode());
|
||||
}
|
||||
|
||||
assertEquals(null, null);
|
||||
|
@ -341,7 +341,7 @@ public class PrivacyTest extends SmackTestCase {
|
|||
// The list should not exist and an error will be raised
|
||||
privacyManager.getPrivacyList(listName);
|
||||
} catch (XMPPException xmppException) {
|
||||
assertEquals(404, xmppException.getXMPPError().getCode());
|
||||
assertEquals(404, xmppException.getStanzaError().getCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -69,6 +69,10 @@ public abstract class XMPPException extends Exception {
|
|||
super(message, wrappedThrowable);
|
||||
}
|
||||
|
||||
/**
|
||||
* An exception caused by an XMPP error stanza response on the protocol level. You can examine the underlying
|
||||
* {@link StanzaError} by calling {@link #getStanzaError()}.
|
||||
*/
|
||||
public static class XMPPErrorException extends XMPPException {
|
||||
/**
|
||||
*
|
||||
|
@ -123,11 +127,23 @@ public abstract class XMPPException extends Exception {
|
|||
* one.
|
||||
*
|
||||
* @return the XMPPError associated with this exception.
|
||||
* @deprecated use {@link #getStanzaError()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO Remove in Smack 4.4.
|
||||
public StanzaError getXMPPError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stanza error extension element associated with this exception.
|
||||
*
|
||||
* @return the stanza error extension element associated with this exception.
|
||||
*/
|
||||
public StanzaError getStanzaError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request which triggered the error response causing this exception.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus.
|
||||
* Copyright 2017-2018 Florian Schmaus.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,6 +27,7 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
|
|||
entityBare,
|
||||
domainFull,
|
||||
domainBare,
|
||||
any,
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -55,6 +56,8 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
|
|||
return jid.isDomainFullJid();
|
||||
case domainBare:
|
||||
return jid.isDomainBareJid();
|
||||
case any:
|
||||
return true;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus.
|
||||
* Copyright 2017-2018 Florian Schmaus.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -26,6 +26,7 @@ public final class FromTypeFilter extends AbstractJidTypeFilter {
|
|||
public static final FromTypeFilter ENTITY_BARE_JID = new FromTypeFilter(JidType.entityBare);
|
||||
public static final FromTypeFilter DOMAIN_FULL_JID = new FromTypeFilter(JidType.domainFull);
|
||||
public static final FromTypeFilter DOMAIN_BARE_JID = new FromTypeFilter(JidType.domainBare);
|
||||
public static final FromTypeFilter FROM_ANY_JID = new FromTypeFilter(JidType.any);
|
||||
|
||||
private FromTypeFilter(JidType jidType) {
|
||||
super(jidType);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus.
|
||||
* Copyright 2017-2018 Florian Schmaus.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -26,6 +26,7 @@ public final class ToTypeFilter extends AbstractJidTypeFilter {
|
|||
public static final ToTypeFilter ENTITY_BARE_JID = new ToTypeFilter(JidType.entityBare);
|
||||
public static final ToTypeFilter DOMAIN_FULL_JID = new ToTypeFilter(JidType.domainFull);
|
||||
public static final ToTypeFilter DOMAIN_BARE_JID = new ToTypeFilter(JidType.domainBare);
|
||||
public static final ToTypeFilter TO_ANY_JID = new ToTypeFilter(JidType.any);
|
||||
|
||||
public static final StanzaFilter ENTITY_FULL_OR_BARE_JID = new OrFilter(ENTITY_FULL_JID, ENTITY_BARE_JID);
|
||||
|
||||
|
|
|
@ -62,9 +62,16 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
* @see <a href="http://xmpp.org/rfcs/rfc6120.html#stanzas-error-syntax">RFC 6120 - 8.3.2 Syntax: The Syntax of XMPP error stanzas</a>
|
||||
*/
|
||||
// TODO Use StanzaErrorTextElement here.
|
||||
public class StanzaError extends AbstractError {
|
||||
public class StanzaError extends AbstractError implements ExtensionElement {
|
||||
|
||||
public static final String ERROR_CONDITION_AND_TEXT_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas";
|
||||
|
||||
/**
|
||||
* TODO describe me.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String NAMESPACE = ERROR_CONDITION_AND_TEXT_NAMESPACE;
|
||||
|
||||
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas";
|
||||
public static final String ERROR = "error";
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(StanzaError.class.getName());
|
||||
|
@ -117,7 +124,7 @@ public class StanzaError extends AbstractError {
|
|||
*/
|
||||
public StanzaError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
|
||||
List<ExtensionElement> extensions, Stanza stanza) {
|
||||
super(descriptiveTexts, NAMESPACE, extensions);
|
||||
super(descriptiveTexts, ERROR_CONDITION_AND_TEXT_NAMESPACE, extensions);
|
||||
this.condition = Objects.requireNonNull(condition, "condition must not be null");
|
||||
this.stanza = stanza;
|
||||
// Some implementations may send the condition as non-empty element containing the empty string, that is
|
||||
|
@ -197,20 +204,34 @@ public class StanzaError extends AbstractError {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return StreamOpen.CLIENT_NAMESPACE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error as XML.
|
||||
*
|
||||
* @return the error as XML.
|
||||
*/
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(ERROR);
|
||||
return toXML(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(String enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.attribute("type", type.toString());
|
||||
xml.optAttribute("by", errorGenerator);
|
||||
xml.rightAngleBracket();
|
||||
|
||||
xml.halfOpenElement(condition.toString());
|
||||
xml.xmlnsAttribute(NAMESPACE);
|
||||
xml.xmlnsAttribute(ERROR_CONDITION_AND_TEXT_NAMESPACE);
|
||||
if (conditionText != null) {
|
||||
xml.rightAngleBracket();
|
||||
xml.escape(conditionText);
|
||||
|
@ -222,7 +243,7 @@ public class StanzaError extends AbstractError {
|
|||
|
||||
addDescriptiveTextsAndExtensions(xml);
|
||||
|
||||
xml.closeElement(ERROR);
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.jivesoftware.smack.packet;
|
|||
|
||||
public class StanzaErrorTextElement extends AbstractTextElement {
|
||||
|
||||
public static final String NAMESPACE = StanzaError.NAMESPACE;
|
||||
public static final String NAMESPACE = StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE;
|
||||
|
||||
public StanzaErrorTextElement(String text, String lang) {
|
||||
super(text, lang);
|
||||
|
|
|
@ -855,7 +855,7 @@ public class PacketParserUtils {
|
|||
String name = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
switch (namespace) {
|
||||
case StanzaError.NAMESPACE:
|
||||
case StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE:
|
||||
switch (name) {
|
||||
case Stanza.TEXT:
|
||||
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
|
||||
|
|
|
@ -906,10 +906,10 @@ public class PacketParserUtilsTest {
|
|||
.build();
|
||||
final String errorXml = XMLBuilder
|
||||
.create(StanzaError.ERROR).a("type", "cancel").up()
|
||||
.element("internal-server-error", StanzaError.NAMESPACE).up()
|
||||
.element("text", StanzaError.NAMESPACE).t(text).up()
|
||||
.element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up()
|
||||
.element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up()
|
||||
.asString();
|
||||
XmlUnitUtils.assertSimilar(errorXml, error.toXML());
|
||||
XmlUnitUtils.assertSimilar(errorXml, error.toXML(StreamOpen.CLIENT_NAMESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -917,8 +917,8 @@ public class PacketParserUtilsTest {
|
|||
final String text = "Dummy descriptive text";
|
||||
final String errorXml = XMLBuilder
|
||||
.create(StanzaError.ERROR).a("type", "cancel").up()
|
||||
.element("internal-server-error", StanzaError.NAMESPACE).up()
|
||||
.element("text", StanzaError.NAMESPACE).t(text).up()
|
||||
.element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up()
|
||||
.element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up()
|
||||
.asString();
|
||||
XmlPullParser parser = TestUtils.getParser(errorXml);
|
||||
StanzaError error = PacketParserUtils.parseError(parser).build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue