HandlerContext#
com.palmyralabs.palmyra.handlers.HandlerContext
Overview#
Request-scope context passed to every handler hook. Exposes the mapped type, URL path, action, query/path parameters, the client info, and the raw HttpServletResponse. It also doubles as a typed scratchpad via put / get(String, Class<T>), scoped to the current request.
Methods#
| Method | Signature |
|---|---|
getType |
String getType() — entity type being handled |
getPathMapping |
String getPathMapping() — matched CRUD/action path |
getAction |
MutableAction getAction() — current CRUD action |
getParams |
Map<String, String> getParams() — query + path params |
getClientInfo |
ClientInfo getClientInfo() — calling client metadata |
getResponse |
HttpServletResponse getResponse() — raw servlet response |
getReturnMode |
String getReturnMode() |
put |
void put(String key, Object value) — scratchpad write |
get |
Object get(String key) · default <T> T get(String key, Class<T> clazz) — typed read |
Example#
@Override
public Tuple preCreate(Tuple tuple, HandlerContext ctx) {
// pull a tenant hint from the URL
String tenant = ctx.getParams().get("tenantId");
tuple.setAttribute("tenantId", tenant);
// cache something for postCreate to read
ctx.put("correlationId", UUID.randomUUID().toString());
// set a custom response header
ctx.getResponse().setHeader("X-Palmyra-Action", ctx.getAction().name());
return tuple;
}
@Override
public Tuple postCreate(Tuple tuple, HandlerContext ctx) {
String correlationId = ctx.get("correlationId", String.class);
outbox.publish("user.created", Map.of("id", tuple.get("id"), "corr", correlationId));
return tuple;
}