Skip to content

Context

Overview

Module

Per-request scratch storage bound to the calling thread. Useful for passing values from a filter or interceptor down to a controller method without threading the data through every method signature — for example user-derived language preferences, correlation ids, request-scoped feature flags.

Values are not persisted across requests. For longer-lived global state use Globals; for the actual HTTP session-scoped storage use org.eclipse.dirigible.sdk.http.Session.

Key Features

  • Thread-bound: Values are visible only to the thread that wrote them.
  • Request-scoped: Cleared between requests — no leak across calls.
  • Untyped values: Stores arbitrary Objects, so the caller is responsible for cast safety.

Example Usage

java
import org.eclipse.dirigible.sdk.core.Context;

// In a request filter / interceptor:
Context.set("correlationId", request.getHeader("X-Correlation-Id"));
Context.set("locale", resolveLocale(request));

// Later, in a controller or service:
String correlationId = (String) Context.get("correlationId");

Methods

get()

Retrieves the value previously set under the given name on the current thread, or null if none.

java
public static Object get(String name);
ParameterTypeDescription
nameStringThe context key.

Returns

  • Type: Object
  • Description: The stored value, or null if no value is set under that name.

set()

Stores a value under the given name in the current thread's context.

java
public static void set(String name, Object value);
ParameterTypeDescription
nameStringThe context key.
valueObjectThe value to store.

Returns

  • Type: void

Released under the EPL-2.0 License.