Class Server.Builder

  • Enclosing interface:
    Server

    public static final class Server.Builder
    extends Object
    Builder to build Server instance.
    • Method Detail

      • build

        public Server build()
        Build a server based on this builder.
        Returns:
        Server instance to be started
        Throws:
        MpException - in case the server fails to be created
      • host

        public Server.Builder host​(String host)
        Configure listen host.
        Parameters:
        host - hostname
        Returns:
        modified builder
      • basePath

        public Server.Builder basePath​(String basePath)
        Configure a path to which the server would redirect when a root path is requested. E.g. when static content is available at "/static" and you want to start there on index.html, you may want to configure this to "/static/index.html". When user requests "http://host:port" or "http://host:port/", the user would be redirected to "http://host:port/static/index.html"
        Parameters:
        basePath - path to redirect user from root path
        Returns:
        updated builder instance
      • defaultExecutorServiceSupplier

        public Server.Builder defaultExecutorServiceSupplier​(Supplier<? extends ExecutorService> supplier)
        Set a supplier of an executor service to use for tasks connected with application processing (JAX-RS).
        Parameters:
        supplier - executor service supplier, only called when an application is configured without its own executor service
        Returns:
        updated builder instance
      • port

        public Server.Builder port​(int port)
        Configure listen port.
        Parameters:
        port - port
        Returns:
        modified builder
      • config

        public Server.Builder config​(Config config)
        Configuration instance to use to configure this server (Helidon config).
        Parameters:
        config - configuration to use
        Returns:
        modified builder
      • config

        public Server.Builder config​(Config config)
        Configuration instance to use to configure this server (Microprofile config).
        Parameters:
        config - configuration to use
        Returns:
        modified builder
      • cdiContainer

        public Server.Builder cdiContainer​(SeContainer cdiContainer)
        Configure CDI container to use. Use this method if you need to manually configure the CDI container. Also understand, that whatever happens during container initialization is already done and cannot be undone, such as when microprofile configuration is used. If you use this method and then set explicit config using config(Config), you may end up with some classes configured from default MP config.
        Parameters:
        cdiContainer - container to use, currently this requires Weld, as Jersey CDI integration depends on it; not other CDI provider is tested
        Returns:
        modified builder
      • resourceConfig

        public Server.Builder resourceConfig​(ResourceConfig config)
        JAX-RS resource configuration to use.

        Order is (e.g. if application is defined, resource classes are ignored):

        • All Applications and Application classes
        • Resource classes
        • Resource config
        Parameters:
        config - configuration to bootstrap Jersey
        Returns:
        modified builder
      • addApplication

        public Server.Builder addApplication​(JaxRsApplication application)
        Add a JAX-RS application with all possible options to this server.
        Parameters:
        application - application to add
        Returns:
        updated builder instance
      • addApplication

        public Server.Builder addApplication​(Application application)
        JAX-RS application to use. If more than one application is added, they must be registered on different ApplicationPath. Also you must make sure that paths do not overlap, as that may cause unexpected results (e.g. registering one application under root ("/") and another under "/app1" would not work as expected).

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        application - application to bootstrap Jersey
        Returns:
        modified builder
      • addApplication

        public Server.Builder addApplication​(String contextRoot,
                                             Application application)
        JAX-RS application to use. If more than one application is added, they must be registered on different ApplicationPath. Also you must make sure that paths do not overlap, as that may cause unexpected results (e.g. registering one application under root ("/") and another under "/app1" would not work as expected).

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        contextRoot - context root this application will be available under
        application - application to bootstrap Jersey
        Returns:
        modified builder
      • addApplication

        public Server.Builder addApplication​(Class<? extends Application> applicationClass)
        JAX-RS application class to use.

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        applicationClass - application class to bootstrap Jersey
        Returns:
        modified builder
      • addApplication

        public Server.Builder addApplication​(String contextRoot,
                                             Class<? extends Application> applicationClass)
        JAX-RS application class to use.

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        contextRoot - context root to serve this application under
        applicationClass - application class to bootstrap Jersey
        Returns:
        modified builder
      • addResourceClass

        public Server.Builder addResourceClass​(Class<?> resource)
        Add a JAX-RS resource class to use.

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        resource - resource class to add, list of these classes is used to bootstrap Jersey
        Returns:
        modified builder
      • addProviderClass

        public Server.Builder addProviderClass​(Class<?> provider)
        Add a JAX-RS provider class to use.

        Order is (e.g. if application is defined, resource and provider classes are ignored):

        • Applications and application classes
        • Resource and provider classes
        • Resource config
        Parameters:
        provider - provider class to add, list of these classes is used to bootstrap Jersey
        Returns:
        modified builder
      • context

        public Server.Builder context​(Context parentContext)
        Configure the parent context to be used by this server.
        Parameters:
        parentContext - context to serve as a parent
        Returns:
        updated builder instance
      • supportParallel

        public Server.Builder supportParallel​(boolean supportParallelRun)
        Enabled (or disable) support for more than one MP Server running in parallel. By default this is not supported, as a single JVM shares class loader and CDI, so running more than one server in a single JVM can lead to unexpected behavior.
        Parameters:
        supportParallelRun - set to true to start more than one Server in the same JVM
        Returns:
        updated builder instance