Class JettyMicroservice
- All Implemented Interfaces:
- ConfigEventListener
Jetty Server Details
The Jetty server is created by thecreateServer() method and started with the startServer() method.
 These methods can be overridden to provided customized behavior.
 Defining REST Resources
Top-level REST resources are defined in theSee Also:
- 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor.
- 
Method SummaryModifier and TypeMethodDescriptionaddServlet(jakarta.servlet.Servlet servlet, String pathSpec) Adds an arbitrary servlet to this microservice.addServletAttribute(String name, Object value) Adds a servlet attribute to the Jetty server.static JettyMicroservice.Buildercreate()Creates a new microservice builder.org.eclipse.jetty.server.ServerMethod used to create (but not start) an instance of a Jetty server.voidCallsHandler.Abstract.destroy()on the underlying Jetty server if it exists.Returns the context path that this microservice is using.Returns the hostname of this microservice.static JettyMicroserviceReturns the Microservice instance.intgetPort()Returns the port that this microservice started up on.Returns whether this microservice is using"http" or"https" .org.eclipse.jetty.server.ServerReturns the underlying Jetty server.org.eclipse.jetty.ee9.servlet.ServletContextHandlerFinds and returns the servlet context handler defined in the Jetty container.getURI()Returns the URI where this microservice is listening on.init()Initializes this microservice.join()Joins the application with the current thread.static voidEntry-point method.start()Start this application.Starts the console thread for this microservice.protected intMethod used to start the Jetty server created bycreateServer().stop()Stop this application.Stops the console thread for this microservice.Methods inherited from class org.apache.juneau.microservice.Microserviceerr, executeCommand, executeCommand, exit, getArgs, getConfig, getConsoleCommands, getConsoleReader, getConsoleWriter, getLogger, getManifest, getVarResolver, kill, log, onConfigChange, out, resolveFile
- 
Constructor Details- 
JettyMicroserviceConstructor.- Parameters:
- builder- The constructor arguments.
- Throws:
- IOException- Problem occurred reading file.
- ParseException- Malformed content found in config file.
 
 
- 
- 
Method Details- 
getInstanceReturns the Microservice instance.This method only works if there's only one Microservice instance in a JVM. Otherwise, it's just overwritten by the last instantiated microservice. - Returns:
- The Microservice instance, or null if there isn't one.
 
- 
mainEntry-point method.- Parameters:
- args- Command line arguments.
- Throws:
- Exception- Error occurred.
 
- 
createCreates a new microservice builder.- Returns:
- A new microservice builder.
 
- 
initDescription copied from class:MicroserviceInitializes this microservice.This method can be called whenever the microservice is not started. It will initialize (or reinitialize) the console commands, system properties, and logger. - Overrides:
- initin class- Microservice
- Returns:
- This object.
- Throws:
- ParseException- Malformed input encountered.
- IOException- Couldn't read a file.
 
- 
startConsoleDescription copied from class:MicroserviceStarts the console thread for this microservice.- Overrides:
- startConsolein class- Microservice
- Returns:
- This object.
- Throws:
- Exception- Error occurred
 
- 
stopConsoleDescription copied from class:MicroserviceStops the console thread for this microservice.- Overrides:
- stopConsolein class- Microservice
- Returns:
- This object.
- Throws:
- Exception- Error occurred
 
- 
startDescription copied from class:MicroserviceStart this application.Overridden methods MUST call this method FIRST so that the MicroserviceListener.onStart(Microservice)method is called.- Overrides:
- startin class- Microservice
- Returns:
- This object.
- Throws:
- Exception- Error occurred.
 
- 
joinDescription copied from class:MicroserviceJoins the application with the current thread.Default implementation is a no-op. - Overrides:
- joinin class- Microservice
- Returns:
- This object.
- Throws:
- Exception- Error occurred
 
- 
stopDescription copied from class:MicroserviceStop this application.Overridden methods MUST call this method LAST so that the MicroserviceListener.onStop(Microservice)method is called.- Overrides:
- stopin class- Microservice
- Returns:
- This object.
- Throws:
- Exception- Error occurred
 
- 
getPortReturns the port that this microservice started up on.The value is determined by looking at the Server/Connectors[ServerConnector]/port value in the Jetty configuration.- Returns:
- The port that this microservice started up on.
 
- 
getContextPathReturns the context path that this microservice is using.The value is determined by looking at the Server/Handlers[ServletContextHandler]/contextPath value in the Jetty configuration.- Returns:
- The context path that this microservice is using.
 
- 
getProtocolReturns whether this microservice is using"http" or"https" .The value is determined by looking for the existence of an SSL Connection Factorie by looking for the Server/Connectors[ServerConnector]/ConnectionFactories[SslConnectionFactory] value in the Jetty configuration.- Returns:
- Whether this microservice is using "http" or"https" .
 
- 
getHostNameReturns the hostname of this microservice.Simply uses InetAddress.getLocalHost().getHostName() .- Returns:
- The hostname of this microservice.
 
- 
getURIReturns the URI where this microservice is listening on.- Returns:
- The URI where this microservice is listening on.
 
- 
createServerpublic org.eclipse.jetty.server.Server createServer() throws ParseException, IOException, ExecutableExceptionMethod used to create (but not start) an instance of a Jetty server.Subclasses can override this method to customize the Jetty server before it is started. The default implementation is configured by the following values in the config file if a jetty.xml is not specified via a REST/jettyXml setting:#================================================================================ # Jetty settings #================================================================================ [Jetty] # Path of the jetty.xml file used to configure the Jetty server. config = jetty.xml# Resolve Juneau variables in the jetty.xml file. resolveVars = true# Port to use for the jetty 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 the # jetty.xml file as "$S{availablePort}" (assuming resolveVars is enabled). port = 10000,0,0,0- Returns:
- The newly-created server.
- Throws:
- ParseException- Configuration file contains malformed input.
- IOException- File could not be read.
- ExecutableException- Exception occurred on invoked constructor/method/field.
 
- 
destroyServerCallsHandler.Abstract.destroy()on the underlying Jetty server if it exists.- Throws:
- Exception- Error occurred.
 
- 
addServletAdds an arbitrary servlet to this microservice.- Parameters:
- servlet- The servlet instance.
- pathSpec- The context path of the servlet.
- Returns:
- This object.
- Throws:
- RuntimeException- if- createServer()has not previously been called.
 
- 
getServletContextHandlerFinds and returns the servlet context handler defined in the Jetty container.- Returns:
- The servlet context handler.
- Throws:
- RuntimeException- if context handler is not defined.
 
- 
addServletAttributeAdds a servlet attribute to the Jetty server.- Parameters:
- name- The server attribute name.
- value- The context path of the servlet.
- Returns:
- This object.
- Throws:
- RuntimeException- if- createServer()has not previously been called.
 
- 
getServerReturns the underlying Jetty server.- Returns:
- The underlying Jetty server, or null ifcreateServer()has not yet been called.
 
- 
startServerMethod used to start the Jetty server created bycreateServer().Subclasses can override this method to customize server startup. - Returns:
- The port that this server started on.
- Throws:
- Exception- Error occurred.
 
 
-