diff --git a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index c29548797..8137860b6 100644 --- a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -24,50 +24,48 @@ import java.util.Map; /** * Represents a XMPP error sub-packet. Typically, a server responds to a request that has - * problems by sending the packet back and including an error packet. Each error has a code, type, + * problems by sending the packet back and including an error packet. Each error has a type, * error condition as well as as an optional text explanation. Typical errors are:

* * - *
- * - * - * > - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * *
CodeXMPP ErrorType
500internal-server-errorWAIT
403forbiddenAUTH
400bad-requestMODIFY
404item-not-foundCANCEL
409conflictCANCEL
501feature-not-implementedCANCEL
302goneMODIFY
400jid-malformedMODIFY
406no-acceptable MODIFY
405not-allowedCANCEL
401not-authorizedAUTH
402payment-requiredAUTH
404recipient-unavailableWAIT
302redirectMODIFY
407registration-requiredAUTH
404remote-server-not-foundCANCEL
504remote-server-timeoutWAIT
502remote-server-errorCANCEL
500resource-constraintWAIT
503service-unavailableCANCEL
407subscription-requiredAUTH
500undefined-conditionWAIT
400unexpected-conditionWAIT
408request-timeoutCANCEL
XMPP ErrorType
internal-server-errorWAIT
forbiddenAUTH
bad-requestMODIFY
item-not-foundCANCEL
conflictCANCEL
feature-not-implementedCANCEL
goneMODIFY
jid-malformedMODIFY
no-acceptable MODIFY
not-allowedCANCEL
not-authorizedAUTH
payment-requiredAUTH
recipient-unavailableWAIT
redirectMODIFY
registration-requiredAUTH
remote-server-not-foundCANCEL
remote-server-timeoutWAIT
remote-server-errorCANCEL
resource-constraintWAIT
service-unavailableCANCEL
subscription-requiredAUTH
undefined-conditionWAIT
unexpected-conditionWAIT
request-timeoutCANCEL
* * @author Matt Tucker */ public class XMPPError { - private int code; - private Type type; - private String condition; + private final Type type; + private final String condition; private String message; private List applicationExtensions = null; - /** - * Creates a new error with the specified condition infering the type and code. + * Creates a new error with the specified condition inferring the type. * If the Condition is predefined, client code should be like: * new XMPPError(XMPPError.Condition.remote_server_timeout); * If the Condition is not predefined, invocations should be like @@ -76,12 +74,20 @@ public class XMPPError { * @param condition the error condition. */ public XMPPError(Condition condition) { - this.init(condition); - this.message = null; + // Look for the condition and its default type + ErrorSpecification defaultErrorSpecification = ErrorSpecification.specFor(condition); + this.condition = condition.value; + if (defaultErrorSpecification != null) { + // If there is a default error specification for the received condition, + // it get configured with the inferred type. + type = defaultErrorSpecification.getType(); + } else { + type = null; + } } /** - * Creates a new error with the specified condition and message infering the type and code. + * Creates a new error with the specified condition and message infering the type. * If the Condition is predefined, client code should be like: * new XMPPError(XMPPError.Condition.remote_server_timeout, "Error Explanation"); * If the Condition is not predefined, invocations should be like @@ -91,71 +97,29 @@ public class XMPPError { * @param messageText a message describing the error. */ public XMPPError(Condition condition, String messageText) { - this.init(condition); + this(condition); this.message = messageText; } /** - * Creates a new error with the specified code and no message. - * - * @param code the error code. - * @deprecated new errors should be created using the constructor XMPPError(condition) - */ - public XMPPError(int code) { - this.code = code; - this.message = null; - } - - /** - * Creates a new error with the specified code and message. - * deprecated - * - * @param code the error code. - * @param message a message describing the error. - * @deprecated new errors should be created using the constructor XMPPError(condition, message) - */ - public XMPPError(int code, String message) { - this.code = code; - this.message = message; - } - - /** - * Creates a new error with the specified code, type, condition and message. + * Creates a new error with the specified type, condition and message. * This constructor is used when the condition is not recognized automatically by XMPPError - * i.e. there is not a defined instance of ErrorCondition or it does not applies the default + * i.e. there is not a defined instance of ErrorCondition or it does not apply the default * specification. * - * @param code the error code. * @param type the error type. * @param condition the error condition. * @param message a message describing the error. * @param extension list of packet extensions */ - public XMPPError(int code, Type type, String condition, String message, + public XMPPError(Type type, String condition, String message, List extension) { - this.code = code; this.type = type; this.condition = condition; this.message = message; this.applicationExtensions = extension; } - /** - * Initialize the error infering the type and code for the received condition. - * - * @param condition the error condition. - */ - private void init(Condition condition) { - // Look for the condition and its default code and type - ErrorSpecification defaultErrorSpecification = ErrorSpecification.specFor(condition); - this.condition = condition.value; - if (defaultErrorSpecification != null) { - // If there is a default error specification for the received condition, - // it get configured with the infered type and code. - this.type = defaultErrorSpecification.getType(); - this.code = defaultErrorSpecification.getCode(); - } - } /** * Returns the error condition. * @@ -174,15 +138,6 @@ public class XMPPError { return type; } - /** - * Returns the error code. - * - * @return the error code. - */ - public int getCode() { - return code; - } - /** * Returns the message describing the error, or null if there is no message. * @@ -199,10 +154,10 @@ public class XMPPError { */ public String toXML() { StringBuilder buf = new StringBuilder(); - buf.append(""); @@ -227,7 +182,6 @@ public class XMPPError { if (condition != null) { txt.append(condition); } - txt.append("(").append(code).append(")"); if (message != null) { txt.append(" ").append(message); } @@ -249,7 +203,7 @@ public class XMPPError { } /** - * Returns the first patcket extension that matches the specified element name and + * Returns the first packet extension that matches the specified element name and * namespace, or null if it doesn't exist. * * @param elementName the XML element name of the packet extension. @@ -356,66 +310,64 @@ public class XMPPError { private static class ErrorSpecification { private static Map instances = new HashMap(); - private final int code; private final Type type; @SuppressWarnings("unused") private final Condition condition; - private ErrorSpecification(Condition condition, Type type, int code) { - this.code = code; + private ErrorSpecification(Condition condition, Type type) { this.type = type; this.condition = condition; } static { instances.put(Condition.internal_server_error, new ErrorSpecification( - Condition.internal_server_error, Type.WAIT, 500)); + Condition.internal_server_error, Type.WAIT)); instances.put(Condition.forbidden, new ErrorSpecification(Condition.forbidden, - Type.AUTH, 403)); + Type.AUTH)); instances.put(Condition.bad_request, new XMPPError.ErrorSpecification( - Condition.bad_request, Type.MODIFY, 400)); + Condition.bad_request, Type.MODIFY)); instances.put(Condition.item_not_found, new XMPPError.ErrorSpecification( - Condition.item_not_found, Type.CANCEL, 404)); + Condition.item_not_found, Type.CANCEL)); instances.put(Condition.conflict, new XMPPError.ErrorSpecification( - Condition.conflict, Type.CANCEL, 409)); + Condition.conflict, Type.CANCEL)); instances.put(Condition.feature_not_implemented, new XMPPError.ErrorSpecification( - Condition.feature_not_implemented, Type.CANCEL, 501)); + Condition.feature_not_implemented, Type.CANCEL)); instances.put(Condition.gone, new XMPPError.ErrorSpecification( - Condition.gone, Type.MODIFY, 302)); + Condition.gone, Type.MODIFY)); instances.put(Condition.jid_malformed, new XMPPError.ErrorSpecification( - Condition.jid_malformed, Type.MODIFY, 400)); + Condition.jid_malformed, Type.MODIFY)); instances.put(Condition.no_acceptable, new XMPPError.ErrorSpecification( - Condition.no_acceptable, Type.MODIFY, 406)); + Condition.no_acceptable, Type.MODIFY)); instances.put(Condition.not_allowed, new XMPPError.ErrorSpecification( - Condition.not_allowed, Type.CANCEL, 405)); + Condition.not_allowed, Type.CANCEL)); instances.put(Condition.not_authorized, new XMPPError.ErrorSpecification( - Condition.not_authorized, Type.AUTH, 401)); + Condition.not_authorized, Type.AUTH)); instances.put(Condition.payment_required, new XMPPError.ErrorSpecification( - Condition.payment_required, Type.AUTH, 402)); + Condition.payment_required, Type.AUTH)); instances.put(Condition.recipient_unavailable, new XMPPError.ErrorSpecification( - Condition.recipient_unavailable, Type.WAIT, 404)); + Condition.recipient_unavailable, Type.WAIT)); instances.put(Condition.redirect, new XMPPError.ErrorSpecification( - Condition.redirect, Type.MODIFY, 302)); + Condition.redirect, Type.MODIFY)); instances.put(Condition.registration_required, new XMPPError.ErrorSpecification( - Condition.registration_required, Type.AUTH, 407)); + Condition.registration_required, Type.AUTH)); instances.put(Condition.remote_server_not_found, new XMPPError.ErrorSpecification( - Condition.remote_server_not_found, Type.CANCEL, 404)); + Condition.remote_server_not_found, Type.CANCEL)); instances.put(Condition.remote_server_timeout, new XMPPError.ErrorSpecification( - Condition.remote_server_timeout, Type.WAIT, 504)); + Condition.remote_server_timeout, Type.WAIT)); instances.put(Condition.remote_server_error, new XMPPError.ErrorSpecification( - Condition.remote_server_error, Type.CANCEL, 502)); + Condition.remote_server_error, Type.CANCEL)); instances.put(Condition.resource_constraint, new XMPPError.ErrorSpecification( - Condition.resource_constraint, Type.WAIT, 500)); + Condition.resource_constraint, Type.WAIT)); instances.put(Condition.service_unavailable, new XMPPError.ErrorSpecification( - Condition.service_unavailable, Type.CANCEL, 503)); + Condition.service_unavailable, Type.CANCEL)); instances.put(Condition.subscription_required, new XMPPError.ErrorSpecification( - Condition.subscription_required, Type.AUTH, 407)); + Condition.subscription_required, Type.AUTH)); instances.put(Condition.undefined_condition, new XMPPError.ErrorSpecification( - Condition.undefined_condition, Type.WAIT, 500)); + Condition.undefined_condition, Type.WAIT)); instances.put(Condition.unexpected_request, new XMPPError.ErrorSpecification( - Condition.unexpected_request, Type.WAIT, 400)); + Condition.unexpected_request, Type.WAIT)); instances.put(Condition.request_timeout, new XMPPError.ErrorSpecification( - Condition.request_timeout, Type.CANCEL, 408)); + Condition.request_timeout, Type.CANCEL)); } protected static ErrorSpecification specFor(Condition condition) { @@ -430,14 +382,5 @@ public class XMPPError { protected Type getType() { return type; } - - /** - * Returns the error code. - * - * @return the error code. - */ - protected int getCode() { - return code; - } } } diff --git a/core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index 6530d00bd..78dee5ddc 100644 --- a/core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -703,7 +703,6 @@ public class PacketParserUtils { */ public static XMPPError parseError(XmlPullParser parser) throws Exception { final String errorNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas"; - String errorCode = "-1"; String type = null; String message = null; String condition = null; @@ -711,9 +710,6 @@ public class PacketParserUtils { // Parse the error header for (int i=0; i extList = new ArrayList(); extList.add(jingleError); - XMPPError error = new XMPPError(0, XMPPError.Type.CANCEL, jingleError.toString(), "", extList); + XMPPError error = new XMPPError(XMPPError.Type.CANCEL, jingleError.toString(), "", extList); // Fill in the fields with the info from the Jingle packet errorPacket.setPacketID(iq.getPacketID());