Class RestContext.Builder

java.lang.Object
org.apache.juneau.Context.Builder
org.apache.juneau.rest.RestContext.Builder
All Implemented Interfaces:
jakarta.servlet.ServletConfig
Enclosing class:
RestContext

public static final class RestContext.Builder extends Context.Builder implements jakarta.servlet.ServletConfig
Builder class.
  • Constructor Details

    • Builder

      protected Builder(Class<?> resourceClass, RestContext parentContext, jakarta.servlet.ServletConfig servletConfig)
      Constructor.
      Parameters:
      resourceClass - The REST servlet/bean type that this context is defined against.
      parentContext - The parent context if this is a child of another resource.
      servletConfig - The servlet config if available.
  • Method Details

    • copy

      Description copied from class: Context.Builder
      Copy creator.
      Specified by:
      copy in class Context.Builder
      Returns:
      A new mutable copy of this builder.
    • build

      public RestContext build()
      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class Context.Builder
      Returns:
      The built object.
    • init

      public RestContext.Builder init(Supplier<?> resource) throws jakarta.servlet.ServletException
      Performs initialization on this builder against the specified REST servlet/bean instance.
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      This object.
      Throws:
      jakarta.servlet.ServletException - If hook method calls failed.
    • resource

      public Supplier<?> resource()
      Returns the REST servlet/bean instance that this context is defined against.
      Returns:
      The REST servlet/bean instance that this context is defined against.
    • resourceAs

      public <T> Optional<T> resourceAs(Class<T> type)
      Returns the REST servlet/bean instance that this context is defined against if it's the specified type.
      Type Parameters:
      T - The expected type of the resource bean.
      Parameters:
      type - The expected type of the resource bean.
      Returns:
      The bean cast to that instance, or Optional.empty() if it's not the specified type.
    • defaultClasses

      Returns the default implementation class list.

      This defines the implementation classes for a variety of bean types.

      Default classes are inherited from the parent REST object. Typically used on the top-level RestContext.Builder to affect class types for that REST object and all children.

      Modifying the default class list on this builder does not affect the default class list on the parent builder, but changes made here are inherited by child builders.

      Returns:
      The default implementation class list.
    • defaultClasses

      public RestContext.Builder defaultClasses(Class<?>... values)
      Adds to the default implementation class list.

      A shortcut for the following code:

      builder.defaultClasses().add(values);

      Parameters:
      values - The values to add to the list of default classes.
      Returns:
      This object.
      See Also:
    • defaultSettings

      Returns the default settings map.

      Default settings are inherited from the parent REST object. Typically used on the top-level RestContext.Builder to affect settings for that REST object and all children.

      Modifying the default settings map on this builder does not affect the default settings on the parent builder, but changes made here are inherited by child builders.

      Returns:
      The default settings map.
    • defaultSetting

      Sets a value in the default settings map.

      A shortcut for the following code:

      builder.defaultSettings().add(key, value);

      Parameters:
      key - The setting key.
      value - The setting value.
      Returns:
      This object.
      See Also:
    • beanStore

      public BeanStore beanStore()
      Returns the bean store in this builder.

      The bean store is a simple storage database for beans keyed by type and name.

      The bean store is created with the parent root bean store as the parent, allowing any beans in the root bean store to be available in this builder. The root bean store typically pulls from an injection framework such as Spring to allow injected beans to be used.

      The default bean store can be overridden via any of the following:

      Returns:
      The bean store in this builder.
    • beanStore

      public <T> RestContext.Builder beanStore(Class<T> beanType, T bean)
      Adds a bean to the bean store of this class.

      Equivalent to calling:

      builder.beanStore().add(beanType, bean);

      See Also:
      Type Parameters:
      T - The class to associate this bean with.
      Parameters:
      beanType - The class to associate this bean with.
      bean - The bean. Can be null.
      Returns:
      This object.
    • beanStore

      public <T> RestContext.Builder beanStore(Class<T> beanType, T bean, String name)
      Adds a bean to the bean store of this class.

      Equivalent to calling:

      builder.beanStore().add(beanType, bean, name);

      See Also:
      Type Parameters:
      T - The class to associate this bean with.
      Parameters:
      beanType - The class to associate this bean with.
      bean - The bean. Can be null.
      name - The bean name if this is a named bean. Can be null.
      Returns:
      This object.
    • rootBeanStore

      Returns the root bean store.

      This is the bean store inherited from the parent resource and does not include any beans added by this class.

      Returns:
      The root bean store.
    • createBeanStore

      protected BeanStore.Builder createBeanStore(Supplier<?> resource)
      Creates the bean store in this builder.
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new bean store builder.
    • varResolver

      Returns the variable resolver sub-builder.

      The variable resolver is used to resolve string variables of the form "$X{...}" in various places such as annotations on the REST class and methods.

      Can be used to add more variables or context objects to the variable resolver. These variables affect the variable resolver returned by RestRequest.getVarResolverSession().

      The var resolver is created by the constructor using the createVarResolver(BeanStore,Supplier,Class) method and is initialized with the following variables:

      The default var resolver can be overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated methods:

        @RestInject public [static] VarResolver myMethod(<args>) {...}

        Args can be any injected bean including VarResolver.Builder, the default builder.
      See Also:
      Returns:
      The variable resolver sub-builder.
    • vars

      @SafeVarargs public final RestContext.Builder vars(Class<? extends Var>... value)
      Adds one or more variables to the var resolver of this class.

      Equivalent to calling:

      builder.vars().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • vars

      public RestContext.Builder vars(Var... value)
      Adds one or more variables to the var resolver of this class.

      Equivalent to calling:

      builder.vars().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createVarResolver

      protected VarResolver.Builder createVarResolver(BeanStore beanStore, Supplier<?> resource, Class<?> resourceClass)
      Creates the variable resolver sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      resourceClass - The REST servlet/bean type that this context is defined against.
      Returns:
      A new variable resolver sub-builder.
    • config

      public Config config()
      Returns the external configuration file for this resource.

      The config file contains arbitrary configuration information that can be accessed by this class, usually via $C variables.

      The default config can be overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(config)
      • @RestInject-annotated method:

        @RestInject public [static] Config myMethod(<args>) {...}

        Args can be any injected bean.

      If a config file is not set up, then an empty config file will be returned that is not backed by any file.

      This bean can be accessed directly via RestContext.getConfig() or passed in as a parameter on a RestOp-annotated method.

      See Also:
      Returns:
      The external configuration file for this resource.
    • config

      Overwrites the default config file with a custom config file.

      By default, the config file is determined using the @Rest(config) annotation. This method allows you to programmatically override it with your own custom config file.

      See Also:
      Parameters:
      config - The new config file.
      Returns:
      This object.
    • createConfig

      protected Config createConfig(BeanStore beanStore, Supplier<?> resource, Class<?> resourceClass)
      Creates the config for this builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      resourceClass - The REST servlet/bean type that this context is defined against.
      Returns:
      A new config.
    • logger

      public Logger logger()
      Returns the logger for this resource.

      The logger is used in the following locations:

      It can also be accessed directly via RestContext.getLogger() or passed in as a parameter on a RestOp-annotated method.

      The default config can be overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] Logger myMethod(<args>) {...}

        Args can be any injected bean.
      See Also:
      Returns:
      The logger for this resource.
    • logger

      Sets the logger for this resource.
      See Also:
      Parameters:
      value - The logger to use for the REST resource.
      Returns:
      This object.
    • createLogger

      protected Logger createLogger(BeanStore beanStore, Supplier<?> resource, Class<?> resourceClass)
      Instantiates the logger for this resource.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      resourceClass - The REST servlet/bean class that this context is defined against.
      Returns:
      A new logger.
    • thrownStore

      Returns the thrown-store sub-builder.

      The thrown store is an in-memory cache of thrown exceptions. It is used to store thrown exceptions when MethodExecStats.error(Throwable) is called from the MethodExecStore bean of this resource. It can also be accessed directly via RestContext.getThrownStore() or passed in as a parameter on a RestOp-annotated method.

      The default thrown store is inherited from the parent context and can be overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] ThrownStore myMethod(<args>) {...}

        Args can be any injected bean including ThrownStore.Builder, the default builder.
      See Also:
      Returns:
      The builder for the ThrownStore object in the REST context.
    • thrownStore

      public RestContext.Builder thrownStore(Class<? extends ThrownStore> value)
      Specifies the thrown store for this class.

      Equivalent to calling:

      builder.thrownStore().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • thrownStore

      Specifies the thrown store for this class.

      Equivalent to calling:

      builder.thrownStore().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createThrownStore

      protected ThrownStore.Builder createThrownStore(BeanStore beanStore, Supplier<?> resource, RestContext parent)
      Instantiates the thrown-store sub-builder.
      See Also:
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      parent - The parent context if the REST bean was registered via Rest.children().
      Will be null if the bean is a top-level resource.
      beanStore - The factory used for creating beans and retrieving injected beans.
      Created by beanStore().
      Returns:
      A new thrown-store sub-builder.
    • encoders

      Returns the encoder group sub-builder.

      Encoders are used to decode HTTP requests and encode HTTP responses based on Content-Encoding and Accept-Encoding headers.

      The default encoder set has support for identity incoding only. It can be overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(encoders)
      • @RestInject-annotated method:

        @RestInject public [static] EncoderSet myMethod(<args>) {...}

        Args can be any injected bean including EncoderSet.Builder, the default builder.
      See Also:
      Returns:
      The builder for the EncoderSet object in the REST context.
    • encoders

      @SafeVarargs public final RestContext.Builder encoders(Class<? extends Encoder>... value)
      Adds one or more encoders to this class.

      Equivalent to calling:

      builder.encoders().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • encoders

      Adds one or more encoders to this class.

      Equivalent to calling:

      builder.encoders().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createEncoders

      protected EncoderSet.Builder createEncoders(BeanStore beanStore, Supplier<?> resource)
      Instantiates the encoder group sub-builder.
      See Also:
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      beanStore - The factory used for creating beans and retrieving injected beans.
      Created by beanStore().
      Returns:
      A new encoder group sub-builder.
    • serializers

      Returns the serializer group sub-builder.

      Serializers are used to convert POJOs to HTTP response bodies based on the Accept header.

      The default serializer set is empty. It can be overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(serializers)
      • @RestInject-annotated method:

        @RestInject public [static] SerializerSet myMethod(<args>) {...}

        Args can be any injected bean including SerializerSet.Builder, the default builder.
      See Also:
      Returns:
      The serializer group sub-builder.
    • serializers

      @SafeVarargs public final RestContext.Builder serializers(Class<? extends Serializer>... value)
      Adds one or more serializers to this class.

      Equivalent to calling:

      builder.serializers().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • serializers

      Adds one or more serializers to this class.

      Equivalent to calling:

      builder.serializers().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createSerializers

      protected SerializerSet.Builder createSerializers(BeanStore beanStore, Supplier<?> resource)
      Instantiates the serializer group sub-builder.
      See Also:
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      beanStore - The factory used for creating beans and retrieving injected beans.
      Created by beanStore().
      Returns:
      A new serializer group sub-builder.
    • parsers

      Returns the parser group sub-builder.

      Parsers are used to HTTP request bodies into POJOs based on the Content-Type header.

      The default parser set is empty. It can be overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(parsers)
      • @RestInject-annotated method:

        @RestInject public [static] ParserSet myMethod(<args>) {...}

        Args can be any injected bean including ParserSet.Builder, the default builder.
      See Also:
      Returns:
      The parser group sub-builder.
    • parsers

      @SafeVarargs public final RestContext.Builder parsers(Class<? extends Parser>... value)
      Adds one or more parsers to this class.

      Equivalent to calling:

      builder.parsers().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • parsers

      public RestContext.Builder parsers(Parser... value)
      Adds one or more parsers to this class.

      Equivalent to calling:

      builder.parsers().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createParsers

      protected ParserSet.Builder createParsers(BeanStore beanStore, Supplier<?> resource)
      Instantiates the parser group sub-builder.
      See Also:
      Parameters:
      resource - The REST servlet/bean instance that this context is defined against.
      beanStore - The factory used for creating beans and retrieving injected beans.
      Created by beanStore().
      Returns:
      A new parser group sub-builder.
    • methodExecStore

      Returns the method execution statistics store sub-builder.

      Used for tracking basic call statistics on Java methods in this class. It can be accessed directly via RestContext.getMethodExecStore() or passed in as a parameter on a RestOp-annotated method.

      The default method exec store can overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] MethodExecStore myMethod(<args>) {...}

        Args can be any injected bean including MethodExecStore.Builder, the default builder.
      See Also:
      Returns:
      The method execution statistics store sub-builder.
    • methodExecStore

      Specifies the method execution store for this class.

      Equivalent to calling:

      builder.methodExecStore().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • methodExecStore

      Specifies the method execution store for this class.

      Equivalent to calling:

      builder.methodExecStore().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createMethodExecStore

      protected MethodExecStore.Builder createMethodExecStore(BeanStore beanStore, Supplier<?> resource)
      Instantiates the method execution statistics store sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new method execution statistics store sub-builder.
    • messages

      Returns the messages sub-builder.

      Messages beans are wrappers around resource bundles containing localized messages.

      By default, the resource bundle name is assumed to match the class name. For example, given the class MyClass.java, the resource bundle is assumed to be MyClass.properties. This property allows you to override this setting to specify a different location such as MyMessages.properties by specifying a value of "MyMessages".

      Resource bundles are searched using the following base name patterns:

      • "{package}.{name}"
      • "{package}.i18n.{name}"
      • "{package}.nls.{name}"
      • "{package}.messages.{name}"

      This annotation is used to provide request-localized (based on Accept-Language) messages for the following methods:

      Request-localized messages are also available by passing either of the following parameter types into your Java method:

      • ResourceBundle - Basic Java resource bundle.
      • Messages - Extended resource bundle with several convenience methods.
      The value can be a relative path like "nls/Messages", indicating to look for the resource bundle "com.foo.sample.nls.Messages" if the resource class is in "com.foo.sample", or it can be an absolute path like "com.foo.sample.nls.Messages"
      Examples:

      # Contents of org/apache/foo/nls/MyMessages.properties HelloMessage = Hello {0}!

      // Contents of org/apache/foo/MyResource.java @Rest(messages="nls/MyMessages") public class MyResource {...} @RestGet("/hello/{you}") public Object helloYou(RestRequest req, Messages messages, @Path("name") String you) { String string; // Get it from the RestRequest object. string = req.getMessage("HelloMessage", you); // Or get it from the method parameter. string = messages.getString("HelloMessage", you); // Or get the message in a locale different from the request. string = messages.forLocale(Locale.UK).getString("HelloMessage", you); return string; } }

      The default messages can overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(messages)
      • @RestInject-annotated method:

        @RestInject public [static] Messages myMethod(<args>) {...}

        Args can be any injected bean including Messages.Builder, the default builder.
      Notes:
      • Mappings are cumulative from super classes.
        Therefore, you can find and retrieve messages up the class-hierarchy chain.
      See Also:
      Returns:
      The messages sub-builder.
    • messages

      public RestContext.Builder messages(Class<? extends Messages> value)
      Specifies the messages bundle for this class.

      Equivalent to calling:

      builder.messages().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • messages

      Specifies the messages bundle for this class.

      Equivalent to calling:

      builder.messages().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createMessages

      protected Messages.Builder createMessages(BeanStore beanStore, Supplier<?> resource)
      Instantiates the messages sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new messages sub-builder.
    • responseProcessors

      Returns the response processor list sub-builder.

      Specifies a list of ResponseProcessor classes that know how to convert POJOs returned by REST methods or set via RestResponse.setContent(Object) into appropriate HTTP responses.

      By default, the following response handlers are provided in the specified order:

      Example:

      // Our custom response processor for Foo objects. public class MyResponseProcessor implements ResponseProcessor { @Override public int process(RestOpSession opSession) throws IOException { RestResponse res = opSession.getResponse(); Foo foo = res.getOutput(Foo.class); if (foo == null) return NEXT; // Let the next processor handle it. try (Writer writer = res.getNegotiatedWriter()) { //Pipe it to the writer ourselves. } return FINISHED; // We handled it. } } } // Option #1 - Defined via annotation. @Rest(responseProcessors=MyResponseProcessor.class) public class MyResource { // Option #2 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.responseProcessors(MyResponseProcessors.class); } @RestGet(...) public Object myMethod() { // Return a special object for our handler. return new MySpecialObject(); } }

      The default response processors can overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(responseProcessors)
      • @RestInject-annotated method:

        @RestInject public [static] ResponseProcessorList myMethod(<args>) {...}

        Args can be any injected bean including ResponseProcessorList.Builder, the default builder.
      Notes:
      • Response processors are always inherited from ascendant resources.
      • When defined as a class, the implementation must have one of the following constructors:
        • public T(RestContext)
        • public T()
        • public static T create(RestContext)
        • public static T create()
      • Inner classes of the REST resource class are allowed.
      See Also:
      Returns:
      The response processor list sub-builder.
    • responseProcessors

      Adds one or more response processors to this class.

      Equivalent to calling:

      builder.responseProcessors().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • responseProcessors

      Adds one or more response processors to this class.

      Equivalent to calling:

      builder.responseProcessors().add(value);

      See Also:
      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createResponseProcessors

      Instantiates the response processor list sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new response processor list sub-builder.
    • callLogger

      Returns the call logger bean creator.

      Specifies the logger to use for logging of HTTP requests and responses.

      Example:

      // Our customized logger. public class MyLogger extends BasicCallLogger { public MyLogger(BeanStore beanStore) { super(beanStore); } @Override protected void log(Level level, String msg, Throwable e) { // Handle logging ourselves. } } // Option #1 - Registered via annotation resolving to a config file setting with default value. @Rest(callLogger=MyLogger.class) public class MyResource { // Option #2 - Registered via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.callLogger(MyLogger.class); } }

      The default call logger can overridden via any of the following:

      • Injected via bean store.
      • Class annotation: @Rest(callLogger)
      • @RestInject-annotated method:

        @RestInject public [static] CallLogger myMethod(<args>) {...}

        Args can be any injected bean.
      Notes:
      • The default call logger if not specified is BasicCallLogger.
      • The resource class itself will be used if it implements the CallLogger interface and not explicitly overridden via this annotation.
      • When defined as a class, the implementation must have one of the following constructor:
        • public T(BeanStore)
      • Inner classes of the REST resource class are allowed.
      See Also:
      Returns:
      The call logger sub-builder.
      Throws:
      RuntimeException - If init(Supplier) has not been called.
    • callLogger

      public RestContext.Builder callLogger(Class<? extends CallLogger> value)
      Specifies the call logger for this class.

      Equivalent to calling:

      builder.callLogger().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • callLogger

      Specifies the call logger for this class.

      Equivalent to calling:

      builder.callLogger().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createCallLogger

      protected BeanCreator<CallLogger> createCallLogger(BeanStore beanStore, Supplier<?> resource)
      Instantiates the call logger sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new call logger sub-builder.
    • beanContext

      Returns the bean context sub-builder.

      The bean context is used to retrieve metadata on Java beans.

      The default bean context can overridden via any of the following:

      • Injected via bean store.
      Returns:
      The bean context sub-builder.
    • createBeanContext

      protected BeanContext.Builder createBeanContext(BeanStore beanStore, Supplier<?> resource)
      Instantiates the bean context sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new bean context sub-builder.
    • partSerializer

      Returns the part serializer sub-builder.

      The part serializer is used for serializing HTTP parts such as response headers.

      The default part serializer is an OpenApiSerializer. It can overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] HttpPartSerializer myMethod(<args>) {...}

        Args can be any injected bean including HttpPartSerializer.Builder, the default builder.
      See Also:
      Returns:
      The part serializer sub-builder.
    • partSerializer

      Specifies the part serializer to use for serializing HTTP parts for this class.

      Equivalent to calling:

      builder.partSerializer().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • partSerializer

      Specifies the part serializer to use for serializing HTTP parts for this class.

      Equivalent to calling:

      builder.partSerializer().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createPartSerializer

      Instantiates the part serializer sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new part serializer sub-builder.
    • partParser

      Returns the part parser sub-builder.

      The part parser is used for parsing HTTP parts such as request headers and query/form/path parameters.

      The default part parser is an OpenApiParser. It can overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] HttpPartParser myMethod(<args>) {...}

        Args can be any injected bean including HttpPartParser.Builder, the default builder.
      See Also:
      Returns:
      The part parser sub-builder.
    • partParser

      Specifies the part parser to use for parsing HTTP parts for this class.

      Equivalent to calling:

      builder.partParser().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • partParser

      Specifies the part parser to use for parsing HTTP parts for this class.

      Equivalent to calling:

      builder.partParser().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createPartParser

      protected HttpPartParser.Creator createPartParser(BeanStore beanStore, Supplier<?> resource)
      Instantiates the part parser sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new part parser sub-builder.
    • jsonSchemaGenerator

      Returns the JSON schema generator sub-builder.

      The JSON schema generator is used for generating JSON schema in the auto-generated Swagger documentation.

      The default JSON schema generator is a default JsonSchemaGenerator. It can overridden via any of the following:

      • Injected via bean store.
      • @RestInject-annotated method:

        @RestInject public [static] JsonSchemaGenerator myMethod(<args>) {...}

        Args can be any injected bean including JsonSchemaGenerator.Builder, the default builder.
      See Also:
      Returns:
      The JSON schema generator sub-builder.
    • jsonSchemaGenerator

      Specifies the JSON schema generator for this class.

      Equivalent to calling:

      builder.jsonSchemaGenerator().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • jsonSchemaGenerator

      Specifies the JSON schema generator for this class.

      Equivalent to calling:

      builder.jsonSchemaGenerator().impl(value);

    • jsonSchemaGenerator()

      See Also:
    • Parameters:
      value - The new value.
      Returns:
      This object.
    • createJsonSchemaGenerator

      Instantiates the JSON schema generator sub-builder.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new JSON schema generator sub-builder.
    • staticFiles

      Returns the static files bean creator.

      Used to retrieve localized files to be served up as static files through the REST API via the following predefined methods:

      The static file finder can be accessed through the following methods:

      The default static files finder implementation class is BasicStaticFiles. This can be overridden via the following:

      Example:

      // Create a static file finder that looks for files in the /files working subdirectory, but // overrides the find() and resolve methods for special handling of special cases and adds a // Foo header to all requests. public class MyStaticFiles extends BasicStaticFiles { public MyStaticFiles() { super( StaticFiles .create() .dir("/files") .headers(BasicStringHeader.of("Foo", "bar")) ); } }

      @Rest(staticFiles=MyStaticFiles.class) public class MyResource {...}

      See Also:
      Returns:
      The static files bean creator.
    • staticFiles

      public RestContext.Builder staticFiles(Class<? extends StaticFiles> value)
      Specifies the static files resource finder for this class.

      Equivalent to calling:

      builder.staticFiles().type(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • staticFiles

      Specifies the static files resource finder for this class.

      Equivalent to calling:

      builder.staticFiles().impl(value);

      See Also:
      Parameters:
      value - The new value.
      Returns:
      This object.
    • createStaticFiles

      protected BeanCreator<StaticFiles> createStaticFiles(BeanStore beanStore, Supplier<?> resource)
      Instantiates the static files bean creator.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new static files sub-builder.
    • defaultRequestHeaders

      Returns the default request headers.
      Returns:
      The default request headers.
    • defaultRequestHeaders

      Default request headers.

      Specifies default values for request headers if they're not passed in through the request.

      Notes:
      • Affects values returned by HttpServletRequestWrapper.getHeader(String) when the header is not present on the request.
      • The most useful reason for this annotation is to provide a default Accept header when one is not specified so that a particular default Serializer is picked.
      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(defaultRequestHeaders={"Accept: application/json", "My-Header=$C{REST/myHeaderValue}"}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder .defaultRequestHeaders( Accept.of("application/json"), BasicHeader.of("My-Header", "foo") ); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.defaultRequestHeaders(Accept.of("application/json")); } // Override at the method level. @RestGet(defaultRequestHeaders={"Accept: text/xml"}) public Object myMethod() {...} }

      See Also:
      Parameters:
      values - The headers to add.
      Returns:
      This object.
    • defaultAccept

      Specifies a default Accept header value if not specified on a request.
      Parameters:
      value - The default value of the Accept header.
      Ignored if null or empty.
      Returns:
      This object.
    • defaultContentType

      Specifies a default Content-Type header value if not specified on a request.
      Parameters:
      value - The default value of the Content-Type header.
      Ignored if null or empty.
      Returns:
      This object.
    • createDefaultRequestHeaders

      protected HeaderList createDefaultRequestHeaders(BeanStore beanStore, Supplier<?> resource)
      Instantiates the default request headers sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request headers sub-builder.
    • defaultResponseHeaders

      Returns the default response headers.
      Returns:
      The default response headers.
    • defaultResponseHeaders

      Default response headers.

      Specifies default values for response headers if they're not set after the Java REST method is called.

      Notes:
      • This is equivalent to calling RestResponse.setHeader(String, String) programmatically in each of the Java methods.
      • The header value will not be set if the header value has already been specified (hence the 'default' in the name).
      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(defaultResponseHeaders={"Content-Type: $C{REST/defaultContentType,text/plain}","My-Header: $C{REST/myHeaderValue}"}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder .defaultResponseHeaders( ContentType.of("text/plain"), BasicHeader.ofPair("My-Header: foo") ); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.defaultResponseHeaders(ContentType.of("text/plain")); } }

      See Also:
      Parameters:
      values - The headers to add.
      Returns:
      This object.
    • createDefaultResponseHeaders

      protected HeaderList createDefaultResponseHeaders(BeanStore beanStore, Supplier<?> resource)
      Instantiates the default response headers sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default response headers sub-builder.
    • defaultRequestAttributes

      Returns the default request attributes sub-builder.
      Returns:
      The default request attributes sub-builder.
    • defaultRequestAttributes

      Default request attributes.

      Specifies default values for request attributes if they're not already set on the request. Affects values returned by the following methods:

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(defaultRequestAttributes={"Foo=bar", "Baz: $C{REST/myAttributeValue}"}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder .defaultRequestAttributes( BasicNamedAttribute.of("Foo", "bar"), BasicNamedAttribute.of("Baz", true) ); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.defaultRequestAttribute("Foo", "bar"); } // Override at the method level. @RestGet(defaultRequestAttributes={"Foo: bar"}) public Object myMethod() {...} }

      Notes:
      Parameters:
      values - The attributes.
      Returns:
      This object.
    • createDefaultRequestAttributes

      Instantiates the default request attributes sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request attributes sub-builder.
    • restOpArgs

      Returns the REST operation args sub-builder.
      Returns:
      The REST operation args sub-builder.
    • restOpArgs

      @SafeVarargs public final RestContext.Builder restOpArgs(Class<? extends RestOpArg>... value)
      Adds one or more REST operation args to this class.

      Equivalent to calling:

      builder.restOpArgs().add(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createRestOpArgs

      protected RestOpArgList.Builder createRestOpArgs(BeanStore beanStore, Supplier<?> resource)
      Instantiates the REST operation args sub-builder.

      Instantiates based on the following logic:

      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new REST operation args sub-builder.
    • debugEnablement

      Returns the debug enablement bean creator.

      Enables the following:

      • HTTP request/response bodies are cached in memory for logging purposes.
      • Request/response messages are automatically logged always or per request.
      Returns:
      The debug enablement sub-builder.
    • debugEnablement

      Specifies the debug enablement class to use for this REST context.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • debugEnablement

      Specifies the debug enablement class to use for this REST context.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • debugDefault

      Sets the debug default value.

      The default debug value is the enablement value if not otherwise overridden at the class or method level.

      Parameters:
      value - The debug default value.
      Returns:
      This object.
    • createDebugEnablement

      protected BeanCreator<DebugEnablement> createDebugEnablement(BeanStore beanStore, Supplier<?> resource)
      Instantiates the debug enablement bean creator.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new debug enablement bean creator.
    • startCallMethods

      Returns the start call method list.
      Returns:
      The start call method list.
    • createStartCallMethods

      protected MethodList createStartCallMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the start call method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new start call method list.
    • endCallMethods

      Returns the end call method list.
      Returns:
      The end call method list.
    • createEndCallMethods

      protected MethodList createEndCallMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the end call method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new end call method list.
    • postInitMethods

      Returns the post-init method list.
      Returns:
      The post-init method list.
    • createPostInitMethods

      protected MethodList createPostInitMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the post-init method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new post-init method list.
    • postInitChildFirstMethods

      Returns the post-init-child-first method list.
      Returns:
      The post-init-child-first method list.
    • createPostInitChildFirstMethods

      protected MethodList createPostInitChildFirstMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the post-init-child-first method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new post-init-child-first method list.
    • destroyMethods

      Returns the destroy method list.
      Returns:
      The destroy method list.
    • createDestroyMethods

      protected MethodList createDestroyMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the destroy method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new destroy method list.
    • preCallMethods

      Returns the pre-call method list.

      The list of methods that gets called immediately before the @RestOp annotated method gets called.

      Returns:
      The pre-call method list.
    • createPreCallMethods

      protected MethodList createPreCallMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the pre-call method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new pre-call method list.
    • postCallMethods

      Returns the post-call method list.

      The list of methods that gets called immediately after the @RestOp annotated method gets called..

      Returns:
      The list of methods that gets called immediately after the @RestOp annotated method gets called..
    • createPostCallMethods

      protected MethodList createPostCallMethods(BeanStore beanStore, Supplier<?> resource)
      Instantiates the post-call method list.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new post-call method list.
    • restOperations

      public RestOperations.Builder restOperations(RestContext restContext) throws jakarta.servlet.ServletException
      Returns the REST operations list.
      Parameters:
      restContext - The rest context.
      Returns:
      The REST operations list.
      Throws:
      jakarta.servlet.ServletException - If a problem occurred instantiating one of the child rest contexts.
    • createRestOperations

      protected RestOperations.Builder createRestOperations(BeanStore beanStore, Supplier<?> resource, RestContext restContext) throws jakarta.servlet.ServletException
      Instantiates the REST operations list.

      The set of RestOpContext objects that represent the methods on this resource.

      Parameters:
      restContext - The rest context.
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new REST operations list.
      Throws:
      jakarta.servlet.ServletException - If a problem occurred instantiating one of the child rest contexts.
    • restChildren

      Returns the REST children list.
      Parameters:
      restContext - The rest context.
      Returns:
      The REST children list.
      Throws:
      Exception - If a problem occurred instantiating one of the child rest contexts.
    • createRestChildren

      protected RestChildren.Builder createRestChildren(BeanStore beanStore, Supplier<?> resource, RestContext restContext) throws Exception
      Instantiates the REST children list.
      Parameters:
      restContext - The rest context.
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new REST children list.
      Throws:
      Exception - If a problem occurred instantiating one of the child rest contexts.
    • swaggerProvider

      Returns the swagger provider sub-builder.
      Returns:
      The swagger provider sub-builder.
    • swaggerProvider

      Specifies the swagger provider for this class.

      Equivalent to calling:

      builder.swaggerProvider().type(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • swaggerProvider

      Specifies the swagger provider for this class.

      Equivalent to calling:

      builder.swaggerProvider().impl(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createSwaggerProvider

      protected BeanCreator<SwaggerProvider> createSwaggerProvider(BeanStore beanStore, Supplier<?> resource)
      Instantiates the swagger provider sub-builder.

      Instantiates based on the following logic:

      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new swagger provider sub-builder.
    • allowedHeaderParams

      Allowed header URL parameters.

      When specified, allows headers such as "Accept" and "Content-Type" to be passed in as URL query parameters.
      For example:

      ?Accept=text/json&Content-Type=text/json

      Notes:
      • Useful for debugging REST interface using only a browser so that you can quickly simulate header values in the URL bar.
      • Header names are case-insensitive.
      • Use "*" to allow any headers to be specified as URL parameters.
      • Use "NONE" (case insensitive) to suppress inheriting a value from a parent class.
      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.allowedHeaderParams"
      • Environment variable "RESTCONTEXT_ALLOWEDHEADERPARAMS"
      • "Accept,Content-Type"
      Returns:
      This object.
    • allowedMethodHeaders

      Allowed method headers.

      A comma-delimited list of HTTP method names that are allowed to be passed as values in an X-Method HTTP header to override the real HTTP method name.

      Allows you to override the actual HTTP method with a simulated method.
      For example, if an HTTP Client API doesn't support PATCH but does support POST (because PATCH is not part of the original HTTP spec), you can add a X-Method: PATCH header on a normal HTTP POST /foo request call which will make the HTTP call look like a PATCH request in any of the REST APIs.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(allowedMethodHeaders="PATCH") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.allowedMethodHeaders("PATCH"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.allowedMethodHeaders("PATCH"); } }

      Notes:
      • Method names are case-insensitive.
      • Use "*" to represent all methods.
      • Use "NONE" (case insensitive) to suppress inheriting a value from a parent class.
      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.allowedMethodHeaders"
      • Environment variable "RESTCONTEXT_ALLOWEDMETHODHEADERS"
      • ""
      Returns:
      This object.
    • allowedMethodParams

      Allowed method parameters.

      When specified, the HTTP method can be overridden by passing in a "method" URL parameter on a regular GET request.
      For example:

      ?method=OPTIONS

      Useful in cases where you want to simulate a non-GET request in a browser by simply adding a parameter.
      Also useful if you want to construct hyperlinks to non-GET REST endpoints such as links to OPTIONS pages.

      Note that per the HTTP specification, special care should be taken when allowing non-safe (POST, PUT, DELETE) methods to be invoked through GET requests.

      Example:

      // Option #1 - Defined via annotation. @Rest(allowedMethodParams="HEAD,OPTIONS,PUT") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.allowedMethodParams("HEAD,OPTIONS,PUT"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.allowedMethodParams("HEAD,OPTIONS,PUT"); } }

      Notes:
      • Format is a comma-delimited list of HTTP method names that can be passed in as a method parameter.
      • 'method' parameter name is case-insensitive.
      • Use "*" to represent all methods.
      • Use "NONE" (case insensitive) to suppress inheriting a value from a parent class.
      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.allowedMethodParams"
      • Environment variable "RESTCONTEXT_ALLOWEDMETHODPARAMS"
      • "HEAD,OPTIONS"
      Returns:
      This object.
    • clientVersionHeader

      Client version header.

      Specifies the name of the header used to denote the client version on HTTP requests.

      The client version is used to support backwards compatibility for breaking REST interface changes.
      Used in conjunction with @RestOp(clientVersion) annotation.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(clientVersionHeader="$C{REST/clientVersionHeader,Client-Version}") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.clientVersionHeader("Client-Version"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.clientVersionHeader("Client-Version"); } }

      // Call this method if Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestGet(path="/foobar", clientVersion="2.0") public Object method1() { ... } // Call this method if Client-Version is at least 1.1, but less than 2.0. @RestGet(path="/foobar", clientVersion="[1.1,2.0)") public Object method2() { ... } // Call this method if Client-Version is less than 1.1. @RestGet(path="/foobar", clientVersion="[0,1.1)") public Object method3() { ... }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.clientVersionHeader"
      • Environment variable "RESTCONTEXT_CLIENTVERSIONHEADER"
      • "Client-Version"
      Returns:
      This object.
    • defaultCharset

      Default character encoding.

      The default character encoding for the request and response if not specified on the request.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(defaultCharset="$C{REST/defaultCharset,US-ASCII}") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.defaultCharset("US-ASCII"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.defaultCharset("US-ASCII"); } // Override at the method level. @RestGet(defaultCharset="UTF-16") public Object myMethod() {...} }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.defaultCharset"
      • Environment variable "RESTCONTEXT_defaultCharset"
      • "utf-8"
      Returns:
      This object.
    • disableContentParam

      Disable content URL parameter.

      When enabled, the HTTP content content on PUT and POST requests can be passed in as text using the "content" URL parameter.
      For example:

      ?content=(name='John%20Smith',age=45)

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(disableContentParam="$C{REST/disableContentParam,true}") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.disableContentParam(); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.disableContentParam(); } }

      Notes:
      • 'content' parameter name is case-insensitive.
      • Useful for debugging PUT and POST methods using only a browser.
      Returns:
      This object.
    • disableContentParam

      public RestContext.Builder disableContentParam(boolean value)
      Disable content URL parameter.

      Same as disableContentParam() but allows you to set it as a boolean value.

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • maxInput

      The maximum allowed input size (in bytes) on HTTP requests.

      Useful for alleviating DoS attacks by throwing an exception when too much input is received instead of resulting in out-of-memory errors which could affect system stability.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(maxInput="$C{REST/maxInput,10M}") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.maxInput("10M"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.maxInput("10M"); } // Override at the method level. @RestPost(maxInput="10M") public Object myMethod() {...} }

      Notes:
      • String value that gets resolved to a long.
      • Can be suffixed with any of the following representing kilobytes, megabytes, and gigabytes: 'K', 'M', 'G'.
      • A value of "-1" can be used to represent no limit.
      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.maxInput"
      • Environment variable "RESTCONTEXT_MAXINPUT"
      • "100M"

      The default is "100M".
      Returns:
      This object.
    • renderResponseStackTraces

      RestContext configuration property:  Render response stack traces in responses.

      Render stack traces in HTTP response bodies when errors occur.

      Parameters:
      value - The new value for this setting.
      The default is false.
      Returns:
      This object.
    • renderResponseStackTraces

      RestContext configuration property:  Render response stack traces in responses.

      Shortcut for calling renderResponseStackTraces(true).

      Returns:
      This object.
    • uriAuthority

      Resource authority path.

      Overrides the authority path value for this resource and any child resources.

      This setting is useful if you want to resolve relative URIs to absolute paths and want to explicitly specify the hostname/port.

      Affects the following methods:

      If you do not specify the authority, it is automatically calculated via the following:

      String scheme = request.getScheme(); int port = request.getServerPort(); StringBuilder sb = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()); if (! (port == 80 && "http".equals(scheme) || port == 443 && "https".equals(scheme))) sb.append(':').append(port); authorityPath = sb.toString();

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest( path="/servlet", uriAuthority="$C{REST/authorityPathOverride,http://localhost:10000}" ) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.uriAuthority("http://localhost:10000"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.uriAuthority("http://localhost:10000"); } }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.uriAuthority"
      • Environment variable "RESTCONTEXT_URIAUTHORITY"
      • null
      Returns:
      This object.
    • uriContext

      Resource context path.

      Overrides the context path value for this resource and any child resources.

      This setting is useful if you want to use "context:/child/path" URLs in child resource POJOs but the context path is not actually specified on the servlet container.

      Affects the following methods:

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest( path="/servlet", uriContext="$C{REST/contextPathOverride,/foo}" ) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.uriContext("/foo"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.uriContext("/foo"); } }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.uriContext"
      • Environment variable "RESTCONTEXT_URICONTEXT"
      • null
      Returns:
      This object.
    • uriRelativity

      URI resolution relativity.

      Specifies how relative URIs should be interpreted by serializers.

      See UriResolution for possible values.

      Affects the following methods:

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest( path="/servlet", uriRelativity="$C{REST/uriRelativity,PATH_INFO}" ) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.uriRelativity(PATH_INFO); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.uriRelativity(PATH_INFO); } }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.uriRelativity"
      • Environment variable "RESTCONTEXT_URIRELATIVITY"
      • UriRelativity.RESOURCE
      Returns:
      This object.
    • uriResolution

      URI resolution.

      Specifies how relative URIs should be interpreted by serializers.

      See UriResolution for possible values.

      Affects the following methods:

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest( path="/servlet", uriResolution="$C{REST/uriResolution,ABSOLUTE}" ) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.uriResolution(ABSOLUTE); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.uriResolution(ABSOLUTE); } }

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      Returns:
      This object.
    • getSerializers

      Returns the serializer group builder containing the serializers for marshalling POJOs into response bodies.

      Serializer are used to convert POJOs to HTTP response bodies.
      Any of the Juneau framework serializers can be used in this setting.
      The serializer selected is based on the request Accept header matched against the values returned by the following method using a best-match algorithm:

      The builder is initialized with serializers defined via the Rest.serializers() annotation. That annotation is applied from parent-to-child order with child entries given priority over parent entries.

      See Also:
      Returns:
      The serializer group builder for this context builder.
    • getParsers

      Returns the parser group builder containing the parsers for converting HTTP request bodies into POJOs.

      Parsers are used to convert the content of HTTP requests into POJOs.
      Any of the Juneau framework parsers can be used in this setting.
      The parser selected is based on the request Content-Type header matched against the values returned by the following method using a best-match algorithm:

      The builder is initialized with parsers defined via the Rest.parsers() annotation. That annotation is applied from parent-to-child order with child entries given priority over parent entries.

      See Also:
      Returns:
      The parser group builder for this context builder.
    • getEncoders

      Returns the encoder group builder containing the encoders for compressing/decompressing input and output streams.

      These can be used to enable various kinds of compression (e.g. "gzip") on requests and responses.

      The builder is initialized with encoders defined via the Rest.encoders() annotation. That annotation is applied from parent-to-child order with child entries given priority over parent entries.

      See Also:
      Returns:
      The encoder group builder for this context builder.
    • children

      public RestContext.Builder children(Object... values)
      Child REST resources.

      Defines children of this resource.

      A REST child resource is simply another servlet or object that is initialized as part of the ascendant resource and has a servlet path directly under the ascendant resource object path.
      The main advantage to defining servlets as REST children is that you do not need to define them in the web.xml file of the web application.
      This can cut down on the number of entries that show up in the web.xml file if you are defining large numbers of servlets.

      Child resources must specify a value for @Rest(path) that identifies the subpath of the child resource relative to the ascendant path UNLESS you use the child(String, Object) method to register it.

      Child resources can be nested arbitrarily deep using this technique (i.e. children can also have children).

      Servlet initialization:

      A child resource will be initialized immediately after the ascendant servlet/resource is initialized.
      The child resource receives the same servlet config as the ascendant servlet/resource.
      This allows configuration information such as servlet initialization parameters to filter to child resources.

      Runtime behavior:

      As a rule, methods defined on the HttpServletRequest object will behave as if the child servlet were deployed as a top-level resource under the child's servlet path.
      For example, the getServletPath() and getPathInfo() methods on the HttpServletRequest object will behave as if the child resource were deployed using the child's servlet path.
      Therefore, the runtime behavior should be equivalent to deploying the child servlet in the web.xml file of the web application.

      Example:

      // Our child resource. @Rest(path="/child") public class MyChildResource {...} // Option #1 - Registered via annotation. @Rest(children={MyChildResource.class}) public class MyResource { // Option #2 - Registered via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.children(MyChildResource.class); // Use a pre-instantiated object instead. builder.child("/child", new MyChildResource()); } // Option #3 - Registered via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.children(MyChildResource.class); } }

      Notes:
      • When defined as classes, instances are resolved using the registered bean store which by default is BeanStore which requires the class have one of the following constructors:
        • public T(RestContext.Builder)
        • public T()
      See Also:
      Parameters:
      values - The values to add to this setting.
      Objects can be any of the specified types:
      • A class that has a constructor described above.
      • An instantiated resource object (such as a servlet object instantiated by a servlet container).
      • An instance of RestChild containing an instantiated resource object and a subpath.
      Returns:
      This object.
    • child

      public RestContext.Builder child(String path, Object child)
      Add a child REST resource.

      Shortcut for adding a single child to this resource.

      This can be used for resources that don't have a @Rest(path) annotation.

      Parameters:
      path - The child path relative to the parent resource URI.
      child - The child to add to this resource.
      Returns:
      This object.
    • parserListener

      RestContext configuration property:  Parser listener.

      Specifies the parser listener class to use for listening to non-fatal parsing errors.

      See Also:
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • path

      Resource path.

      Identifies the URL subpath relative to the parent resource.

      This setting is critical for the routing of HTTP requests from ascendant to child resources.

      Example:

      // Option #1 - Defined via annotation. @Rest(path="/myResource") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.path("/myResource"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.path("/myResource"); } }

      Notes:
      • This annotation is ignored on top-level servlets (i.e. servlets defined in web.xml files).
        Therefore, implementers can optionally specify a path value for documentation purposes.
      • Typically, this setting is only applicable to resources defined as children through the @Rest(children) annotation.
        However, it may be used in other ways (e.g. defining paths for top-level resources in microservices).
      • Slashes are trimmed from the path ends.
        As a convention, you may want to start your path with '/' simple because it make it easier to read.
      • This path is available through the following method:
      See Also:
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • restChildrenClass

      REST children class.

      Allows you to extend the RestChildren class to modify how any of the methods are implemented.

      The subclass must have a public constructor that takes in any of the following arguments:

      • RestChildren.Builder - The builder for the object.
      • Any beans found in the specified bean store.
      • Any Optional beans that may or may not be found in the specified bean store.
      Example:

      // Our extended context class public MyRestChildren extends RestChildren { public MyRestChildren(RestChildren.Builder builder, ARequiredSpringBean bean1, Optional<AnOptionalSpringBean> bean2) { super(builder); } // Override any methods. @Override public Optional<RestChildMatch> findMatch(RestCall call) { String path = call.getPathInfo(); if (path.endsWith("/foo")) { // Do our own special handling. } return super.findMatch(call); } }

      // Option #1 - Defined via annotation. @Rest(restChildrenClass=MyRestChildren.class) public class MyResource { ... // Option #2 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.restChildrenClass(MyRestChildren.class); } }

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • restOpContextClass

      REST operation context class.

      Allows you to extend the RestOpContext class to modify how any of the methods are implemented.

      The subclass must have a public constructor that takes in any of the following arguments:

      • RestOpContext.Builder - The builder for the object.
      • Any beans found in the specified bean store.
      • Any Optional beans that may or may not be found in the specified bean store.
      Example:

      // Our extended context class that adds a request attribute to all requests. // The attribute value is provided by an injected spring bean. public MyRestOperationContext extends RestOpContext { private final Optional<? extends Supplier<Object>> fooSupplier; // Constructor that takes in builder and optional injected attribute provider. public MyRestOperationContext(RestOpContext.Builder builder, Optional<AnInjectedFooSupplier> fooSupplier) { super(builder); this.fooSupplier = fooSupplier.orElseGet(()->null); } // Override the method used to create default request attributes. @Override protected NamedAttributeMap createDefaultRequestAttributes(Object resource, BeanStore beanStore, Method method, RestContext context) throws Exception { return super .createDefaultRequestAttributes(resource, beanStore, method, context) .append(NamedAttribute.of("foo", ()->fooSupplier.get()); } }

      // Option #1 - Defined via annotation. @Rest(restOpContextClass=MyRestOperationContext.class) public class MyResource { ... // Option #2 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.methodContextClass(MyRestOperationContext.class); } @RestGet public Object foo(RequestAttributes attributes) { return attributes.get("foo"); } }

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • restOperationsClass

      REST operations class.

      Allows you to extend the RestOperations class to modify how any of the methods are implemented.

      The subclass must have a public constructor that takes in any of the following arguments:

      • RestOperations.Builder - The builder for the object.
      • Any beans found in the specified bean store.
      • Any Optional beans that may or may not be found in the specified bean store.
      Example:

      // Our extended context class public MyRestOperations extends RestOperations { public MyRestOperations(RestOperations.Builder builder, ARequiredSpringBean bean1, Optional<AnOptionalSpringBean> bean2) { super(builder); } // Override any methods. @Override public RestOpContext findMethod(RestCall call) throws MethodNotAllowed, PreconditionFailed, NotFound { String path = call.getPathInfo(); if (path.endsWith("/foo")) { // Do our own special handling. } return super.findMethod(call); } }

      // Option #1 - Defined via annotation. @Rest(restMethodsClass=MyRestOperations.class) public class MyResource { ... // Option #2 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.restMethodsClass(MyRestOperations.class); } }

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • serializerListener

      RestContext configuration property:  Serializer listener.

      Specifies the serializer listener class to use for listening to non-fatal serialization errors.

      See Also:
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • produces

      Supported accept media types.

      Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
      An example where this might be useful if you have serializers registered that handle media types that you don't want exposed in the Swagger documentation.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(produces={"$C{REST/supportedProduces,application/json}"}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.produces(false, "application/json") } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.produces(false, "application/json"); } }

      This affects the returned values from the following:

      See Also:
      Parameters:
      values - The values to add to this setting.
      Returns:
      This object.
    • produces

      Returns the media types produced by this resource if it's manually specified.
      Returns:
      The media types.
    • consumes

      Supported content media types.

      Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
      An example where this might be useful if you have parsers registered that handle media types that you don't want exposed in the Swagger documentation.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(consumes={"$C{REST/supportedConsumes,application/json}"}) public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.consumes(false, "application/json") } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.consumes(false, "application/json"); } }

      This affects the returned values from the following:

      See Also:
      Parameters:
      values - The values to add to this setting.
      Returns:
      This object.
    • consumes

      Returns the media types consumed by this resource if it's manually specified.
      Returns:
      The media types.
    • annotations

      Description copied from class: Context.Builder
      Defines annotations to apply to specific classes and methods.

      Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so.

      As a rule, any Juneau annotation with an on() method can be used with this setting.

      The following example shows the equivalent methods for applying the @Bean annotation:

      // Class with explicit annotation. @Bean(properties="street,city,state") public class A {...} // Class with annotation applied via @BeanConfig public class B {...} // Java REST method with @BeanConfig annotation. @RestGet(...) @Bean(on="B", properties="street,city,state") public void doFoo() {...}

      In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so:

      // Create a concrete @Bean annotation. Bean annotation = BeanAnnotation.create(B.class).properties("street,city,state").build(); // Apply it to a serializer. WriterSerializer serializer = JsonSerializer.create().annotations(annotation).build(); // Serialize a bean with the dynamically applied annotation. String json = serializer.serialize(new B());

      The following is the list of annotations builders provided that can be constructed and passed into the builder class:

      The syntax for the on() pattern match parameter depends on whether it applies to a class, method, field, or constructor. The valid pattern matches are:

      • Classes:
        • Fully qualified:
          • "com.foo.MyClass"
        • Fully qualified inner class:
          • "com.foo.MyClass$Inner1$Inner2"
        • Simple:
          • "MyClass"
        • Simple inner:
          • "MyClass$Inner1$Inner2"
          • "Inner1$Inner2"
          • "Inner2"
      • Methods:
        • Fully qualified with args:
          • "com.foo.MyClass.myMethod(String,int)"
          • "com.foo.MyClass.myMethod(java.lang.String,int)"
          • "com.foo.MyClass.myMethod()"
        • Fully qualified:
          • "com.foo.MyClass.myMethod"
        • Simple with args:
          • "MyClass.myMethod(String,int)"
          • "MyClass.myMethod(java.lang.String,int)"
          • "MyClass.myMethod()"
        • Simple:
          • "MyClass.myMethod"
        • Simple inner class:
          • "MyClass$Inner1$Inner2.myMethod"
          • "Inner1$Inner2.myMethod"
          • "Inner2.myMethod"
      • Fields:
        • Fully qualified:
          • "com.foo.MyClass.myField"
        • Simple:
          • "MyClass.myField"
        • Simple inner class:
          • "MyClass$Inner1$Inner2.myField"
          • "Inner1$Inner2.myField"
          • "Inner2.myField"
      • Constructors:
        • Fully qualified with args:
          • "com.foo.MyClass(String,int)"
          • "com.foo.MyClass(java.lang.String,int)"
          • "com.foo.MyClass()"
        • Simple with args:
          • "MyClass(String,int)"
          • "MyClass(java.lang.String,int)"
          • "MyClass()"
        • Simple inner class:
          • "MyClass$Inner1$Inner2()"
          • "Inner1$Inner2()"
          • "Inner2()"
      • A comma-delimited list of anything on this list.
      See Also:
      Overrides:
      annotations in class Context.Builder
      Parameters:
      values - The annotations to register with the context.
      Returns:
      This object.
    • apply

      Description copied from class: Context.Builder
      Applies a set of applied to this builder.

      An AnnotationWork consists of a single pair of AnnotationInfo that represents an annotation instance, and AnnotationApplier which represents the code used to apply the values in that annotation to a specific builder.

      Example:

      // A class annotated with a config annotation. @BeanConfig(sortProperties="$S{sortProperties,false}") public class MyClass {...} // Find all annotations that themselves are annotated with @ContextPropertiesApply. AnnotationList annotations = ClassInfo.of(MyClass.class).getAnnotationList(CONTEXT_APPLY_FILTER); VarResolverSession vrs = VarResolver.DEFAULT.createSession(); AnnotationWorkList work = AnnotationWorkList.of(vrs, annotations); // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .apply(work) .build();

      Overrides:
      apply in class Context.Builder
      Parameters:
      work - The list of annotations and appliers to apply to this builder.
      Returns:
      This object.
    • applyAnnotations

      public RestContext.Builder applyAnnotations(Class<?>... fromClasses)
      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified class to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on classes are appended in the following order:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.

      The default var resolver VarResolver.DEFAULT is used to resolve any variables in annotation field values.

      Example:

      // A class annotated with a config annotation. @BeanConfig(sortProperties="$S{sortProperties,false}") public class MyClass {...} // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class) .build();

      Overrides:
      applyAnnotations in class Context.Builder
      Parameters:
      fromClasses - The classes on which the annotations are defined.
      Returns:
      This object.
    • applyAnnotations

      public RestContext.Builder applyAnnotations(Method... fromMethods)
      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified method to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on methods are appended in the following order:

      1. On the package of the method class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On the method class.
      5. On this method and matching methods ordered parent-to-child.

      The default var resolver VarResolver.DEFAULT is used to resolve any variables in annotation field values.

      Example:

      // A method annotated with a config annotation. public class MyClass { @BeanConfig(sortProperties="$S{sortProperties,false}") public void myMethod() {...} } // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class.getMethod("myMethod")) .build();

      Overrides:
      applyAnnotations in class Context.Builder
      Parameters:
      fromMethods - The methods on which the annotations are defined.
      Returns:
      This object.
    • cache

      public RestContext.Builder cache(Cache<HashKey,? extends Context> value)
      Description copied from class: Context.Builder
      Specifies a cache to use for hashkey-based caching.
      Overrides:
      cache in class Context.Builder
      Parameters:
      value - The cache.
      Returns:
      This object.
    • debug

      Description copied from class: Context.Builder
      Context configuration property:  Debug mode.

      Enables the following additional information during serialization:

      Enables the following additional information during parsing:

      • When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
      Example:

      // Create a serializer with debug enabled. WriterSerializer serializer = JsonSerializer .create() .debug() .build(); // Create a POJO model with a recursive loop. public class MyBean { public Object f; } MyBean bean = new MyBean(); bean.f = bean; // Throws a SerializeException and not a StackOverflowError String json = serializer.serialize(bean);

      See Also:
      Overrides:
      debug in class Context.Builder
      Returns:
      This object.
    • debug

      public RestContext.Builder debug(boolean value)
      Description copied from class: Context.Builder
      Same as Context.Builder.debug() but allows you to explicitly specify the value.
      Overrides:
      debug in class Context.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • impl

      Description copied from class: Context.Builder
      Specifies a pre-instantiated bean for the Context.Builder.build() method to return.
      Overrides:
      impl in class Context.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • type

      public RestContext.Builder type(Class<? extends Context> value)
      Description copied from class: Context.Builder
      Associates a context class with this builder.

      This is the type of object that this builder creates when the Context.Builder.build() method is called.

      By default, it's the outer class of where the builder class is defined.

      Overrides:
      type in class Context.Builder
      Parameters:
      value - The context class that this builder should create.
      Returns:
      This object.
    • getInitParameter

      Specified by:
      getInitParameter in interface jakarta.servlet.ServletConfig
    • getInitParameterNames

      Specified by:
      getInitParameterNames in interface jakarta.servlet.ServletConfig
    • getServletContext

      public jakarta.servlet.ServletContext getServletContext()
      Specified by:
      getServletContext in interface jakarta.servlet.ServletConfig
    • getServletName

      Specified by:
      getServletName in interface jakarta.servlet.ServletConfig