- All Implemented Interfaces:
Handler,Handler.Container,Handler.Singleton,Request.Handler,org.eclipse.jetty.util.Attributes,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle,org.eclipse.jetty.util.thread.Invocable
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract
Handler.Abstract.NonBlockingNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
org.eclipse.jetty.util.Attributes.Layer, org.eclipse.jetty.util.Attributes.Lazy, org.eclipse.jetty.util.Attributes.Mapped, org.eclipse.jetty.util.Attributes.Synthetic, org.eclipse.jetty.util.Attributes.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler
Handler.Abstract, Handler.AbstractContainer, Handler.Collection, Handler.Container, Handler.Sequence, Handler.Singleton, Handler.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
org.eclipse.jetty.util.thread.Invocable.Callable, org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Field Summary
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.Attributes
NULLFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEYFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP -
Constructor Summary
ConstructorsConstructorDescriptionServer()Server(int port) Convenience constructor Creates server and aServerConnectorat the passed port.Server(InetSocketAddress addr) Convenience constructorServer(org.eclipse.jetty.util.thread.ThreadPool pool) Server(org.eclipse.jetty.util.thread.ThreadPool threadPool, org.eclipse.jetty.util.thread.Scheduler scheduler, org.eclipse.jetty.io.ByteBufferPool bufferPool) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBeanToAllConnectors(Object bean) Add a bean to all connectors on the server.voidaddConnector(Connector connector) voidprotected voiddoStart()protected voiddoStop()voiddump(Appendable out, String indent) getAttribute(String name) org.eclipse.jetty.io.ByteBufferPoolorg.eclipse.jetty.http.HttpFieldorg.eclipse.jetty.util.resource.ResourceGet the default Faviconorg.eclipse.jetty.util.resource.ResourceGet the Default CSSorg.eclipse.jetty.util.thread.Invocable.InvocationTypeorg.eclipse.jetty.http.MimeTypes.Mutableorg.eclipse.jetty.util.thread.Schedulerbooleanlongorg.eclipse.jetty.util.thread.ThreadPoolgetURI()static StringbooleanInvoked to handle the passed HTTP request and response.booleanisDryRun()booleanbooleanvoidjoin()static voidremoveAttribute(String name) voidremoveConnector(Connector connector) Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.setAttribute(String name, Object attribute) voidsetConnectors(Connector[] connectors) Set the connectors for this server.voidsetDefaultHandler(Handler defaultHandler) voidsetDryRun(boolean dryRun) voidsetDumpAfterStart(boolean dumpAfterStart) Set true ifContainerLifeCycle.dumpStdErr()is called after starting.voidsetDumpBeforeStop(boolean dumpBeforeStop) Set true ifContainerLifeCycle.dumpStdErr()is called before stopping.voidsetErrorHandler(Request.Handler errorHandler) voidsetRequestLog(RequestLog requestLog) voidsetServerInfo(String serverInfo) voidsetStopAtShutdown(boolean stop) Set stop server at shutdown behaviour.voidsetStopTimeout(long stopTimeout) voidsetTempDirectory(File temp) Set the temporary directory returned byContext.getTempDirectory()for the rootContextreturnedgetContext().voidsetTempDirectory(String temp) Convenience method to callsetTempDirectory(File)from a String representation of the temporary directory.protected voidstart(org.eclipse.jetty.util.component.LifeCycle l) toString()Methods inherited from class org.eclipse.jetty.server.Handler.Wrapper
getHandler, setHandlerMethods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServerMethods inherited from class org.eclipse.jetty.server.Handler.Abstract
destroyMethods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Attributes
asAttributeMap, equals, hashCodeMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Destroyable
destroyMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods inherited from interface org.eclipse.jetty.server.Handler.Container
getContainer, getDescendant, getDescendants, getDescendantsMethods inherited from interface org.eclipse.jetty.server.Handler.Singleton
getHandlers, getTail, insertHandler, setHandlerMethods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Constructor Details
-
Server
public Server() -
Server
public Server(@Name("port") int port) Convenience constructor Creates server and aServerConnectorat the passed port.- Parameters:
port- The port of a network HTTP connector (or 0 for a randomly allocated port).- See Also:
-
Server
Convenience constructorCreates server and a
ServerConnectorat the passed address.- Parameters:
addr- the inet socket address to create the connector from
-
Server
public Server(@Name("threadPool") org.eclipse.jetty.util.thread.ThreadPool pool) -
Server
public Server(@Name("threadPool") org.eclipse.jetty.util.thread.ThreadPool threadPool, @Name("scheduler") org.eclipse.jetty.util.thread.Scheduler scheduler, @Name("bufferPool") org.eclipse.jetty.io.ByteBufferPool bufferPool)
-
-
Method Details
-
getDefaultHandler
-
setDefaultHandler
- Parameters:
defaultHandler- The handler to use if no other handler is set or has handled the request. This handler should always accept the request, even if only to send a 404.
-
handle
public boolean handle(Request request, Response response, org.eclipse.jetty.util.Callback callback) throws Exception Description copied from interface:Request.HandlerInvoked to handle the passed HTTP request and response.
The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed.
Exceptions thrown by this method may be subsequently handled by an error
Request.Handler, if present, otherwise a default HTTP 500 error is generated and the callback completed while writing the error response.The simplest implementation is:
public boolean handle(Request request, Response response, Callback callback) { callback.succeeded(); return true; }A HelloWorld implementation is:
public boolean handle(Request request, Response response, Callback callback) { response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback); return true; }- Specified by:
handlein interfaceRequest.Handler- Overrides:
handlein classHandler.Wrapper- Parameters:
request- the HTTP request to handleresponse- the HTTP response to handlecallback- the callback to complete when the handling is complete- Returns:
- True if and only if the request will be handled, a response generated and the callback eventually called. This may occur within the scope of the call to this method, or asynchronously some time later. If false is returned, then this method must not generate a response, nor complete the callback.
- Throws:
Exception- if there is a failure during the handling. Catchers cannot assume that the callback will be called and thus should attempt to complete the request as if a false had been returned.
-
getServerInfo
-
setTempDirectory
Convenience method to call
setTempDirectory(File)from a String representation of the temporary directory.- Parameters:
temp- A string representation of the temporary directory.- See Also:
-
setTempDirectory
Set the temporary directory returned by
Context.getTempDirectory()for the rootContextreturnedgetContext(). If not set explicitly here, then the rootContext.getTempDirectory()will return either the directory found atnew File(IO.asFile(System.getProperty("jetty.base")), "work")if it exists, else the JVMs temporary directory asIO.asFile(System.getProperty("java.io.tmpdir")).- Parameters:
temp- A directory that must exist and be writable or null to get the default.
-
getTempDirectory
@ManagedAttribute(value="The server temporary directory", readonly=true) public File getTempDirectory()- Returns:
- The server temporary directory if set, else null. To always obtain a non-null
temporary directory use
Context.getTempDirectory()ongetContext(). - See Also:
-
setServerInfo
-
getContext
Get theContextassociated with allRequests prior to being handled by aContextHandler. AServer'sContext:- has a
nullcontext path - returns the
ClassLoaderthat loaded theServerfromContext.getClassLoader(). - is an
Executorthat delegates to theServer ThreadPool - is a
Decoratorusing theDecoratedObjectFactoryfound as abeanof theServer - has the same
temporary directorof theserver
- has a
-
getMimeTypes
public org.eclipse.jetty.http.MimeTypes.Mutable getMimeTypes() -
getInvocationType
public org.eclipse.jetty.util.thread.Invocable.InvocationType getInvocationType()- Specified by:
getInvocationTypein interfaceorg.eclipse.jetty.util.thread.Invocable- Specified by:
getInvocationTypein interfaceRequest.Handler- Overrides:
getInvocationTypein classHandler.Wrapper
-
isDryRun
public boolean isDryRun() -
setDryRun
public void setDryRun(boolean dryRun) -
getRequestLog
-
getErrorHandler
-
setRequestLog
-
setErrorHandler
-
getVersion
-
setStopTimeout
public void setStopTimeout(long stopTimeout) -
getStopTimeout
public long getStopTimeout() -
getStopAtShutdown
public boolean getStopAtShutdown() -
setStopAtShutdown
public void setStopAtShutdown(boolean stop) Set stop server at shutdown behaviour.- Parameters:
stop- If true, this server instance will be explicitly stopped when the JVM is shutdown. Otherwise the JVM is stopped with the server running.- See Also:
-
getConnectors
@ManagedAttribute(value="connectors for this server", readonly=true) public Connector[] getConnectors()- Returns:
- Returns the connectors.
-
addConnector
-
removeConnector
Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.- Parameters:
connector- The connector to remove.
-
setConnectors
Set the connectors for this server. Each connector has this server set as it's ThreadPool and its Handler.- Parameters:
connectors- The connectors to set.
-
addBeanToAllConnectors
Add a bean to all connectors on the server. If the bean is an instance ofConnection.Listenerit will also be registered as a listener on all connections accepted by the connectors.- Parameters:
bean- the bean to be added.
-
getThreadPool
@ManagedAttribute("The server Thread pool") public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()- Returns:
- Returns the threadPool.
-
getScheduler
@ManagedAttribute("The server Scheduler") public org.eclipse.jetty.util.thread.Scheduler getScheduler() -
getByteBufferPool
@ManagedAttribute("The server ByteBuffer pool") public org.eclipse.jetty.io.ByteBufferPool getByteBufferPool() -
isDumpAfterStart
@ManagedAttribute("Whether to dump the server to stderr after start") public boolean isDumpAfterStart()- Returns:
- true if
ContainerLifeCycle.dumpStdErr()is called after starting
-
setDumpAfterStart
public void setDumpAfterStart(boolean dumpAfterStart) Set true ifContainerLifeCycle.dumpStdErr()is called after starting.- Parameters:
dumpAfterStart- true ifContainerLifeCycle.dumpStdErr()is called after starting
-
isDumpBeforeStop
@ManagedAttribute("Whether to dump the server to stderr before stop") public boolean isDumpBeforeStop()- Returns:
- true if
ContainerLifeCycle.dumpStdErr()is called before stopping
-
setDumpBeforeStop
public void setDumpBeforeStop(boolean dumpBeforeStop) Set true ifContainerLifeCycle.dumpStdErr()is called before stopping.- Parameters:
dumpBeforeStop- true ifContainerLifeCycle.dumpStdErr()is called before stopping
-
getDateField
public org.eclipse.jetty.http.HttpField getDateField()- Returns:
- A
HttpFieldinstance efficiently recording the current time to a second resolution, that cannot be cleared from aResponseHttpFieldsinstance. - See Also:
-
doStart
- Overrides:
doStartin classHandler.Abstract- Throws:
Exception
-
start
-
doStop
- Overrides:
doStopin classHandler.Abstract- Throws:
Exception
-
join
- Throws:
InterruptedException
-
setAttribute
-
removeAttribute
-
getAttribute
-
getAttributeNameSet
-
clearAttributes
public void clearAttributes()- Specified by:
clearAttributesin interfaceorg.eclipse.jetty.util.Attributes
-
getURI
- Returns:
- The URI of the first
NetworkConnectorand firstContextHandler, or null
-
getServer
- Specified by:
getServerin interfaceHandler- Overrides:
getServerin classHandler.Abstract- Returns:
- the
Serverassociated with thisHandler
-
getDefaultStyleSheet
public org.eclipse.jetty.util.resource.Resource getDefaultStyleSheet()Get the Default CSS- Returns:
- the default CSS
-
getDefaultFavicon
public org.eclipse.jetty.util.resource.Resource getDefaultFavicon()Get the default Favicon- Returns:
- the default Favicon
-
toString
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
dump
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
IOException
-
main
-