mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Rework XMPP Error class design
Introduce AbstractError, change 'Conditions' to enums. Because of AbstractError, it was necessary that PlainStreamElement and TopLevelStreamElement becomes an interface. Thus the implementation of TopLevelStreamElement.toString() had to be removed. This adds - policy-violation - unexpected-request to XMPPError.Condition, and removes the - payment-required - remote-server-error - unexpected-condition - request-timeout Conditions The file transfer code does now no longer throw XMPPErrorExceptions, but SmackExceptions. Fixes SMACK-608. Makes it possible to resolves SMACK-386.
This commit is contained in:
parent
cc09192095
commit
9286a1decb
31 changed files with 582 additions and 548 deletions
|
@ -1101,7 +1101,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
break;
|
||||
case Failed.ELEMENT:
|
||||
Failed failed = ParseStreamManagement.failed(parser);
|
||||
XMPPError xmppError = failed.getXMPPError();
|
||||
XMPPError xmppError = new XMPPError(failed.getXMPPErrorCondition());
|
||||
XMPPException xmppException = new XMPPErrorException("Stream Management failed", xmppError);
|
||||
// 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
|
||||
|
|
|
@ -189,25 +189,26 @@ public class StreamManagement {
|
|||
public static class Failed extends FullStreamElement {
|
||||
public static final String ELEMENT = "failed";
|
||||
|
||||
private XMPPError error;
|
||||
private XMPPError.Condition condition;
|
||||
|
||||
public Failed() {
|
||||
}
|
||||
|
||||
public Failed(XMPPError error) {
|
||||
this.error = error;
|
||||
public Failed(XMPPError.Condition condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public XMPPError getXMPPError() {
|
||||
return error;
|
||||
public XMPPError.Condition getXMPPErrorCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
if (error != null) {
|
||||
if (condition != null) {
|
||||
xml.rightAngleBracket();
|
||||
xml.append(error.toXML());
|
||||
xml.append(condition.toString());
|
||||
xml.xmlnsAttribute(XMPPError.NAMESPACE);
|
||||
xml.closeElement(ELEMENT);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ParseStreamManagement {
|
|||
public static Failed failed(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
String name;
|
||||
String condition = "unknown";
|
||||
XMPPError.Condition condition = null;
|
||||
outerloop:
|
||||
while(true) {
|
||||
int event = parser.next();
|
||||
|
@ -53,7 +53,7 @@ public class ParseStreamManagement {
|
|||
name = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
if (XMPPError.NAMESPACE.equals(namespace)) {
|
||||
condition = name;
|
||||
condition = XMPPError.Condition.fromString(name);
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
|
@ -65,8 +65,7 @@ public class ParseStreamManagement {
|
|||
}
|
||||
}
|
||||
ParserUtils.assertAtEndTag(parser);
|
||||
XMPPError error = new XMPPError(condition);
|
||||
return new Failed(error);
|
||||
return new Failed(condition);
|
||||
}
|
||||
|
||||
public static Resumed resumed(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jivesoftware.smack.tcp.sm.provider;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.tcp.sm.packet.StreamManagement;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
@ -34,6 +35,7 @@ import static org.hamcrest.CoreMatchers.is;
|
|||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ParseStreamManagementTest {
|
||||
private static final Properties outputProperties = initOutputProperties();
|
||||
|
@ -83,19 +85,16 @@ public class ParseStreamManagementTest {
|
|||
PacketParserUtils.getParserFor(failedStanza));
|
||||
|
||||
assertThat(failedPacket, is(notNullValue()));
|
||||
XMPPError error = failedPacket.getXMPPError();
|
||||
|
||||
assertThat(error, is(notNullValue()));
|
||||
assertThat(error.getCondition(), equalTo("unknown"));
|
||||
assertTrue(failedPacket.getXMPPErrorCondition() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseFailedError() throws Exception {
|
||||
String errorCondition = "failure";
|
||||
XMPPError.Condition errorCondition = XMPPError.Condition.unexpected_request;
|
||||
|
||||
String failedStanza = XMLBuilder.create("failed")
|
||||
.a("xmlns", "urn:xmpp:sm:3")
|
||||
.element(errorCondition, XMPPError.NAMESPACE)
|
||||
.element(errorCondition.toString(), XMPPError.NAMESPACE)
|
||||
.asString(outputProperties);
|
||||
|
||||
System.err.println(failedStanza);
|
||||
|
@ -104,10 +103,7 @@ public class ParseStreamManagementTest {
|
|||
PacketParserUtils.getParserFor(failedStanza));
|
||||
|
||||
assertThat(failedPacket, is(notNullValue()));
|
||||
XMPPError error = failedPacket.getXMPPError();
|
||||
|
||||
assertThat(error, is(notNullValue()));
|
||||
assertThat(error.getCondition(), equalTo(errorCondition));
|
||||
assertTrue(failedPacket.getXMPPErrorCondition() == errorCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue