Class RestOpContext

java.lang.Object
org.apache.juneau.marshall.Context
org.apache.juneau.rest.server.RestOpContext
All Implemented Interfaces:
Comparable<RestOpContext>
Direct Known Subclasses:
RrpcRestOpContext

public class RestOpContext extends Context implements Comparable<RestOpContext>
Represents a single Java servlet/resource method annotated with @RestOp.
Notes:
  • This class is thread safe and reusable.
See Also:
  • Field Details

  • Constructor Details

    • RestOpContext

      public RestOpContext(Method method, RestContext context) throws jakarta.servlet.ServletException
      2-arg positional context constructor.

      All operation-level configuration is resolved from RestOp-group annotations on the method and inherited from the parent RestContext.

      Parameters:
      method - The Java method this context represents. Must not be null.
      context - The owning RestContext. Must not be null.
      Throws:
      jakarta.servlet.ServletException - If context could not be created.
      Since:
      9.2.1
    • RestOpContext

      public RestOpContext(Method method, RestContext context, Supplier<Object> resourceSupplier) throws jakarta.servlet.ServletException
      3-arg positional context constructor.
      Parameters:
      method - The Java method this context represents. Must not be null.
      context - The owning RestContext. Must not be null.
      resourceSupplier - Supplier that returns the invocation target for this operation.
      Throws:
      jakarta.servlet.ServletException - If context could not be created.
  • Method Details

    • getContext

      Returns the RestContext that owns this operation context.

      For operations declared directly on the host resource class, returns the host context. For operations registered through a @Rest(mixins=...) mixin, returns the per-mixin sub-context (parent-linked to the host's context via RestContext.getParentContext()). Callers can use this to identify whether the operation was contributed by a mixin (via RestContext.isMixinContext()).

      Returns:
      The owning RestContext for this operation.
      Since:
      10.0.0
    • getRestOpAnnotations

      Returns all RestOp-group annotations on this operation method, in child-to-parent order.
      Returns:
      An unmodifiable list, never null.
    • isInherited

      protected boolean isInherited(String property)
      Returns true if context-level values for the given property should be merged.
      Parameters:
      property - The annotation attribute name (e.g. "allowedParserOptions", "defaultCharset", "maxInput").
      Returns:
      true if noInherit does not contain this property.
    • getAllowedParserOptions

      Returns the parser session-option keys allowed for this operation.
      Returns:
      An unmodifiable case-insensitive sorted set, never null.
    • getAllowedSerializerOptions

      Returns the serializer session-option keys allowed for this operation.
      Returns:
      An unmodifiable case-insensitive sorted set, never null.
    • compareTo

      public int compareTo(RestOpContext o)
      Specified by:
      compareTo in interface Comparable<RestOpContext>
    • copy

      Description copied from class: Context
      Creates a builder from this context object.

      Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.

      Overrides:
      copy in class Context
      Returns:
      A new Builder object.
    • createRequest

      Creates a RestRequest object based on the specified incoming HttpServletRequest object.
      Parameters:
      session - The current REST call.
      Returns:
      The wrapped request object.
      Throws:
      Exception - If any errors occur trying to interpret the request.
    • createResponse

      Creates a RestResponse object based on the specified incoming HttpServletResponse object and the request returned by createRequest(RestSession).
      Parameters:
      session - The current REST call.
      req - The REST request.
      Returns:
      The wrapped response object.
      Throws:
      Exception - If any errors occur trying to interpret the request or response.
    • createSession

      Creates a new REST operation session.
      Parameters:
      session - The REST session.
      Returns:
      A new REST operation session.
      Throws:
      Exception - If op session could not be created.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getMarshallingContext

      Returns the marshalling context associated with this context.
      Returns:
      The marshalling context associated with this context.
    • getDefaultCharset

      Returns the default charset.
      Returns:
      The default charset. Never null.
    • getDefaultRequestAttributes

      Returns the default request attributes.
      Returns:
      The default request attributes. Never null.
    • getDefaultRequestFormData

      Returns the default form data parameters.
      Returns:
      The default form data parameters. Never null.
    • getDefaultRequestHeaders

      Returns the default request headers.
      Returns:
      The default request headers. Never null.
    • getDefaultRequestQueryData

      Returns the default request query parameters.
      Returns:
      The default request query parameters. Never null.
    • getDefaultResponseHeaders

      Returns the default response headers.
      Returns:
      The default response headers. Never null.
    • getEncoders

      Returns the compression encoders to use for this method.
      Returns:
      The compression encoders to use for this method.
    • getHttpMethod

      Returns the HTTP method name (e.g. "GET").
      Returns:
      The HTTP method name.
    • isRead

      public boolean isRead()
      Returns whether this operation is declared read=true.

      A read operation may be reached by overriding a safe request (GET, HEAD, OPTIONS, TRACE) to its custom method.

      Returns:
      true if this operation is declared a read.
      Throws:
      InternalServerError - If read=true is declared on an inherited @RestOp that names no method.
      Since:
      10.0.0
    • getJavaMethod

      Returns the underlying Java method that this context belongs to.
      Returns:
      The underlying Java method that this context belongs to.
    • getJsonSchemaGenerator

      Returns the JSON-Schema generator applicable to this Java method.
      Returns:
      The JSON-Schema generator applicable to this Java method.
    • getMaxInput

      public long getMaxInput()
      Returns the max number of bytes to process in the input content.
      Returns:
      The max number of bytes to process in the input content.
    • isProblemDetails

      public boolean isProblemDetails()
      Returns whether this operation emits RFC 7807 application/problem+json responses.

      Tri-state inheritance semantics: an explicit "true" or "false" on the operation annotation wins; otherwise the value is inherited from RestContext.isProblemDetails() (resource-level @Rest(problemDetails)).

      See Also:
      Returns:
      true if RFC 7807 problem-details responses are enabled on this operation.
    • isDebugMarshalling

      public boolean isDebugMarshalling()
      Returns whether REST-driven serializer/parser debug behavior is enabled for this operation.

      Resolved via the tri-state @RestOp-group debugMarshalling attribute ("true" wins, "false" opts out, "" inherits the resource-level @Rest(debugMarshalling)), independent of the JUL logger level.

      See Also:
      Returns:
      true if REST-driven marshalling debug is enabled for this operation.
    • isVirtualThreadsEnabled

      public boolean isVirtualThreadsEnabled()
      Returns whether this operation opts into per-request virtual-thread dispatch on Java 21+.

      The op-level @RestOp(virtualThreads) value (when non-blank) wins; otherwise the value is inherited from RestContext.isVirtualThreadsEnabled() (resource-level @Rest(virtualThreads)). Honored only when the resource-level RestContext.getVirtualThreadExecutor() is non-null (Java 21+).

      Returns:
      true if virtual-thread dispatch is configured on this operation.
    • isObservabilityEnabled

      public boolean isObservabilityEnabled()
      Returns whether the observability block is enabled for this operation.

      Returns false when the effective resolved attribute is "false" (explicit opt-out). Returns true in all other cases ("true" strict opt-in or empty/null default).

      Note: the default behavior (empty/null attribute) still runs the observability block, but silently falls back to NoOpMetricsRecorder when no backend is wired. Only "false" completely short-circuits the block.

      Returns:
      false when this operation has explicitly opted out of observability.
      See Also:
    • getMetricName

      Returns the per-op metric name override from @RestOp(metricName).
      Returns:
      The metric name override, or an empty string when not set.
      See Also:
    • getMetricTags

      Returns the per-op additional metric tags from @RestOp(metricTags).
      Returns:
      The tags string (comma-separated key=value pairs), or empty string when not set.
      See Also:
    • getAsyncTimeoutMillis

      public long getAsyncTimeoutMillis()
      Returns the configured async-response timeout (milliseconds) for this operation, or -1 when no value was supplied at the op or resource level — in which case the default 30-second fallback applies in AsyncResponseProcessor.
      Returns:
      The async timeout in milliseconds, or -1 when unset.
    • getAsyncCompletionExecutor

      Returns the effective Executor for routing CompletableFuture completion callbacks on this operation, or null when neither the op nor the resource configures an executor (natural completion thread).
      Returns:
      The executor, or null if no async-completion executor is configured.
      Since:
      10.0.0
    • getParsers

      Returns the parsers to use for this method.
      Returns:
      The parsers to use for this method.
    • getPartParser

      Bean property getter: partParser.
      Returns:
      The value of the partParser property on this bean, or null if it is not set.
    • getPartSerializer

      Bean property getter: partSerializer.
      Returns:
      The value of the partSerializer property on this bean, or null if it is not set.
    • getPathPattern

      Returns the path pattern for this method.
      Returns:
      The path pattern.
    • getPathMatchers

      Returns the URL path matchers for this operation.
      Returns:
      The URL path matchers for this operation.
      Never null.
      The returned list is an immutable, cached view.
    • getOptionalMatchers

      Returns the optional matchers for this operation.
      Returns:
      The optional matchers for this operation.
      Never null.
      The returned list is an immutable, cached view.
    • getRequiredMatchers

      Returns the required matchers for this operation.
      Returns:
      The required matchers for this operation.
      Never null.
      The returned list is an immutable, cached view.
    • getLogger

      Returns the per-operation logger used for debug capture.

      A hierarchical child of the host resource's resolved logger (<hostLoggerName>.<methodName>) — see the logger memoizer for how the host's bean-store-overridden RichLogger (if any) is honored.

      Returns:
      The per-operation logger.
      Never null.
    • getResponseBeanMeta

      Returns metadata about the specified response object if it's annotated with @Response.
      Parameters:
      o - The response POJO. Can be null (returns null).
      Returns:
      Metadata about the specified response object, or null if it's not annotated with @Response.
    • getResponseHeaderMeta

      Returns metadata about the specified response object if it's annotated with @Header.
      Parameters:
      o - The response POJO. Can be null (returns null).
      Returns:
      Metadata about the specified response object, or null if it's not annotated with @Header.
    • getResponseMeta

      Returns the response bean meta if this method returns a Response-annotated bean.
      Returns:
      The response bean meta or null if it's not a Response-annotated bean.
    • getSerializers

      Returns the serializers to use for this method.
      Returns:
      The serializers to use for this method.
    • getSupportedAcceptTypes

      Returns a list of supported accept types.
      Returns:
      An unmodifiable list.
    • getSupportedContentTypes

      Returns the list of supported content types.
      Returns:
      An unmodifiable list.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • match

      protected int match(RestSession session)
      Identifies if this method can process the specified call.

      To process the call, the following must be true:

      • Path pattern must match.
      • Matchers (if any) must match.
      Parameters:
      session - The call to check.
      Returns:
      One of the following values:
      • 0 - Path doesn't match.
      • 1 - Path matched but matchers did not.
      • 2 - Matches.
    • properties

      Description copied from class: Context
      Returns the properties on this bean as a map for debugging.
      Overrides:
      properties in class Context
      Returns:
      The properties on this bean as a map for debugging.