Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. @Override
  2.     protected Optional<String> get(HttpRequest httpRequest, HttpResponse httpResponse, StopWatch stopWatch) throws Exception {
  3.  
  4.         try {
  5.             return fromNullable(filter(new QueryStringDecoder(httpRequest.getUri()).getParameters().entrySet().stream()
  6.                     .collect(toMap(
  7.                             e -> {
  8.                                 if (e.getKey().length() > 1)
  9.                                     throw new IllegalArgumentException("Multiple parameter values not supported");
  10.  
  11.                                 if(parameters.contains(e.getValue().get(0).toLowerCase()))
  12.                                     return Filters.valueOf(e.getKey());
  13.                                 else
  14.                                     throw new IllegalArgumentException(format("Illegal parameter [key=%s]", e.getValue().get(0)));
  15.                             },
  16.                             e -> e.getValue().get(0)))).getContent());
  17.         } catch (IllegalArgumentException e) {
  18.             httpResponse.setStatus(HttpResponseStatus.BAD_REQUEST);
  19.             return fromNullable(e.getMessage());
  20.         } catch (Exception e) {
  21.             httpResponse.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
  22.             return fromNullable(e.getMessage());
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement