AntiForgeryMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { protected Optional<String> sessionToken(HttpRequest request) { return ThreadingUtils.some(request, HttpRequest::getSession, s -> s.get(TOKEN_KEY), Objects::toString); }  @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> next);  }
@Test void getSessionToken() { HttpRequest request = builder(new DefaultHttpRequest()) .build(); assertThat(middleware.sessionToken(request)).isNotPresent(); Session session = new Session(); request.setSession(session); assertThat(middleware.sessionToken(request)).isNotPresent(); session.put(AntiForgeryMiddleware.class.getName() + "/antiForgeryToken", "token"); assertThat(middleware.sessionToken(request).get()).isEqualTo("token"); }