public class JettyMicroservice extends Microservice
createServer()
method and started with the startServer()
method.
These methods can be overridden to provided customized behavior.
Modifier | Constructor and Description |
---|---|
protected |
JettyMicroservice(JettyMicroserviceBuilder builder)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
JettyMicroservice |
addServlet(Servlet servlet,
String pathSpec)
Adds an arbitrary servlet to this microservice.
|
JettyMicroservice |
addServletAttribute(String name,
Object value)
Adds a servlet attribute to the Jetty server.
|
static JettyMicroserviceBuilder |
create()
Creates a new microservice builder.
|
org.eclipse.jetty.server.Server |
createServer()
Method used to create (but not start) an instance of a Jetty server.
|
void |
destroyServer()
Calls
HandlerWrapper.destroy() on the underlying Jetty server if it exists. |
String |
getContextPath()
Returns the context path that this microservice is using.
|
String |
getHostName()
Returns the hostname of this microservice.
|
static JettyMicroservice |
getInstance()
Returns the Microservice instance.
|
int |
getPort()
Returns the port that this microservice started up on.
|
String |
getProtocol()
Returns whether this microservice is using
|
org.eclipse.jetty.server.Server |
getServer()
Returns the underlying Jetty server.
|
protected org.eclipse.jetty.servlet.ServletContextHandler |
getServletContextHandler()
Finds and returns the servlet context handler define in the Jetty container.
|
URI |
getURI()
Returns the URI where this microservice is listening on.
|
JettyMicroservice |
init()
Initializes this microservice.
|
JettyMicroservice |
join()
Joins the application with the current thread.
|
static void |
main(String[] args)
Entry-point method.
|
JettyMicroservice |
start()
Start this application.
|
JettyMicroservice |
startConsole()
Starts the console thread for this microservice.
|
protected int |
startServer()
Method used to start the Jetty server created by
createServer() . |
JettyMicroservice |
stop()
Stop this application.
|
JettyMicroservice |
stopConsole()
Stops the console thread for this microservice.
|
err, executeCommand, executeCommand, exit, getArgs, getConfig, getConsoleCommands, getConsoleReader, getConsoleWriter, getLogger, getManifest, getVarResolver, kill, log, onConfigChange, out, resolveFile
protected JettyMicroservice(JettyMicroserviceBuilder builder) throws ParseException, IOException
builder
- The constructor arguments.IOException
- Problem occurred reading file.ParseException
- Malformed content found in config file.public static JettyMicroservice getInstance()
This method only works if there's only one Microservice instance in a JVM. Otherwise, it's just overwritten by the last instantiated microservice.
public static void main(String[] args) throws Exception
args
- Command line arguments.Exception
- Error occurred.public static JettyMicroserviceBuilder create()
public JettyMicroservice init() throws ParseException, IOException
Microservice
This method can be called whenever the microservice is not started.
It will initialize (or reinitialize) the console commands, system properties, and logger.
init
in class Microservice
ParseException
- Malformed input encountered.IOException
- Couldn't read a file.public JettyMicroservice startConsole() throws Exception
Microservice
startConsole
in class Microservice
Exception
- Error occurredpublic JettyMicroservice stopConsole() throws Exception
Microservice
stopConsole
in class Microservice
Exception
- Error occurredpublic JettyMicroservice start() throws Exception
Microservice
Overridden methods MUST call this method FIRST so that the MicroserviceListener.onStart(Microservice)
method is called.
start
in class Microservice
Exception
- Error occurred.public JettyMicroservice join() throws Exception
Microservice
Default implementation is a no-op.
join
in class Microservice
Exception
- Error occurredpublic JettyMicroservice stop() throws Exception
Microservice
Overridden methods MUST call this method LAST so that the MicroserviceListener.onStop(Microservice)
method is called.
stop
in class Microservice
Exception
- Error occurredpublic int getPort()
The value is determined by looking at the
public String getContextPath()
The value is determined by looking at the
public String getProtocol()
The value is determined by looking for the existence of an SSL Connection Factorie by looking for the
public String getHostName()
Simply uses
public URI getURI()
public org.eclipse.jetty.server.Server createServer() throws ParseException, IOException, ExecutableException
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
ParseException
- Configuration file contains malformed input.IOException
- File could not be read.ExecutableException
- Exception occurred on invoked constructor/method/field.public void destroyServer() throws Exception
HandlerWrapper.destroy()
on the underlying Jetty server if it exists.Exception
- Error occurred.public JettyMicroservice addServlet(Servlet servlet, String pathSpec)
servlet
- The servlet instance.pathSpec
- The context path of the servlet.RuntimeException
- if createServer()
has not previously been called.protected org.eclipse.jetty.servlet.ServletContextHandler getServletContextHandler()
RuntimeException
- if context handler is not defined.public JettyMicroservice addServletAttribute(String name, Object value)
name
- The server attribute name.value
- The context path of the servlet.RuntimeException
- if createServer()
has not previously been called.public org.eclipse.jetty.server.Server getServer()
createServer()
has not yet been called.protected int startServer() throws Exception
createServer()
.
Subclasses can override this method to customize server startup.
Exception
- Error occurred.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.