BoshBindingError.java 6.14 KB
Newer Older
1
/**
2 3 4
 * $RCSfile$
 * $Revision: 3144 $
 * $Date: 2005-12-01 14:20:11 -0300 (Thu, 01 Dec 2005) $
5
 *
6 7 8 9 10
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
11 12 13 14 15 16 17 18 19 20 21 22 23
 */
package org.jivesoftware.openfire.http;

import javax.servlet.http.HttpServletResponse;

/**
 *  An enum defining all errors which can happen during a BOSH session.
 */
public enum BoshBindingError {
    /**
     * The format of an HTTP header or binding element received from the client is unacceptable
     * (e.g., syntax error), or Script Syntax is not supported.
     */
24
    badRequest(Type.terminate, "bad-request", HttpServletResponse.SC_BAD_REQUEST),
25 26 27 28
    /**
     * The target domain specified in the 'to' attribute or the target host or port specified in the
     * 'route' attribute is no longer serviced by the connection manager.
     */
29
    hostGone(Type.terminate, "host-gone"),
30 31 32 33
    /**
     * The target domain specified in the 'to' attribute or the target host or port specified in the
     * 'route' attribute is unknown to the connection manager.
     */
34
    hostUnknown(Type.terminate, "host-unknown"),
35 36 37 38
    /**
     * The initialization element lacks a 'to' or 'route' attribute (or the attribute has no value)
     * but the connection manager requires one.
     */
39
    improperAddressing(Type.terminate, "improper-addressing"),
40 41 42 43
    /**
     * The connection manager has experienced an internal error that prevents it from servicing the
     * request.
     */
44
    internalServerError(Type.terminate, "internal-server-error"),
45 46 47
    /**
     * (1) 'sid' is not valid, (2) 'stream' is not valid, (3) 'rid' is larger than the upper limit
     * of the expected window, (4) connection manager is unable to resend response, (5) 'key'
48
     * sequence is invalid (6) script syntax is not enabled
49
     */
50
    itemNotFound(Type.terminate, "item-not-found", HttpServletResponse.SC_NOT_FOUND),
51 52 53 54
    /**
     * Another request being processed at the same time as this request caused the session to
     * terminate.
     */
55
    otherRequest(Type.terminate, "other-request"),
56 57 58 59
    /**
     * The client has broken the session rules (polling too frequently, requesting too frequently,
     * too many simultaneous requests).
     */
60
    policyViolation(Type.terminate, "policy-violation",
61 62 63 64 65
            HttpServletResponse.SC_FORBIDDEN),
    /**
     * The connection manager was unable to connect to, or unable to connect securely to, or has
     * lost its connection to, the server.
     */
66
    remoteConnectionFailed(Type.terminate, "remote-connection-failed"),
67 68 69
    /**
     * Encapsulates an error in the protocol being transported.
     */
70
    remoteStreamError(Type.terminate, "remote-stream-error"),
71 72 73 74 75 76
    /**
     * The connection manager does not operate at this URI (e.g., the connection manager accepts
     * only SSL or TLS connections at some https: URI rather than the http: URI requested by the
     * client). The client may try POSTing to the URI in the content of the <uri/> child
     * element.
     */
77
    seeOtherUri(Type.terminate, "see-other-uri"),
78 79 80 81
    /**
     * The connection manager is being shut down. All active HTTP sessions are being terminated. No
     * new sessions can be created.
     */
82
    systemShutdown(Type.terminate, "system-shutdown"),
83 84 85 86
    /**
     * The error is not one of those defined herein; the connection manager SHOULD include
     * application-specific information in the content of the <body> wrapper.
     */
87
    undefinedCondition(Type.terminate, "undefined-condition");
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

    private Type errorType;
    private String condition;
    private int legacyErrorCode = HttpServletResponse.SC_BAD_REQUEST;

    BoshBindingError(Type errorType, String condition, int legacyErrorCode) {
        this(errorType, condition);
        this.legacyErrorCode = legacyErrorCode;
    }

    BoshBindingError(Type errorType, String condition) {
        this.errorType = errorType;
        this.condition = condition;
    }

    public Type getErrorType() {
        return errorType;
    }

    /**
     * Returns the condition that caused the binding error. This should be returned to the client
     * so that the client can take appropriate action.
     *
     * @return the condition that caused the binding error.
     */
    public String getCondition() {
        return condition;
    }

    /**
     * Returns the legacy HTTP error code which is related to the binding error. With the 1.6
     * version of BOSH the use of HTTP errors was deprecated in favor of using errors inside of the
     * response to the client so that they could be more easily processed on the client side.
     *
     * @return the legacy HTTP error code which is related to the binding error.
     */
    public int getLegacyErrorCode() {
        return legacyErrorCode;
    }

    public enum Type {
        /**
130
         * The terminate error condition prevents the client from making any further requests until a
131 132
         * new session is established.
         */
133
        terminate(null),
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
        /**
         * In the case of a recoverable binding error the client MUST repeat the HTTP request and
         * all the preceding HTTP requests that have not received responses. The content of these
         * requests MUST be identical to the <body> elements of the original requests. This
         * allows the connection manager to recover a session after the previous request was lost
         * due to a communication failure.
         */
        recoverable("error");
        private String type;

        Type(String type) {
            this.type = type;
        }

        /**
         * Returns the type that will be displayed to the client.
         *
         * @return the type that will be displayed to the client.
         */
        public String getType() {
            if (type == null) {
                return name();
            }
            else {
                return type;
            }
        }
    }
}