Sets the local serializer based on a query string parameter or content type. If the caller supplies a "serializer=" parameter, the proper serializer is loaded if found. If the serializer doesn't exist, an exception will be thrown and the user gets an error If no query string parameter is sup
()
| 304 | * not exist |
| 305 | */ |
| 306 | public void setSerializer() throws InvocationTargetException, |
| 307 | IllegalArgumentException, InstantiationException, IllegalAccessException { |
| 308 | if (this.hasQueryStringParam("serializer")) { |
| 309 | final String qs = this.getQueryStringParam("serializer"); |
| 310 | Constructor<? extends HttpSerializer> ctor = |
| 311 | serializer_map_query_string.get(qs); |
| 312 | if (ctor == null) { |
| 313 | this.serializer = new HttpJsonSerializer(this); |
| 314 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 315 | "Requested serializer was not found", |
| 316 | "Could not find a serializer with the name: " + qs); |
| 317 | } |
| 318 | |
| 319 | this.serializer = ctor.newInstance(this); |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | // attempt to parse the Content-Type string. We only want the first part, |
| 324 | // not the character set. And if the CT is missing, we'll use the default |
| 325 | // serializer |
| 326 | String content_type = request().headers().get("Content-Type"); |
| 327 | if (content_type == null || content_type.isEmpty()) { |
| 328 | return; |
| 329 | } |
| 330 | if (content_type.indexOf(";") > -1) { |
| 331 | content_type = content_type.substring(0, content_type.indexOf(";")); |
| 332 | } |
| 333 | Constructor<? extends HttpSerializer> ctor = |
| 334 | serializer_map_content_type.get(content_type); |
| 335 | if (ctor == null) { |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | this.serializer = ctor.newInstance(this); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Sends a 500 error page to the client. |