Skip to main content

RestOpContext

The RestOpContext object is the workhorse class for an individual RestOp-annotated method. Every class annotated with @RestOp ends up with an instance of this object.

Similar to RestContext, the object is read-only and unchangeable and is initialized with all of the various annotations pulled from the method.

Per-operation configuration is annotation-driven via @RestOp (and its method-specific cousins @RestGet, @RestPut, @RestPost, @RestDelete, @RestPatch, @RestOptions). Programmatic per-operation overrides are supplied via @Bean-named beans (use the methodScope= attribute to scope an override to specific operation methods). Both Builder-injection protocols — per-op @RestInit(RestOpContext.Builder) and class-level @RestInit(RestContext.Builder) — were removed in 10.0; see the V10 Migration Guide for replacement recipes.

10.0+ configuration model

RestOpContext is now configured through:

  • @RestOp(...) / @RestGet(...) / @RestPost(...) / @RestPut(...) / @RestPatch(...) / @RestDelete(...) / @RestOptions(...) attributes.
  • @Bean(name="...") bean suppliers (optionally scoped with methodScope=).
  • Resource-level defaults inherited from @Rest(...) (unless blocked by noInherit).

See @Rest and @RestOp for every attribute that feeds into the context.

Obtaining a RestOpContext​

A RestOpContext is created once per @RestOp method when the owning RestContext is initialized, and is shared by all requests to that method. You can get at it in three ways:

@RestGet("/info")
public String info(RestOpContext opContext, RestRequest req) {
// 1. As a Java method parameter (see JavaMethodParameters).
// 2. From the request.
RestOpContext same = req.getOpContext();
return opContext.getHttpMethod() + " " + opContext.getPathPattern();
}

The owning resource-level context is available through RestOpContext.getContext(), which returns the RestContext (see RestContext).

Getter reference​

The context exposes the effective, fully-resolved settings for the operation, i.e. the @RestOp value with anything unset inherited from @Rest.

Identity and routing​

MethodDescription
getJavaMethod()The java.lang.reflect.Method implementing the operation.
getHttpMethod()The resolved HTTP method (explicit, inferred from the Java method name, or *).
getPathPattern()The first path pattern as a string.
getPathMatchers()All UrlPathMatcher objects for the operation.
getRequiredMatchers() / getOptionalMatchers()The RestMatcher objects that must / may match for the operation to be chosen.
getRestOpAnnotations()The @RestOp-group annotations applied to the method.

Marshalling and content negotiation​

MethodDescription
getSerializers() / getParsers()The SerializerSet / ParserSet for the operation.
getEncoders()The EncoderSet.
getMarshallingContext()The MarshallingContext.
getPartSerializer() / getPartParser()The HttpPartSerializer / HttpPartParser.
getJsonSchemaGenerator()The JsonSchemaGenerator.
getSupportedAcceptTypes() / getSupportedContentTypes()The MediaType lists derived from the serializers/parsers (or produces/consumes).
getAllowedParserOptions() / getAllowedSerializerOptions()Session option keys clients may set.
getMaxInput()Maximum number of input bytes.
getResponseMeta(), getResponseBeanMeta(Object), getResponseHeaderMeta(Object)Response metadata for the return type / a given object.

Defaults​

MethodDescription
getDefaultCharset()Default character set.
getDefaultRequestHeaders()HttpHeaderList applied when the client does not send the header.
getDefaultRequestAttributes()NamedAttributeMap of default request attributes.
getDefaultRequestQueryData() / getDefaultRequestFormData()HttpPartList of default query / form-data values.
getDefaultResponseHeaders()HttpHeaderList of default response headers.

Behavior flags and runtime​

MethodDescription
isProblemDetails()Whether RFC 7807 problem-details responses are enabled; inherited from @Rest(problemDetails) when unset.
isDebugMarshalling()Whether REST-driven marshalling debug is enabled.
isVirtualThreadsEnabled()Whether per-request virtual-thread dispatch is enabled (Java 21+).
isObservabilityEnabled()Whether observability is enabled for the operation.
getMetricName() / getMetricTags()Metric name and tags from @RestOp(metricName, metricTags).
getAsyncTimeoutMillis() / getAsyncCompletionExecutor()Timeout and completion executor for CompletableFuture-returning handlers.
getLogger()The per-operation RichLogger.

RestOpContext implements Comparable<RestOpContext>, which is what orders operations when a request is matched against them.