@Override public void setSessionAttribute(final String name, final Object value) { Session session = req.session(); if (value == null) { session.unset(name); } else { session.set(name, objToStr(value)); } }
@Override public Collection<Cookie> getRequestCookies() { return req.cookies() .stream() .map( c -> { Cookie cookie = new Cookie(c.name(), c.value().orElse(null)); c.domain().ifPresent(cookie::setDomain); c.path().ifPresent(cookie::setPath); cookie.setHttpOnly(c.httpOnly()); cookie.setSecure(c.secure()); return cookie; }) .collect(Collectors.toList()); }
private Map<String, String[]> params(final Request req) { ImmutableMap.Builder<String, String[]> result = ImmutableMap.<String, String[]>builder(); req.params() .toMap() .forEach( (name, value) -> { try { List<String> values = value.toList(); result.put(name, values.toArray(new String[values.size()])); } catch (Err ignored) { log.debug("ignoring HTTP param: " + name, ignored); } }); return result.build(); }
@Override public String getRequestMethod() { return req.method(); }
@Override public Object getSessionAttribute(final String name) { Session session = req.session(); return strToObject(session.get(name).value(null)); }
@Override public String getRequestHeader(final String name) { return req.header(name).value(null); }
@Override public String getRemoteAddr() { return req.ip(); }
@Override public Object getSessionIdentifier() { return req.session().id(); }
@Override public void setRequestAttribute(final String name, final Object value) { req.set(name, value); }
@Override public Object getRequestAttribute(final String name) { Optional<Object> attr = req.get(name); return attr.orElse(null); }
@Override public String toString() { return req.toString(); }
@Override public String getFullRequestURL() { return getScheme() + "://" + getServerName() + ":" + getServerPort() + req.path(); }
@Override public String getScheme() { return req.secure() ? "https" : "http"; }
@Override public int getServerPort() { return req.port(); }
@Override public String getServerName() { return req.hostname(); }