This method splits the query path component and returns a string suitable for routing by RpcHandler. The resulting route is always lower case and will consist of either an empty string, a deprecated API call or an API route. API routes will set the #apiVersion to either a user provid
()
| 204 | * @since 2.0 |
| 205 | */ |
| 206 | @Override |
| 207 | public String getQueryBaseRoute() { |
| 208 | final String[] split = explodePath(); |
| 209 | if (split.length < 1) { |
| 210 | return ""; |
| 211 | } |
| 212 | if (!split[0].toLowerCase().equals("api")) { |
| 213 | return split[0].toLowerCase(); |
| 214 | } |
| 215 | // set the default api_version so the API call is handled by a serializer if |
| 216 | // an exception is thrown |
| 217 | this.api_version = MAX_API_VERSION; |
| 218 | if (split.length < 2) { |
| 219 | return "api"; |
| 220 | } |
| 221 | if (split[1].toLowerCase().startsWith("v") && split[1].length() > 1 && |
| 222 | Character.isDigit(split[1].charAt(1))) { |
| 223 | try { |
| 224 | final int version = Integer.parseInt(split[1].substring(1)); |
| 225 | if (version > MAX_API_VERSION) { |
| 226 | throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, |
| 227 | "Requested API version is greater than the max implemented", |
| 228 | "API version [" + version + "] is greater than the max [" + |
| 229 | MAX_API_VERSION + "]"); |
| 230 | } |
| 231 | this.api_version = version; |
| 232 | } catch (NumberFormatException nfe) { |
| 233 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 234 | "Invalid API version format supplied", |
| 235 | "API version [" + split[1].substring(1) + |
| 236 | "] cannot be parsed to an integer"); |
| 237 | } |
| 238 | } else { |
| 239 | return "api/" + split[1].toLowerCase(); |
| 240 | } |
| 241 | if (split.length < 3){ |
| 242 | return "api"; |
| 243 | } |
| 244 | return "api/" + split[2].toLowerCase(); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Determines the requested HttpMethod via VERB and QS override. |