[Hard] AccessLogFilter.java: set RequestBody null, handle it later & should record "clien
Source
- File:
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java - References: L45-L46, L149-L150
I have enough information to answer the question. Let me analyze the TODO/FIXME comment and explain the two issues it describes.
The TODO is at line 150 in AccessLogFilter.java:
// TODO: set RequestBody null, handle it later & should record "client IP"
LOG.info("[Slow Query] execTime={}ms, body={}, method={}, path={}, query={}",
executeTime, null, method, path, uri.getQuery());
There are two distinct issues here:
-
body={}is hardcoded asnull: The log statement passesnullas thebodyargument. The TODO says "set RequestBody null, handle it later" — meaning the actual request body content is not being read and logged. For slow query diagnostics, you'd want to know what query/body was sent. The challenge is thatAccessLogFilteris aContainerResponseFilter, meaning it runs after the request body has already been consumed by the resource method. Reading theInputStreamfromrequestContext.getEntityStream()at this point would return an empty stream (already consumed). To fix this, aContainerRequestFilterwould need to cache the body (e.g., store it as a request property), and thenAccessLogFiltercould read it from the property. -
Client IP is not logged: The log format string doesn't include a client IP field at all. The TODO says "should record 'client IP'". Looking at
AuthenticationFilter, it usesrequestProvider.get().getRemoteAddr()(a GrizzlyRequest) to get the client IP.AccessLogFilterdoesn't inject the GrizzlyRequestprovider, so it has no way to get the client IP currently.
Files affected:
AccessLogFilter.java— the primary file needing changes (log format, body reading, IP extraction)- Potentially
PathFilter.java— if the body needs to be cached in the request filter phase (PathFilter is aContainerRequestFilterthat already setsREQUEST_TIMEas a property), it could also cache the body. Or a new request filter could be added. - Possibly a new filter class if body caching is done separately.
So the minimum files affected would be:
AccessLogFilter.java— add client IP to log, injectRequestproviderPathFilter.java— optionally cache the request body as a property (or this could be done inAccessLogFilteritself if it also implementsContainerRequestFilter)
Actually, looking more carefully: AccessLogFilter is only a ContainerResponseFilter. To read the body, it would need to either:
- Also implement
ContainerRequestFilter(and cache the body in a request property) - Or rely on another filter (like
PathFilter) to cache the body
The most likely minimal change is:
AccessLogFilter.java— addContainerRequestFilterimplementation to cache body, add IP to log- That's potentially just 1 file if
AccessLogFilteris extended to also be a request filter
But realistically, since body caching requires wrapping the InputStream (to allow re-reading), it might need a helper class too.
Let me give a clear, concise answer.
There are two distinct problems captured in that single TODO comment at line 150:
The TODO in context
// TODO: set RequestBody null, handle it later & should record "client IP"
LOG.info("[Slow Query] execTime={}ms, body={}, method={}, path={}, query={}",
executeTime, null, method, path, uri.getQuery());
Problem 1: Request body is always null
The second argument to LOG.info(...) is hardcoded as null. The intent is to log the actual request body (e.g., the Gremlin query string) for slow query diagnostics, but it is deferred with "handle it later."
The root cause is architectural: AccessLogFilter implements only ContainerResponseFilter, meaning it runs after the request body InputStream has already been fully consumed by the resource method. Calling requestContext.getEntityStream() at this point returns an empty stream.
To fix this, the body must be cached during the request phase — either by:
- Making
AccessLogFilteralso implementContainerRequestFilterand wrapping/caching theInputStreaminto a request property, or - Having
PathFilter(which already runs as aContainerRequestFilterand setsREQUEST_TIME) also cache the body as a property.
PathFilter already sets a property constant REQUEST_PARAMS_JSON (line 53), which suggests this caching was planned but not implemented:
Problem 2: Client IP is not logged at all
The log format string has no ip field. The TODO says it "should record client IP," but AccessLogFilter has no mechanism to retrieve it — it doesn't inject the Grizzly Request object.
Compare with AuthenticationFilter, which does inject the Grizzly Request and reads the remote address:
@Context
private jakarta.inject.Provider<Request> requestProvider;
...
peer = request.getRemoteAddr() + ":" + request.getRemotePort();
AccessLogFilter would need the same @Context injection of jakarta.inject.Provider<Request> to extract remoteAddr.
Files affected
The fix is self-contained to the filter package. Minimum files:
| File | Change needed |
|---|---|
AccessLogFilter.java |
Inject Grizzly Request, add IP to log format, read cached body from request property |
PathFilter.java |
Cache the request body into a request property (using REQUEST_PARAMS_JSON) during the request phase |
That's 2 files. If body-caching logic is complex enough to warrant a dedicated wrapper class (e.g., a CachedBodyInputStream), a 3rd new file could be added, but it is not strictly required.
Closing — this was created during testing of a contributor task mining script and was unintentionally pointed at the main repo. Apologies for the noise.