1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.guacamole.protocol; 21 22 /** 23 * All possible statuses returned by various Guacamole instructions, each having 24 * a corresponding code. 25 */ 26 public enum GuacamoleStatus { 27 28 /** 29 * The operation succeeded. 30 */ 31 SUCCESS(200, 1000, 0x0000), 32 33 /** 34 * The requested operation is unsupported. 35 */ 36 UNSUPPORTED(501, 1011, 0x0100), 37 38 /** 39 * The operation could not be performed due to an internal failure. 40 */ 41 SERVER_ERROR(500, 1011, 0x0200), 42 43 /** 44 * The operation could not be performed as the server is busy. 45 */ 46 SERVER_BUSY(503, 1008, 0x0201), 47 48 /** 49 * The operation could not be performed because the upstream server is not 50 * responding. 51 */ 52 UPSTREAM_TIMEOUT(504, 1011, 0x0202), 53 54 /** 55 * The operation was unsuccessful due to an error or otherwise unexpected 56 * condition of the upstream server. 57 */ 58 UPSTREAM_ERROR(502, 1011, 0x0203), 59 60 /** 61 * The operation could not be performed as the requested resource does not 62 * exist. 63 */ 64 RESOURCE_NOT_FOUND(404, 1002, 0x0204), 65 66 /** 67 * The operation could not be performed as the requested resource is already 68 * in use. 69 */ 70 RESOURCE_CONFLICT(409, 1008, 0x0205), 71 72 /** 73 * The operation could not be performed as the requested resource is now 74 * closed. 75 */ 76 RESOURCE_CLOSED(404, 1002, 0x0206), 77 78 /** 79 * The operation could not be performed because the upstream server does 80 * not appear to exist. 81 */ 82 UPSTREAM_NOT_FOUND(502, 1011, 0x0207), 83 84 /** 85 * The operation could not be performed because the upstream server is not 86 * available to service the request. 87 */ 88 UPSTREAM_UNAVAILABLE(502, 1011, 0x0208), 89 90 /** 91 * The session within the upstream server has ended because it conflicted 92 * with another session. 93 */ 94 SESSION_CONFLICT(409, 1008, 0x0209), 95 96 /** 97 * The session within the upstream server has ended because it appeared to 98 * be inactive. 99 */ 100 SESSION_TIMEOUT(408, 1002, 0x020A), 101 102 /** 103 * The session within the upstream server has been forcibly terminated. 104 */ 105 SESSION_CLOSED(404, 1002, 0x020B), 106 107 /** 108 * The operation could not be performed because bad parameters were given. 109 */ 110 CLIENT_BAD_REQUEST(400, 1002, 0x0300), 111 112 /** 113 * Permission was denied to perform the operation, as the user is not yet 114 * authorized (not yet logged in, for example). As HTTP 401 has implications 115 * for HTTP-specific authorization schemes, this status continues to map to 116 * HTTP 403 ("Forbidden"). To do otherwise would risk unintended effects. 117 */ 118 CLIENT_UNAUTHORIZED(403, 1008, 0x0301), 119 120 /** 121 * Permission was denied to perform the operation, and this operation will 122 * not be granted even if the user is authorized. 123 */ 124 CLIENT_FORBIDDEN(403, 1008, 0x0303), 125 126 /** 127 * The client took too long to respond. 128 */ 129 CLIENT_TIMEOUT(408, 1002, 0x0308), 130 131 /** 132 * The client sent too much data. 133 */ 134 CLIENT_OVERRUN(413, 1009, 0x030D), 135 136 /** 137 * The client sent data of an unsupported or unexpected type. 138 */ 139 CLIENT_BAD_TYPE(415, 1003, 0x030F), 140 141 /** 142 * The operation failed because the current client is already using too 143 * many resources. 144 */ 145 CLIENT_TOO_MANY(429, 1008, 0x031D); 146 147 /** 148 * The most applicable HTTP error code. 149 */ 150 private final int http_code; 151 152 /** 153 * The most applicable WebSocket error code. 154 */ 155 private final int websocket_code; 156 157 /** 158 * The Guacamole protocol status code. 159 */ 160 private final int guac_code; 161 162 /** 163 * Initializes a GuacamoleStatusCode with the given HTTP and Guacamole 164 * status/error code values. 165 * 166 * @param http_code The most applicable HTTP error code. 167 * @param websocket_code The most applicable WebSocket error code. 168 * @param guac_code The Guacamole protocol status code. 169 */ GuacamoleStatus(int http_code, int websocket_code, int guac_code)170 private GuacamoleStatus(int http_code, int websocket_code, int guac_code) { 171 this.http_code = http_code; 172 this.websocket_code = websocket_code; 173 this.guac_code = guac_code; 174 } 175 176 /** 177 * Returns the most applicable HTTP error code. 178 * 179 * @return The most applicable HTTP error code. 180 */ getHttpStatusCode()181 public int getHttpStatusCode() { 182 return http_code; 183 } 184 185 /** 186 * Returns the most applicable HTTP error code. 187 * 188 * @return The most applicable HTTP error code. 189 */ getWebSocketCode()190 public int getWebSocketCode() { 191 return websocket_code; 192 } 193 194 /** 195 * Returns the corresponding Guacamole protocol status code. 196 * 197 * @return The corresponding Guacamole protocol status code. 198 */ getGuacamoleStatusCode()199 public int getGuacamoleStatusCode() { 200 return guac_code; 201 } 202 203 /** 204 * Returns the GuacamoleStatus corresponding to the given Guacamole 205 * protocol status code. If no such GuacamoleStatus is defined, null is 206 * returned. 207 * 208 * @param code 209 * The Guacamole protocol status code to translate into a 210 * GuacamoleStatus. 211 * 212 * @return 213 * The GuacamoleStatus corresponding to the given Guacamole protocol 214 * status code, or null if no such GuacamoleStatus is defined. 215 */ fromGuacamoleStatusCode(int code)216 public static GuacamoleStatus fromGuacamoleStatusCode(int code) { 217 218 // Search for a GuacamoleStatus having the given status code 219 for (GuacamoleStatus status : values()) { 220 if (status.getGuacamoleStatusCode() == code) 221 return status; 222 } 223 224 // No such status found 225 return null; 226 227 } 228 229 } 230