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:
*
*
- *
Code | XMPP Error | Type |
- * 500 | internal-server-error | WAIT |
- * 403 | forbidden | AUTH |
- * 400 | bad-requestMODIFY | >
- * 404 | item-not-found | CANCEL |
- * 409 | conflict | CANCEL |
- * 501 | feature-not-implemented | CANCEL |
- * 302 | gone | MODIFY |
- * 400 | jid-malformed | MODIFY |
- * 406 | no-acceptable | MODIFY |
- * 405 | not-allowed | CANCEL |
- * 401 | not-authorized | AUTH |
- * 402 | payment-required | AUTH |
- * 404 | recipient-unavailable | WAIT |
- * 302 | redirect | MODIFY |
- * 407 | registration-required | AUTH |
- * 404 | remote-server-not-found | CANCEL |
- * 504 | remote-server-timeout | WAIT |
- * 502 | remote-server-error | CANCEL |
- * 500 | resource-constraint | WAIT |
- * 503 | service-unavailable | CANCEL |
- * 407 | subscription-required | AUTH |
- * 500 | undefined-condition | WAIT |
- * 400 | unexpected-condition | WAIT |
- * 408 | request-timeout | CANCEL |
+ *
XMPP Error | Type |
+ * internal-server-error | WAIT |
+ * forbidden | AUTH |
+ * bad-request | MODIFY |
+ * item-not-found | CANCEL |
+ * conflict | CANCEL |
+ * feature-not-implemented | CANCEL |
+ * gone | MODIFY |
+ * jid-malformed | MODIFY |
+ * no-acceptable | MODIFY |
+ * not-allowed | CANCEL |
+ * not-authorized | AUTH |
+ * payment-required | AUTH |
+ * recipient-unavailable | WAIT |
+ * redirect | MODIFY |
+ * registration-required | AUTH |
+ * remote-server-not-found | CANCEL |
+ * remote-server-timeout | WAIT |
+ * remote-server-error | CANCEL |
+ * resource-constraint | WAIT |
+ * service-unavailable | CANCEL |
+ * subscription-required | AUTH |
+ * undefined-condition | WAIT |
+ * unexpected-condition | WAIT |
+ * request-timeout | CANCEL |
*
*
* @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());