@Override public String getClientAddress() { return original.getClientAddress(); }
@Override public String getClientAddress() { return original.getClientAddress(); }
/** * Prepares the metadata to be used for session stats monitoring. * * If you override this method, make sure to include the map built by the default implementation if you want * the monitor admin session view to work properly, unless you override it too. * * @param req the request for which metadata should be prepared * @param session the session for which metadata should be prepared * @return the prepared metadata */ protected ImmutableMap<String, String> prepareSessionStatsMetadata(RestxRequest req, RestxSession session) { return ImmutableMap.of( "clientAddress", req.getClientAddress(), "userAgent", req.getHeader("User-Agent").or("Unknown")); } }
/** * Prepares the metadata to be used for session stats monitoring. * * If you override this method, make sure to include the map built by the default implementation if you want * the monitor admin session view to work properly, unless you override it too. * * @param req the request for which metadata should be prepared * @param session the session for which metadata should be prepared * @return the prepared metadata */ protected ImmutableMap<String, String> prepareSessionStatsMetadata(RestxRequest req, RestxSession session) { return ImmutableMap.of( "clientAddress", req.getClientAddress(), "userAgent", req.getHeader("User-Agent").or("Unknown")); } }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { RestxSession session = RestxSession.current(); ImmutableMap<String, String> metadata = prepareSessionStatsMetadata(req, session); if (session.getPrincipal().isPresent()) { String name = session.getPrincipal().get().getName(); sessions.touch(name, metadata); MDC.put("principal", name); } else { sessions.touch("anonymous@" + req.getClientAddress(), metadata); } ctx.nextHandlerMatch().handle(req, resp, ctx); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { RestxSession session = RestxSession.current(); ImmutableMap<String, String> metadata = prepareSessionStatsMetadata(req, session); if (session.getPrincipal().isPresent()) { String name = session.getPrincipal().get().getName(); sessions.touch(name, metadata); MDC.put("principal", name); } else { sessions.touch("anonymous@" + req.getClientAddress(), metadata); } ctx.nextHandlerMatch().handle(req, resp, ctx); }