public class JettyMicroserviceBuilder extends MicroserviceBuilder
JettyMicroservice class.
Instances of this class are created using JettyMicroservice.create().
| Modifier | Constructor and Description |
|---|---|
protected |
JettyMicroserviceBuilder()
Constructor.
|
protected |
JettyMicroserviceBuilder(JettyMicroserviceBuilder copyFrom)
Copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
JettyMicroserviceBuilder |
args(Args args)
Specifies the command-line arguments passed into the Java command.
|
JettyMicroserviceBuilder |
args(String... args)
Specifies the command-line arguments passed into the Java command.
|
JettyMicroservice |
build()
Instantiate a new microservice using the settings defined on this builder.
|
JettyMicroserviceBuilder |
config(Config config)
Specifies the config for initializing this microservice.
|
JettyMicroserviceBuilder |
configName(String configName)
Specifies the config name for initializing this microservice.
|
JettyMicroserviceBuilder |
configStore(ConfigStore configStore)
Specifies the config store to use for storing and retrieving configurations.
|
JettyMicroserviceBuilder |
console(Scanner consoleReader,
PrintWriter consoleWriter)
Specifies the console input and output.
|
JettyMicroserviceBuilder |
consoleCommands(ConsoleCommand... consoleCommands)
Specifies console commands to make available on the Java console.
|
JettyMicroserviceBuilder |
consoleEnabled(boolean consoleEnabled)
Specifies that the Java console is enabled for this microservice.
|
JettyMicroserviceBuilder |
copy()
Creates a copy of this builder.
|
JettyMicroserviceBuilder |
jettyServerFactory(JettyServerFactory value)
Specifies the factory to use for creating the Jetty
Server instance. |
JettyMicroserviceBuilder |
jettyXml(Object jettyXml,
boolean resolveVars)
Specifies the contents or location of the
|
JettyMicroserviceBuilder |
listener(JettyMicroserviceListener listener)
Registers an event listener for this microservice.
|
JettyMicroserviceBuilder |
logConfig(LogConfig logConfig)
Specifies logging instructions for the microservice.
|
JettyMicroserviceBuilder |
logger(Logger logger)
Specifies the logger used by the microservice and returned by the
Microservice.getLogger() method. |
JettyMicroserviceBuilder |
manifest(Object manifest)
Specifies the manifest file of the jar file this microservice is contained within.
|
JettyMicroserviceBuilder |
ports(int... ports)
Specifies the ports to use for the web server.
|
JettyMicroserviceBuilder |
servlet(Class<? extends RestServlet> c)
Adds a servlet to the servlet container.
|
JettyMicroserviceBuilder |
servlet(Class<? extends Servlet> c,
String path)
Adds a servlet to the servlet container.
|
JettyMicroserviceBuilder |
servlet(Servlet servlet,
String path)
Adds a servlet instance to the servlet container.
|
JettyMicroserviceBuilder |
servletAttribute(Map<String,Object> values)
Adds a set of servlet attributes to the servlet container.
|
JettyMicroserviceBuilder |
servletAttribute(String name,
Object value)
Adds a servlet attribute to the servlet container.
|
JettyMicroserviceBuilder |
servlets(Map<String,Servlet> servlets)
Adds a set of servlets to the servlet container.
|
JettyMicroserviceBuilder |
varContext(String name,
Object object)
Adds a var resolver context object for vars defined in the configuration and var resolver.
|
JettyMicroserviceBuilder |
vars(Class<? extends Var>... vars)
Augments the set of variables defined in the configuration and var resolver.
|
JettyMicroserviceBuilder |
workingDir(File path)
Specifies the directory to use to resolve the config file and other paths defined with the config file.
|
JettyMicroserviceBuilder |
workingDir(String path)
Specifies the directory to use to resolve the config file and other paths defined with the config file.
|
consoleCommands, listener, resolveFileprotected JettyMicroserviceBuilder()
protected JettyMicroserviceBuilder(JettyMicroserviceBuilder copyFrom)
copyFrom - The builder to copy settings from.public JettyMicroserviceBuilder copy()
MicroserviceBuildercopy in class MicroserviceBuilderpublic JettyMicroserviceBuilder jettyXml(Object jettyXml, boolean resolveVars) throws IOException
If you do not specify this value, it is pulled from the following in the specified order:
By default, we look for the
jettyXml - The contents or location of the file.
String - Relative path to file on file system or classpath.
File - File on file system.
InputStream - Raw contents as Reader - Raw contents.
resolveVars - If IOException - Thrown by underlying stream.public JettyMicroserviceBuilder ports(int... ports)
You can specify multiple ports. The first available will be used.
If you do not specify this value, it is pulled from the following in the specified order:
ports - The ports to use for the web server.public JettyMicroserviceBuilder servlet(Class<? extends RestServlet> c) throws ExecutableException
This method can only be used with servlets with no-arg constructors.
The path is pulled from the Rest.path() annotation.
c - The servlet to add to the servlet container.ExecutableException - Exception occurred on invoked constructor/method/field.public JettyMicroserviceBuilder servlet(Class<? extends Servlet> c, String path) throws ExecutableException
This method can only be used with servlets with no-arg constructors.
c - The servlet to add to the servlet container.path - The servlet path spec.ExecutableException - Exception occurred on invoked constructor/method/field.public JettyMicroserviceBuilder servlet(Servlet servlet, String path)
servlet - The servlet to add to the servlet container.path - The servlet path spec.public JettyMicroserviceBuilder servlets(Map<String,Servlet> servlets)
servlets - A map of servlets to add to the servlet container.
public JettyMicroserviceBuilder servletAttribute(String name, Object value)
name - The attribute name.value - The attribute value.public JettyMicroserviceBuilder servletAttribute(Map<String,Object> values)
values - The map of attributes.public JettyMicroserviceBuilder jettyServerFactory(JettyServerFactory value)
Server instance.
If not specified, uses BasicJettyServerFactory.
value - The new value for this property.public JettyMicroservice build() throws Exception
MicroserviceBuilderbuild in class MicroserviceBuilderException - Error occurred.public JettyMicroserviceBuilder args(Args args)
MicroserviceBuilder
This is required if you use Microservice.getArgs() or
args in class MicroserviceBuilderargs - The command-line arguments passed into the Java command as a pre-parsed Args object.public JettyMicroserviceBuilder args(String... args)
MicroserviceBuilder
This is required if you use Microservice.getArgs() or
args in class MicroserviceBuilderargs - The command-line arguments passed into the Java command as the raw command-line arguments.public JettyMicroserviceBuilder manifest(Object manifest) throws IOException
MicroserviceBuilder
This is required if you use Microservice.getManifest().
It's also used to locate initialization values such as
If you do not specify the manifest file, we attempt to resolve it through the following methods:
manifest in class MicroserviceBuildermanifest - The manifest file of this microservice.
ManifestFile
Manifest
Reader - Containing the raw contents of the manifest. Note that the input must end with a newline.
InputStream - Containing the raw contents of the manifest. Note that the input must end with a newline.
File - File containing the raw contents of the manifest.
String - Path to file containing the raw contents of the manifest.
Class - Finds and loads the manifest file of the jar file that the specified class is contained within.
IOException - Thrown by underlying stream.public JettyMicroserviceBuilder logger(Logger logger)
MicroserviceBuilderMicroservice.getLogger() method.
Calling this method overrides the default logging mechanism controlled by the MicroserviceBuilder.logConfig(LogConfig) method.
logger in class MicroserviceBuilderlogger - The logger to use for logging microservice messages.public JettyMicroserviceBuilder logConfig(LogConfig logConfig)
MicroserviceBuilder
If not specified, the values are taken from the
This method is ignored if MicroserviceBuilder.logger(Logger) is used to set the microservice logger.
logConfig in class MicroserviceBuilderlogConfig - The log configuration.public JettyMicroserviceBuilder config(Config config)
MicroserviceBuilder
Calling this method overrides the default configuration controlled by the MicroserviceBuilder.configName(String) and MicroserviceBuilder.configStore(ConfigStore) methods.
config in class MicroserviceBuilderconfig - The configuration.public JettyMicroserviceBuilder configName(String configName)
MicroserviceBuilderIf you do not specify the config file location, we attempt to resolve it through the following methods:
If no configuration file is found, and empty in-memory configuration is used.
configName in class MicroserviceBuilderconfigName - The configuration name.public JettyMicroserviceBuilder configStore(ConfigStore configStore)
MicroserviceBuilder
By default, we use a ConfigFileStore store for configuration files.
configStore in class MicroserviceBuilderconfigStore - The configuration name.public JettyMicroserviceBuilder consoleEnabled(boolean consoleEnabled)
MicroserviceBuilder
If not specified, this value is taken from the
consoleEnabled in class MicroserviceBuilderconsoleEnabled - public JettyMicroserviceBuilder consoleCommands(ConsoleCommand... consoleCommands)
MicroserviceBuilder
Note that these are ignored if the console is not enabled via MicroserviceBuilder.consoleEnabled(boolean).
This list augments the commands defined via the
consoleCommands in class MicroserviceBuilderconsoleCommands - The list of console commands to append to the list of available commands.public JettyMicroserviceBuilder console(Scanner consoleReader, PrintWriter consoleWriter)
MicroserviceBuilder
If not specified, uses the console returned by System.console().
If that is not available, uses System.in and System.out.
Note that these are ignored if the console is not enabled via MicroserviceBuilder.consoleEnabled(boolean).
console in class MicroserviceBuilderconsoleReader - The console input.consoleWriter - The console output.public JettyMicroserviceBuilder vars(Class<? extends Var>... vars)
MicroserviceBuilder
This calls VarResolverBuilder.vars(Class[]) on the var resolver used to construct the configuration
object returned by Microservice.getConfig() and the var resolver returned by Microservice.getVarResolver().
vars in class MicroserviceBuildervars - The set of variables to append to the var resolver builder.public JettyMicroserviceBuilder varContext(String name, Object object)
MicroserviceBuilder
This calls VarResolverBuilder.contextObject(String,Object) on the var resolver used to construct the configuration
object returned by Microservice.getConfig() and the var resolver returned by Microservice.getVarResolver().
varContext in class MicroserviceBuildername - The context object name.object - The context object.public JettyMicroserviceBuilder workingDir(File path)
MicroserviceBuilderworkingDir in class MicroserviceBuilderpath - The working directory, or public JettyMicroserviceBuilder workingDir(String path)
MicroserviceBuilderworkingDir in class MicroserviceBuilderpath - The working directory, or public JettyMicroserviceBuilder listener(JettyMicroserviceListener listener)
listener - An event listener for this microservice.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.