1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 02:27:58 +01:00

Add XMPPErrorException.getStanzaError()

Also deprecate getXMPPError and let StanzaError implement
ExtensionElement.
This commit is contained in:
Florian Schmaus 2018-06-20 15:55:48 +02:00
parent 651ee7b85e
commit 23bb5c5625
31 changed files with 108 additions and 75 deletions

View file

@ -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());
}

View file

@ -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();

View file

@ -123,11 +123,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.
*

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -90,7 +90,7 @@ public final class IoTControlManager extends IoTManager {
try {
controlRequest.processRequest(iotSetRequest.getFrom(), iotSetRequest.getSetData());
} catch (XMPPErrorException e) {
return IQ.createErrorResponse(iotSetRequest, e.getXMPPError());
return IQ.createErrorResponse(iotSetRequest, e.getStanzaError());
}
return new IoTSetResponse(iotSetRequest);

View file

@ -94,7 +94,7 @@ public class CompressionTest extends SmackTestCase {
setupConnection.getAccountManager().createAccount("user0", "user0");
} catch (XMPPException e) {
// Do nothing if the accout already exists
if (e.getXMPPError().getCode() != 409) {
if (e.getStanzaError().getCode() != 409) {
throw e;
}
}

View file

@ -84,9 +84,9 @@ public class LastActivityManagerTest extends SmackTestCase {
LastActivityManager.getLastActivity(conn0, getFullJID(2));
fail("No error was received from the server. User was able to get info of other user not in his roster.");
} catch (XMPPException e) {
assertNotNull("No error was returned from the server", e.getXMPPError());
assertNotNull("No error was returned from the server", e.getStanzaError());
assertEquals("Forbidden error was not returned from the server", 403,
e.getXMPPError().getCode());
e.getStanzaError().getCode());
}
}
@ -121,7 +121,7 @@ public class LastActivityManagerTest extends SmackTestCase {
try {
lastActivity = LastActivityManager.getLastActivity(conn0, getHost());
} catch (XMPPException e) {
if (e.getXMPPError().getCode() == 403) {
if (e.getStanzaError().getCode() == 403) {
//The test can not be done since the host do not allow this kind of request
return;
}

View file

@ -77,7 +77,7 @@ public class ServiceDiscoveryManagerTest extends SmackTestCase {
fail("Unexpected identities were returned instead of a 404 error");
}
catch (XMPPException e) {
assertEquals("Incorrect error", 404, e.getXMPPError().getCode());
assertEquals("Incorrect error", 404, e.getStanzaError().getCode());
}
catch (Exception e) {
e.printStackTrace();

View file

@ -527,7 +527,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("Other user was able to join with other user's reserved nickname");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull(
"No XMPPError was received when joining with other user's reserved nickname",
xmppError);
@ -551,7 +551,7 @@ public class MultiUserChatTest extends SmackTestCase {
muc3.sendRegistrationForm(answerForm);
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull(
"No XMPPError was received when reserving an already reserved nickname",
xmppError);
@ -605,7 +605,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was allowed to change the room's subject");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull(
"No XMPPError was received when changing the room's subject",
xmppError);
@ -677,7 +677,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to kick a room owner");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received when kicking a room owner", xmppError);
assertEquals(
"A simple participant was able to kick another participant from the room",
@ -754,7 +754,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to ban a room owner");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received when banning a room owner", xmppError);
assertEquals(
"A simple participant was able to ban another participant from the room",
@ -842,7 +842,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to grant voice");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received granting voice", xmppError);
assertEquals(
"A visitor was able to grant voice to another visitor",
@ -947,7 +947,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to grant moderator privileges");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received granting moderator privileges", xmppError);
assertEquals(
"A visitor was able to grant moderator privileges to another visitor",
@ -1078,7 +1078,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to grant membership privileges");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull(
"No XMPPError was received granting membership privileges",
xmppError);
@ -1188,7 +1188,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to grant admin privileges");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received granting admin privileges", xmppError);
assertEquals(
"A visitor was able to grant admin privileges to another visitor",
@ -1363,7 +1363,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to grant ownership privileges");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received granting ownership privileges", xmppError);
assertEquals(
"A visitor was able to grant ownership privileges to another visitor",
@ -1609,7 +1609,7 @@ public class MultiUserChatTest extends SmackTestCase {
fail("User2 was able to get the list of owners");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
XMPPError xmppError = e.getStanzaError();
assertNotNull("No XMPPError was received getting the list of owners", xmppError);
assertEquals(
"A member was able to get the list of owners",

View file

@ -73,8 +73,8 @@ public class MultiUserSubscriptionUseCases extends PubSubTestCase
}
catch (XMPPException exc)
{
assertEquals("bad-request", exc.getXMPPError().getCondition());
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
assertEquals("bad-request", exc.getStanzaError().getCondition());
assertEquals(XMPPError.Type.MODIFY, exc.getStanzaError().getType());
}
List<Item> items = user2Node.getItems(sub1.getId());
assertTrue(items.size() == 5);

View file

@ -47,7 +47,7 @@ public class PublisherUseCases extends SingleUserTestCase
fail("Exception should be thrown when there is no payload");
}
catch (XMPPException e) {
XMPPError err = e.getXMPPError();
XMPPError err = e.getStanzaError();
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
@ -59,7 +59,7 @@ public class PublisherUseCases extends SingleUserTestCase
fail("Exception should be thrown when there is no payload");
}
catch (XMPPException e) {
XMPPError err = e.getXMPPError();
XMPPError err = e.getStanzaError();
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
@ -104,7 +104,7 @@ public class PublisherUseCases extends SingleUserTestCase
fail("Exception should be thrown when there is no payload");
}
catch (XMPPException e) {
XMPPError err = e.getXMPPError();
XMPPError err = e.getStanzaError();
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
@ -116,7 +116,7 @@ public class PublisherUseCases extends SingleUserTestCase
fail("Exception should be thrown when there is no payload");
}
catch (XMPPException e) {
XMPPError err = e.getXMPPError();
XMPPError err = e.getStanzaError();
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));

View file

@ -67,7 +67,7 @@ public class TestEvents extends SmackTestCase
}
catch (XMPPException e)
{
if (e.getXMPPError().getType() == Type.CANCEL && e.getXMPPError().getCondition().equals("item-not-found"))
if (e.getStanzaError().getType() == Type.CANCEL && e.getXMPPError().getCondition().equals("item-not-found"))
creatorNode = creatorMgr.createNode(nodeId);
else
throw e;

View file

@ -460,7 +460,7 @@ public final class AdHocCommandManager extends Manager {
// If there is an exception caused by the next, complete,
// prev or cancel method, then that error is returned to the
// requester.
StanzaError error = e.getXMPPError();
StanzaError error = e.getStanzaError();
// If the error type is cancel, then the execution is
// canceled therefore the status must show that, and the
@ -570,7 +570,7 @@ public final class AdHocCommandManager extends Manager {
// If there is an exception caused by the next, complete,
// prev or cancel method, then that error is returned to the
// requester.
StanzaError error = e.getXMPPError();
StanzaError error = e.getStanzaError();
// If the error type is cancel, then the execution is
// canceled therefore the status must show that, and the

View file

@ -344,7 +344,7 @@ public class OutgoingFileTransfer extends FileTransfer {
}
private void handleXMPPException(XMPPErrorException e) {
StanzaError error = e.getXMPPError();
StanzaError error = e.getStanzaError();
if (error != null) {
switch (error.getCondition()) {
case forbidden:

View file

@ -221,7 +221,7 @@ public final class PrivateDataManager extends Manager {
return true;
}
catch (XMPPErrorException e) {
if (e.getXMPPError().getCondition() == Condition.service_unavailable) {
if (e.getStanzaError().getCondition() == Condition.service_unavailable) {
return false;
}
else {

View file

@ -149,7 +149,7 @@ public final class PingManager extends Manager {
return true;
}
final StanzaError xmppError = xmppErrorException.getXMPPError();
final StanzaError xmppError = xmppErrorException.getStanzaError();
// We may received an error response from an intermediate service returning an error like
// 'remote-server-not-found' or 'remote-server-timeout' to us (which would fake the 'from' address,

View file

@ -276,12 +276,12 @@ public final class PubSubManager extends Manager {
return createNode(id);
}
catch (XMPPErrorException e1) {
if (e1.getXMPPError().getCondition() == Condition.item_not_found) {
if (e1.getStanzaError().getCondition() == Condition.item_not_found) {
try {
return createNode(id);
}
catch (XMPPErrorException e2) {
if (e2.getXMPPError().getCondition() == Condition.conflict) {
if (e2.getStanzaError().getCondition() == Condition.conflict) {
// The node was created in the meantime, re-try getNode(). Note that this case should be rare.
try {
return getNode(id);
@ -294,7 +294,7 @@ public final class PubSubManager extends Manager {
throw e2;
}
}
if (e1.getXMPPError().getCondition() == Condition.service_unavailable) {
if (e1.getStanzaError().getCondition() == Condition.service_unavailable) {
// This could be caused by Prosody bug #805 (see https://prosody.im/issues/issue/805). Prosody does not
// answer to disco#info requests on the node ID, which makes it undecidable if a node is a leaf or
// collection node.
@ -326,7 +326,7 @@ public final class PubSubManager extends Manager {
node = getNode(id);
}
catch (XMPPErrorException e) {
if (e.getXMPPError().getCondition() == Condition.service_unavailable) {
if (e.getStanzaError().getCondition() == Condition.service_unavailable) {
// This could be caused by Prosody bug #805 (see https://prosody.im/issues/issue/805). Prosody does not
// answer to disco#info requests on the node ID, which makes it undecidable if a node is a leaf or
// collection node.
@ -349,7 +349,7 @@ public final class PubSubManager extends Manager {
// Try to ensure that this is not a collection node by asking for one item form the node.
leafNode.getItems(1);
} catch (XMPPErrorException e) {
Condition condition = e.getXMPPError().getCondition();
Condition condition = e.getStanzaError().getCondition();
if (condition == Condition.feature_not_implemented) {
// XEP-0060 § 6.5.9.5: Item retrieval not supported, e.g. because node is a collection node
throw new PubSubException.NotALeafNodeException(id, pubSubService);
@ -369,7 +369,7 @@ public final class PubSubManager extends Manager {
return createNode(id);
}
catch (XMPPErrorException e1) {
if (e1.getXMPPError().getCondition() == Condition.conflict) {
if (e1.getStanzaError().getCondition() == Condition.conflict) {
return getLeafNodeProsodyWorkaround(id);
}
throw e1;
@ -556,7 +556,7 @@ public final class PubSubManager extends Manager {
leafNode = createNode();
}
catch (XMPPErrorException e) {
if (e.getXMPPError().getCondition() == StanzaError.Condition.forbidden) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.forbidden) {
return false;
}
throw e;

View file

@ -125,7 +125,7 @@ public class InBandBytestreamManagerTest extends InitExtensions {
}
catch (XMPPErrorException e) {
assertEquals(StanzaError.Condition.feature_not_implemented,
e.getXMPPError().getCondition());
e.getStanzaError().getCondition());
}
}

View file

@ -451,7 +451,7 @@ public class Socks5ByteStreamManagerTest {
}
catch (XMPPErrorException e) {
protocol.verifyAll();
assertEquals(rejectPacket.getError(), e.getXMPPError());
assertEquals(rejectPacket.getError(), e.getStanzaError());
}
catch (Exception e) {
fail(e.getMessage());

View file

@ -110,7 +110,7 @@ public class Socks5ByteStreamRequestTest {
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
assertTrue(e.getStanzaError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
}
// verify targets response
@ -154,7 +154,7 @@ public class Socks5ByteStreamRequestTest {
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
assertTrue(e.getStanzaError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
}
// verify targets response
@ -201,7 +201,7 @@ public class Socks5ByteStreamRequestTest {
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains(
assertTrue(e.getStanzaError().getDescriptiveText("en").contains(
"Could not establish socket with any provided host"));
}
@ -293,7 +293,7 @@ public class Socks5ByteStreamRequestTest {
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains(
assertTrue(e.getStanzaError().getDescriptiveText("en").contains(
"Could not establish socket with any provided host"));
}

View file

@ -231,7 +231,7 @@ public class Socks5ClientForInitiatorTest {
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(StanzaError.Condition.internal_server_error.equals(e.getXMPPError().getCondition()));
assertTrue(StanzaError.Condition.internal_server_error.equals(e.getStanzaError().getCondition()));
protocol.verifyAll();
}

View file

@ -77,7 +77,7 @@ public class ConfigureFormTest extends InitExtensions {
fail();
}
catch (XMPPErrorException e) {
Assert.assertEquals(StanzaError.Type.AUTH, e.getXMPPError().getType());
Assert.assertEquals(StanzaError.Type.AUTH, e.getStanzaError().getType());
}
}

View file

@ -85,8 +85,8 @@ public class SmackIntegrationTestFrameworkUnitTest {
FailedTest failedTest = failedTests.get(0);
assertTrue(failedTest.failureReason instanceof XMPPErrorException);
XMPPErrorException ex = (XMPPErrorException) failedTest.failureReason;
assertEquals(StanzaError.Condition.bad_request, ex.getXMPPError().getCondition());
assertEquals(ThrowsNonFatalExceptionDummyTest.DESCRIPTIVE_TEXT, ex.getXMPPError().getDescriptiveText());
assertEquals(StanzaError.Condition.bad_request, ex.getStanzaError().getCondition());
assertEquals(ThrowsNonFatalExceptionDummyTest.DESCRIPTIVE_TEXT, ex.getStanzaError().getDescriptiveText());
}
public static class ThrowsNonFatalExceptionDummyTest extends AbstractSmackIntegrationTest {

View file

@ -467,7 +467,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
} catch (XMPPException.XMPPErrorException e) {
if (e.getXMPPError().getCondition() == StanzaError.Condition.item_not_found) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
LOGGER.log(Level.WARNING, "Could not refresh own deviceList, because the node did not exist: "
+ e.getMessage());
return true;

View file

@ -211,7 +211,7 @@ public class StreamManagement {
}
}
public StanzaError.Condition getXMPPErrorCondition() {
public StanzaError.Condition getStanzaErrorCondition() {
return condition;
}
@ -228,7 +228,7 @@ public class StreamManagement {
if (condition != null) {
xml.rightAngleBracket();
xml.append(condition.toString());
xml.xmlnsAttribute(StanzaError.NAMESPACE);
xml.xmlnsAttribute(StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE);
xml.closeEmptyElement();
}
xml.append(textElements);

View file

@ -58,7 +58,7 @@ public class ParseStreamManagement {
case XmlPullParser.START_TAG:
name = parser.getName();
String namespace = parser.getNamespace();
if (StanzaError.NAMESPACE.equals(namespace)) {
if (StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE.equals(namespace)) {
if (name.equals(AbstractTextElement.ELEMENT)) {
String lang = ParserUtils.getXmlLang(parser);
String text = parser.nextText();

View file

@ -1139,7 +1139,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
break;
case Failed.ELEMENT:
Failed failed = ParseStreamManagement.failed(parser);
FailedNonzaException xmppException = new FailedNonzaException(failed, failed.getXMPPErrorCondition());
FailedNonzaException xmppException = new FailedNonzaException(failed, failed.getStanzaErrorCondition());
// If only XEP-198 would specify different failure elements for the SM
// enable and SM resume failure case. But this is not the case, so we
// need to determine if this is a 'Failed' response for either 'Enable'

View file

@ -85,7 +85,7 @@ public class ParseStreamManagementTest {
PacketParserUtils.getParserFor(failedStanza));
assertThat(failedPacket, is(notNullValue()));
assertTrue(failedPacket.getXMPPErrorCondition() == null);
assertTrue(failedPacket.getStanzaErrorCondition() == null);
}
@Test
@ -94,14 +94,14 @@ public class ParseStreamManagementTest {
String failedStanza = XMLBuilder.create("failed")
.a("xmlns", "urn:xmpp:sm:3")
.element(errorCondition.toString(), StanzaError.NAMESPACE)
.element(errorCondition.toString(), StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE)
.asString(outputProperties);
StreamManagement.Failed failedPacket = ParseStreamManagement.failed(
PacketParserUtils.getParserFor(failedStanza));
assertThat(failedPacket, is(notNullValue()));
assertTrue(failedPacket.getXMPPErrorCondition() == errorCondition);
assertTrue(failedPacket.getStanzaErrorCondition() == errorCondition);
}
@Test
@ -118,7 +118,7 @@ public class ParseStreamManagementTest {
StreamManagement.Failed failed = ParseStreamManagement.failed(parser);
assertEquals(StanzaError.Condition.item_not_found, failed.getXMPPErrorCondition());
assertEquals(StanzaError.Condition.item_not_found, failed.getStanzaErrorCondition());
List<StanzaErrorTextElement> textElements = failed.getTextElements();
assertEquals(1, textElements.size());