Class JettyMicroservice.Builder
- Enclosing class:
- JettyMicroservice
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Builder()
Constructor.protected
Builder
(JettyMicroservice.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionSpecifies the command-line arguments passed into the Java command.Specifies the command-line arguments passed into the Java command.build()
Instantiate a new microservice using the settings defined on this builder.Specifies the config for initializing this microservice.configName
(String configName) Specifies the config name for initializing this microservice.configStore
(ConfigStore configStore) Specifies the config store to use for storing and retrieving configurations.console
(Scanner consoleReader, PrintWriter consoleWriter) Specifies the console input and output.consoleCommands
(ConsoleCommand... consoleCommands) Specifies console commands to make available on the Java console.consoleEnabled
(boolean consoleEnabled) Specifies that the Java console is enabled for this microservice.copy()
Creates a copy of this builder.Specifies the factory to use for creating the JettyServer
instance.Specifies the contents or location of thejetty.xml file used by the Jetty server.listener
(JettyMicroserviceListener listener) Registers an event listener for this microservice.Specifies the logger used by the microservice and returned by theMicroservice.getLogger()
method.Specifies the manifest file of the jar file this microservice is contained within.ports
(int... ports) Specifies the ports to use for the web server.Adds a servlet instance to the servlet container.Adds a servlet to the servlet container.servlet
(Class<? extends RestServlet> c) Adds a servlet to the servlet container.servletAttribute
(String name, Object value) Adds a servlet attribute to the servlet container.servletAttribute
(Map<String, Object> values) Adds a set of servlet attributes to the servlet container.Adds a set of servlets to the servlet container.Adds a bean for vars defined in the var resolver.Augments the set of variables defined in the configuration and var resolver.workingDir
(File path) Specifies the directory to use to resolve the config file and other paths defined with the config file.workingDir
(String path) Specifies the directory to use to resolve the config file and other paths defined with the config file.Methods inherited from class org.apache.juneau.microservice.Microservice.Builder
consoleCommands, listener, logConfig, resolveFile
-
Constructor Details
-
Builder
protected Builder()Constructor. -
Builder
Copy constructor.- Parameters:
copyFrom
- The builder to copy settings from.
-
-
Method Details
-
copy
Description copied from class:Microservice.Builder
Creates a copy of this builder.- Overrides:
copy
in classMicroservice.Builder
- Returns:
- A new copy of this builder.
-
jettyXml
Specifies the contents or location of thejetty.xml file used by the Jetty server.If you do not specify this value, it is pulled from the following in the specified order:
-
Jetty/config setting in the config file.Jetty-Config setting in the manifest file.
By default, we look for the
jetty.xml file in the following locations:jetty.xml in home directory.files/jetty.xml in home directory./jetty.xml in classpath./files/jetty.xml in classpath.
- Parameters:
jettyXml
- The contents or location of the file.
Can be any of the following:String
- Relative path to file on file system or classpath.File
- File on file system.Path
- Path on file system.InputStream
- Raw contents asUTF-8 encoded stream.Reader
- Raw contents.
resolveVars
- Iftrue , SVL variables in the file will automatically be resolved.- Returns:
- This object.
- Throws:
IOException
- Thrown by underlying stream.
-
-
ports
Specifies the ports to use for the web server.You can specify multiple ports. The first available will be used.
'0' indicates to try a random port. The resulting available port gets set as the system property"availablePort" which can be referenced in thejetty.xml file as"$S{availablePort}" (assuming resolveVars is enabled).If you do not specify this value, it is pulled from the following in the specified order:
-
Jetty/port setting in the config file. -
Jetty-Port setting in the manifest file. -
8000
- Parameters:
ports
- The ports to use for the web server.- Returns:
- This object.
-
-
servlet
Adds a servlet to the servlet container.This method can only be used with servlets with no-arg constructors.
The path is pulled from theRest.path()
annotation.- Parameters:
c
- The servlet to add to the servlet container.- Returns:
- This object.
- Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
servlet
public JettyMicroservice.Builder servlet(Class<? extends jakarta.servlet.Servlet> c, String path) throws ExecutableException Adds a servlet to the servlet container.This method can only be used with servlets with no-arg constructors.
- Parameters:
c
- The servlet to add to the servlet container.path
- The servlet path spec.- Returns:
- This object.
- Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
servlet
Adds a servlet instance to the servlet container.- Parameters:
servlet
- The servlet to add to the servlet container.path
- The servlet path spec.- Returns:
- This object.
-
servlets
Adds a set of servlets to the servlet container.- Parameters:
servlets
- A map of servlets to add to the servlet container.
Keys are path specs for the servlet.- Returns:
- This object.
-
servletAttribute
Adds a servlet attribute to the servlet container.- Parameters:
name
- The attribute name.value
- The attribute value.- Returns:
- This object.
-
servletAttribute
Adds a set of servlet attributes to the servlet container.- Parameters:
values
- The map of attributes.- Returns:
- This object.
-
jettyServerFactory
Specifies the factory to use for creating the JettyServer
instance.If not specified, uses
BasicJettyServerFactory
.- Parameters:
value
- The new value for this property.- Returns:
- This object.
-
build
Description copied from class:Microservice.Builder
Instantiate a new microservice using the settings defined on this builder.- Overrides:
build
in classMicroservice.Builder
- Returns:
- A new microservice.
- Throws:
Exception
- Error occurred.
-
args
Description copied from class:Microservice.Builder
Specifies the command-line arguments passed into the Java command.This is required if you use
Microservice.getArgs()
or$A string variables.- Overrides:
args
in classMicroservice.Builder
- Parameters:
args
- The command-line arguments passed into the Java command as a pre-parsedArgs
object.- Returns:
- This object.
-
args
Description copied from class:Microservice.Builder
Specifies the command-line arguments passed into the Java command.This is required if you use
Microservice.getArgs()
or$A string variables.- Overrides:
args
in classMicroservice.Builder
- Parameters:
args
- The command-line arguments passed into the Java command as the raw command-line arguments.- Returns:
- This object.
-
manifest
Description copied from class:Microservice.Builder
Specifies the manifest file of the jar file this microservice is contained within.This is required if you use
Microservice.getManifest()
. It's also used to locate initialization values such asMain-Config .If you do not specify the manifest file, we attempt to resolve it through the following methods:
-
Looking on the file system for a file at
"META-INF/MANIFEST.MF" . This is primarily to allow for running microservices from within eclipse workspaces where the manifest file is located in the project root. -
Using the class loader for this class to find the file at the URL
"META-INF/MANIFEST.MF" .
- Overrides:
manifest
in classMicroservice.Builder
- Parameters:
manifest
- The manifest file of this microservice.
Can be any of the following types: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.
- Returns:
- This object.
- Throws:
IOException
- Thrown by underlying stream.
-
Looking on the file system for a file at
-
logger
Description copied from class:Microservice.Builder
Specifies the logger used by the microservice and returned by theMicroservice.getLogger()
method.Calling this method overrides the default logging mechanism controlled by the
Microservice.Builder.logConfig(LogConfig)
method.- Overrides:
logger
in classMicroservice.Builder
- Parameters:
logger
- The logger to use for logging microservice messages.- Returns:
- This object.
-
config
Description copied from class:Microservice.Builder
Specifies the config for initializing this microservice.Calling this method overrides the default configuration controlled by the
Microservice.Builder.configName(String)
andMicroservice.Builder.configStore(ConfigStore)
methods.- Overrides:
config
in classMicroservice.Builder
- Parameters:
config
- The configuration.- Returns:
- This object.
-
configName
Description copied from class:Microservice.Builder
Specifies the config name for initializing this microservice.If you do not specify the config file location, we attempt to resolve it through the following methods:
-
Resolve file first in working directory, then in classpath, using the following names:
-
The
"configFile" argument in the command line arguments passed in through the constructor. -
The value of the
Main-Config entry in the manifest file. -
A config file in the same location and with the same name as the executable jar file.
(e.g.
"java -jar myjar.jar" will look for"myjar.cfg" ).
-
The
-
Resolve any
"*.cfg" file that can be found in the working directory. -
Resolve any of the following files in the classpath:
"juneau.cfg" ,"system.cfg"
If no configuration file is found, and empty in-memory configuration is used.
- Overrides:
configName
in classMicroservice.Builder
- Parameters:
configName
- The configuration name.- Returns:
- This object.
-
Resolve file first in working directory, then in classpath, using the following names:
-
configStore
Description copied from class:Microservice.Builder
Specifies the config store to use for storing and retrieving configurations.By default, we use a
FileStore
store for configuration files.- Overrides:
configStore
in classMicroservice.Builder
- Parameters:
configStore
- The configuration name.- Returns:
- This object.
-
consoleEnabled
Description copied from class:Microservice.Builder
Specifies that the Java console is enabled for this microservice.If not specified, this value is taken from the
"Console/enabled" configuration setting. If not specified in the configuration, defaults tofalse .- Overrides:
consoleEnabled
in classMicroservice.Builder
- Parameters:
consoleEnabled
-true if the Java console is enabled for this microservice.- Returns:
- This object.
-
consoleCommands
Description copied from class:Microservice.Builder
Specifies console commands to make available on the Java console.Note that these are ignored if the console is not enabled via
Microservice.Builder.consoleEnabled(boolean)
.This list augments the commands defined via the
"Console/commands" configuration setting.- Overrides:
consoleCommands
in classMicroservice.Builder
- Parameters:
consoleCommands
- The list of console commands to append to the list of available commands.- Returns:
- This object.
-
console
Description copied from class:Microservice.Builder
Specifies the console input and output.If not specified, uses the console returned by
System.console()
. If that is not available, usesSystem.in
andSystem.out
.Note that these are ignored if the console is not enabled via
Microservice.Builder.consoleEnabled(boolean)
.- Overrides:
console
in classMicroservice.Builder
- Parameters:
consoleReader
- The console input.consoleWriter
- The console output.- Returns:
- This object.
-
vars
Description copied from class:Microservice.Builder
Augments the set of variables defined in the configuration and var resolver.This calls
VarResolver.Builder.vars(Class[])
on the var resolver used to construct the configuration object returned byMicroservice.getConfig()
and the var resolver returned byMicroservice.getVarResolver()
.- Overrides:
vars
in classMicroservice.Builder
- Parameters:
vars
- The set of variables to append to the var resolver builder.- Returns:
- This object.
-
varBean
Description copied from class:Microservice.Builder
Adds a bean for vars defined in the var resolver.This calls
VarResolver.Builder.bean(Class,Object)
on the var resolver used to construct the configuration object returned byMicroservice.getConfig()
and the var resolver returned byMicroservice.getVarResolver()
.- Overrides:
varBean
in classMicroservice.Builder
- Type Parameters:
T
- The bean type.- Parameters:
c
- The bean type.value
- The bean.- Returns:
- This object.
-
workingDir
Description copied from class:Microservice.Builder
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Overrides:
workingDir
in classMicroservice.Builder
- Parameters:
path
- The working directory, ornull to use the underlying working directory.- Returns:
- This object.
-
workingDir
Description copied from class:Microservice.Builder
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Overrides:
workingDir
in classMicroservice.Builder
- Parameters:
path
- The working directory, ornull to use the underlying working directory.- Returns:
- This object.
-
listener
Registers an event listener for this microservice.- Parameters:
listener
- An event listener for this microservice.- Returns:
- This object.
-