Skip to content

feat: JSON-LD context caching and HTTP access logging#46

Open
Mortega5 wants to merge 6 commits into
mainfrom
fix/json-handler
Open

feat: JSON-LD context caching and HTTP access logging#46
Mortega5 wants to merge 6 commits into
mainfrom
fix/json-handler

Conversation

@Mortega5
Copy link
Copy Markdown
Collaborator

Improvements to JSON-LD context resolution and server observability:

  • Local ODRL context: Bundled the W3C ODRL JSON-LD context as a static resource to avoid external calls and rate limiting issues.
  • In-memory cache with Caffeine: Remote JSON-LD context lookups are cached to reduce latency and external dependencies.
  • Robust HTTP client: Added timeouts and proper connection cleanup to the JSON-LD HTTP client.
  • Access logging: Logs incoming and outgoing HTTP requests to aid diagnostics.

Mortega5 added 4 commits May 19, 2026 13:32
Without a timeout, fetching external JSON-LD contexts (e.g. w3.org)
could block indefinitely, causing EDC transfer provisioning to fail
with a socket timeout. The empty close() also leaked connections from
the pool after each request.

- Add configurable timeout to the Apache HTTP client (default 10s)
  via http-client.timeout-ms property
- Implement close() in JsonLdHttpResponse to release connections
Introduces a composite document loader pattern to intercept known
JSON-LD context URLs and serve them from classpath resources instead
of hitting the W3C servers on every policy evaluation. The loader
chain (LocalContextRepository → HTTP fallback) is produced as a
singleton bean to avoid recreating it on each request.
Adds a CachingContextRepository that wraps HTTP fetches with a
Caffeine cache (configurable TTL via jsonld-cache.ttl-seconds).
Logs distinguish local classpath hits, cache hits, and HTTP fetches.
The httpFallback in CompositeDocumentLoader is removed — the cache
layer is now the last and exhaustive resolver in the chain.
Adds ContainerRequestFilter/ContainerResponseFilter for inbound
requests (remote IP, X-Forwarded-For, protocol, method, path, status,
duration) and ClientRequestFilter/ClientResponseFilter for outbound
REST client calls. Configurable exclude-paths for server log.
OPA REST client registered with the outgoing filter via providers config.
@Mortega5 Mortega5 requested a review from wistefan May 19, 2026 12:24
@Mortega5 Mortega5 added the patch Should be used for small fixes. label May 19, 2026
Comment thread src/main/java/org/fiware/odrl/http/AccessLogClientFilter.java Outdated

@Slf4j
@Provider
@ApplicationScoped
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully sure, but I think the request filter needs to be annotated with@RegisterForReflection to work on native images

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runner file seems to work. Claude says it isn't needed, so I guess it isn't needed.

Long start = (Long) requestContext.getProperty(START_TIME);
if (start == null) return;

long duration = System.currentTimeMillis() - start;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testability, it would be better to use the clock interface here, instead of directly accessing System.currentTime

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Should be used for small fixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants