Example #1
1
  public String oneCookie(String name) {
    Cookie found = null;
    List<Cookie> allFound = null;
    for (Cookie cookie : getCookies()) {
      if (cookie.name().equals(name)) {
        if (found == null) {
          found = cookie;
        } else if (allFound == null) {
          allFound = new ArrayList<>(2);
          allFound.add(found);
        } else {
          allFound.add(cookie);
        }
      }
    }

    if (found == null) {
      return null;
    } else if (allFound != null) {
      StringBuilder s =
          new StringBuilder("Multiple cookies with name '").append(name).append("': ");
      int i = 0;
      for (Cookie cookie : allFound) {
        s.append(cookie.toString());
        if (++i < allFound.size()) {
          s.append(", ");
        }
      }

      throw new IllegalStateException(s.toString());
    } else {
      return found.value();
    }
  }
Example #2
0
 @Override
 public Collection<Cookie> getRequestCookies() {
   final List<Cookie> newCookies = new ArrayList<>();
   final Set<io.netty.handler.codec.http.cookie.Cookie> cookies = request.getCookies();
   for (final io.netty.handler.codec.http.cookie.Cookie cookie : cookies) {
     final Cookie newCookie = new Cookie(cookie.name(), cookie.value());
     newCookie.setDomain(cookie.domain());
     newCookie.setPath(cookie.path());
     newCookie.setMaxAge((int) cookie.maxAge());
     newCookie.setSecure(cookie.isSecure());
     newCookie.setHttpOnly(cookie.isHttpOnly());
     newCookies.add(newCookie);
   }
   return newCookies;
 }