APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.net.httpserver

pack-priv Class ServerImpl

extends Object
Class Inheritance
Imports
com.sun.net.httpserver.Filter, .Headers, .HttpContext, .HttpExchange, .HttpHandler, .HttpServer, .HttpsConfigurator, sun.net.httpserver.HttpConnection.State, javax.net.ssl.SSLContext, .SSLEngine, java.io.BufferedInputStream, .BufferedOutputStream, .IOException, .InputStream, .OutputStream, java.lang.System.Logger, .System.Logger.Level, java.net.BindException, .InetSocketAddress, .ProtocolException, .ServerSocket, .URI, .URISyntaxException, java.nio.channels.CancelledKeyException, .SelectionKey, .Selector, .ServerSocketChannel, .SocketChannel, java.util.ArrayList, .Collections, .HashSet, .List, .Set, .Timer, .TimerTask, java.util.concurrent.CountDownLatch, .Executor, .TimeUnit

Provides implementation for both HTTP and HTTPS

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv class
ServerImpl.Dispatcher

The Dispatcher is responsible for accepting any connections and then using those connections to processing any incoming requests.

pack-priv class
pack-priv class
ServerImpl.IdleTimeoutTask

Responsible for closing connections that have been idle.

pack-priv class
ServerImpl.ReqRspTimeoutTask

Responsible for closing connections which have timed out while in REQUEST or RESPONSE state

Field Summary

Modifier and TypeField and Description
private InetSocketAddress
private final Set<HttpConnection>
private boolean
private ContextList
pack-priv static boolean
pack-priv ServerImpl.Dispatcher
private Thread
private List<Event>
private int
private Executor
private final CountDownLatch
private boolean
private HttpsConfigurator
pack-priv static final long
pack-priv static final long
private final Set<HttpConnection>
private SelectionKey
private final System.Logger
private final Object
pack-priv static final int
pack-priv static final int
pack-priv static final long
pack-priv static final long
pack-priv static final long
private final Set<HttpConnection>
private String
pack-priv static final long
private final Set<HttpConnection>
pack-priv static final boolean
private final Set<HttpConnection>
private ServerSocketChannel
private Selector
private SSLContext
private boolean
private volatile boolean
private Timer
private Timer
private HttpServer

Constructor Summary

AccessConstructor and Description
pack-priv
ServerImpl(HttpServer wrapper, String protocol, InetSocketAddress addr, int backlog)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public void
bind(InetSocketAddress addr, int backlog)

private void
public synchronized HttpContextImpl
public synchronized HttpContextImpl
pack-priv static synchronized void
pack-priv static synchronized void
pack-priv synchronized int
private final boolean
public InetSocketAddress
pack-priv synchronized int
public Executor
public HttpsConfigurator
pack-priv System.Logger
private static long
getTimeMillis(long secs)

Converts and returns the passed secs as milli seconds.

pack-priv HttpServer
public final boolean
pack-priv void
logReply(int code, String requestStr, String text)

pack-priv void
pack-priv void
public synchronized void
public synchronized void
pack-priv void
pack-priv void
pack-priv void
public void
public void
public void
pack-priv synchronized void
public void
stop(int
maximum delay to wait for exchanges completion, in seconds
delay
)

This method stops the server by adding a stop request event and waiting for the server until the event is triggered or until the maximum delay is triggered.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressback to summary
private InetSocketAddress address
allConnectionsback to summary
private final Set<HttpConnection> allConnections
boundback to summary
private boolean bound
contextsback to summary
private ContextList contexts
debugback to summary
pack-priv static boolean debug
dispatcherback to summary
pack-priv ServerImpl.Dispatcher dispatcher
dispatcherThreadback to summary
private Thread dispatcherThread
eventsback to summary
private List<Event> events
exchangeCountback to summary
private int exchangeCount
executorback to summary
private Executor executor
finishedLatchback to summary
private final CountDownLatch finishedLatch
httpsback to summary
private boolean https
httpsConfigback to summary
private HttpsConfigurator httpsConfig
IDLE_INTERVALback to summary
pack-priv static final long IDLE_INTERVAL
IDLE_TIMER_TASK_SCHEDULEback to summary
pack-priv static final long IDLE_TIMER_TASK_SCHEDULE
idleConnectionsback to summary
private final Set<HttpConnection> idleConnections
listenerKeyback to summary
private SelectionKey listenerKey
loggerback to summary
private final System.Logger logger
lolockback to summary
private final Object lolock
MAX_CONNECTIONSback to summary
pack-priv static final int MAX_CONNECTIONS
MAX_IDLE_CONNECTIONSback to summary
pack-priv static final int MAX_IDLE_CONNECTIONS
MAX_REQ_TIMEback to summary
pack-priv static final long MAX_REQ_TIME
MAX_RSP_TIMEback to summary
pack-priv static final long MAX_RSP_TIME
NEWLY_ACCEPTED_CONN_IDLE_INTERVALback to summary
pack-priv static final long NEWLY_ACCEPTED_CONN_IDLE_INTERVAL
newlyAcceptedConnectionsback to summary
private final Set<HttpConnection> newlyAcceptedConnections
protocolback to summary
private String protocol
REQ_RSP_TIMER_SCHEDULEback to summary
pack-priv static final long REQ_RSP_TIMER_SCHEDULE
reqConnectionsback to summary
private final Set<HttpConnection> reqConnections
reqRspTimeoutEnabledback to summary
pack-priv static final boolean reqRspTimeoutEnabled
rspConnectionsback to summary
private final Set<HttpConnection> rspConnections
schanback to summary
private ServerSocketChannel schan
selectorback to summary
private Selector selector
sslContextback to summary
private SSLContext sslContext
startedback to summary
private boolean started
terminatingback to summary
private volatile boolean terminating
timerback to summary
private Timer timer
timer1back to summary
private Timer timer1
wrapperback to summary
private HttpServer wrapper

Constructor Detail

ServerImplback to summary
pack-priv ServerImpl(HttpServer wrapper, String protocol, InetSocketAddress addr, int backlog) throws IOException

Method Detail

addEventback to summary
pack-priv void addEvent(Event r)
bindback to summary
public void bind(InetSocketAddress addr, int backlog) throws IOException
closeConnectionback to summary
private void closeConnection(HttpConnection conn)
createContextback to summary
public synchronized HttpContextImpl createContext(String path, HttpHandler handler)
createContextback to summary
public synchronized HttpContextImpl createContext(String path)
dprintback to summary
pack-priv static synchronized void dprint(String s)
dprintback to summary
pack-priv static synchronized void dprint(Exception e)
endExchangeback to summary
pack-priv synchronized int endExchange()
finishedback to summary
private final boolean finished()
getAddressback to summary
public InetSocketAddress getAddress()
getExchangeCountback to summary
pack-priv synchronized int getExchangeCount()
getExecutorback to summary
public Executor getExecutor()
getHttpsConfiguratorback to summary
public HttpsConfigurator getHttpsConfigurator()
getLoggerback to summary
pack-priv System.Logger getLogger()
getTimeMillisback to summary
private static long getTimeMillis(long secs)

Converts and returns the passed secs as milli seconds. If the passed secs is negative or zero or if the conversion from seconds to milli seconds results in a negative number, then this method returns -1.

getWrapperback to summary
pack-priv HttpServer getWrapper()
isFinishingback to summary
public final boolean isFinishing()
logReplyback to summary
pack-priv void logReply(int code, String requestStr, String text)
markIdleback to summary
pack-priv void markIdle(HttpConnection c)
markNewlyAcceptedback to summary
pack-priv void markNewlyAccepted(HttpConnection c)
removeContextback to summary
public synchronized void removeContext(String path) throws IllegalArgumentException
removeContextback to summary
public synchronized void removeContext(HttpContext context) throws IllegalArgumentException
requestCompletedback to summary
pack-priv void requestCompleted(HttpConnection c)
requestStartedback to summary
pack-priv void requestStarted(HttpConnection c)
responseCompletedback to summary
pack-priv void responseCompleted(HttpConnection c)
setExecutorback to summary
public void setExecutor(Executor executor)
setHttpsConfiguratorback to summary
public void setHttpsConfigurator(HttpsConfigurator config)
startback to summary
public void start()
startExchangeback to summary
pack-priv synchronized void startExchange()
stopback to summary
public void stop(int delay)

This method stops the server by adding a stop request event and waiting for the server until the event is triggered or until the maximum delay is triggered.

This ensures that the server is stopped immediately after all exchanges are complete. HttpConnections will be forcefully closed if active exchanges do not complete within the imparted delay.

Parameters
delay:int

maximum delay to wait for exchanges completion, in seconds

sun.net.httpserver back to summary

private Class ServerImpl.DefaultExecutor

extends Object
implements Executor
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Executor

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultExecutorback to summary
private DefaultExecutor()

Method Detail

executeback to summary
public void execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

sun.net.httpserver back to summary

pack-priv Class ServerImpl.Dispatcher

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

The Dispatcher is responsible for accepting any connections and then using those connections to processing any incoming requests. A connection is represented as an instance of sun.net.httpserver.HttpConnection. Connection states: An instance of HttpConnection goes through the following states: - NEWLY_ACCEPTED: A connection is marked as newly accepted as soon as the Dispatcher accept()s a connection. A newly accepted connection is added to a newlyAcceptedConnections collection. A newly accepted connection also gets added to the allConnections collection. The newlyAcceptedConnections isn't checked for any size limits, however, if the server is configured with a maximum connection limit, then the elements in the newlyAcceptedConnections will never exceed that configured limit (no explicit size checks are done on the newlyAcceptedConnections collection, since the maximum connection limit applies to connections across different connection states). A connection in NEWLY_ACCEPTED state is considered idle and is eligible for idle connection management. - REQUEST: A connection is marked to be in REQUEST state when the request processing starts on that connection. This typically happens when the first byte of data is received on a NEWLY_ACCEPTED connection or when new data arrives on a connection which was previously in IDLE state. When a connection is in REQUEST state, it implies that the connection is active and thus isn't eligible for idle connection management. If the server is configured with a maximum request timeout, then connections in REQUEST state are eligible for Request/Response timeout management. - RESPONSE: A connection is marked to be in RESPONSE state when the server has finished reading the request. A connection is RESPONSE state is considered active and isn't eligible for idle connection management. If the server is configured with a maximum response timeout, then connections in RESPONSE state are eligible for Request/Response timeout management. - IDLE: A connection is marked as IDLE when a request/response cycle (successfully) completes on that particular connection. Idle connections are held in a idleConnections collection. The idleConnections collection is limited in size and the size is decided by a server configuration. Connections in IDLE state get added to the idleConnections collection only if that collection hasn't reached the configured limit. If a connection has reached IDLE state and there's no more room in the idleConnections collection, then such a connection gets closed. Connections in idleConnections collection are eligible for idle connection management. Idle connection management: A timer task is responsible for closing idle connections. Each connection that is in a state which is eligible for idle timeout management (see above section on connection states) will have a corresponding idle expiration time associated with it. The idle timeout management task will check the expiration time of each such connection against the current time and will close the connection if the current time is either equal to or past the expiration time. Request/Response timeout management: The server can be optionally configured with a maximum request timeout and/or maximum response timeout. If either of these timeouts have been configured, then an additional timer task is run by the server. This timer task is then responsible for closing connections which have been in REQUEST or RESPONSE state for a period of time that exceeds the respective configured timeouts. Maximum connection limit management: The server can be optionally configured with a maximum connection limit. A value of 0 or negative integer is ignored and considered to represent no connection limit. In case of a positive integer value, any newly accepted connections will be first checked against the current count of established connections (held by the allConnections collection) and if the configured limit has reached, then the newly accepted connection will be closed immediately (even before setting its state to NEWLY_ACCEPTED or adding it to the newlyAcceptedConnections collection).

Field Summary

Modifier and TypeField and Description
pack-priv final ArrayList<HttpConnection>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
private void
private void
pack-priv void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connsToRegisterback to summary
pack-priv final ArrayList<HttpConnection> connsToRegister

Constructor Detail

Dispatcherback to summary
pack-priv Dispatcher()

Method Detail

handleback to summary
public void handle(SocketChannel chan, HttpConnection conn)
handleEventback to summary
private void handleEvent(Event r)
handleExceptionback to summary
private void handleException(SelectionKey key, Exception e)
reRegisterback to summary
pack-priv void reRegister(HttpConnection c)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

sun.net.httpserver back to summary

pack-priv Class ServerImpl.Exchange

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv SocketChannel
pack-priv HttpConnection
pack-priv HttpContextImpl
pack-priv HttpContextImpl
pack-priv String
pack-priv InputStream
pack-priv OutputStream
pack-priv boolean
pack-priv ExchangeImpl

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
reject(int code, String requestStr, String message)

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

pack-priv void
sendReply(int code, boolean closeNow, String text)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chanback to summary
pack-priv SocketChannel chan
connectionback to summary
pack-priv HttpConnection connection
contextback to summary
pack-priv HttpContextImpl context
ctxback to summary
pack-priv HttpContextImpl ctx
protocolback to summary
pack-priv String protocol
rawinback to summary
pack-priv InputStream rawin
rawoutback to summary
pack-priv OutputStream rawout
rejectedback to summary
pack-priv boolean rejected
txback to summary
pack-priv ExchangeImpl tx

Constructor Detail

Exchangeback to summary
pack-priv Exchange(SocketChannel chan, String protocol, HttpConnection conn) throws IOException

Method Detail

rejectback to summary
pack-priv void reject(int code, String requestStr, String message)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

sendReplyback to summary
pack-priv void sendReply(int code, boolean closeNow, String text)
sun.net.httpserver back to summary

pack-priv Class ServerImpl.Exchange.LinkHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
com.sun.net.httpserver.HttpHandler

Field Summary

Modifier and TypeField and Description
pack-priv Filter.Chain

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
handle(HttpExchange exchange)

Implements com.sun.net.httpserver.HttpHandler.handle.

Handle the given request and generate an appropriate response.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextChainback to summary
pack-priv Filter.Chain nextChain

Constructor Detail

LinkHandlerback to summary
pack-priv LinkHandler(Filter.Chain nextChain)

Method Detail

handleback to summary
public void handle(HttpExchange exchange) throws IOException

Implements com.sun.net.httpserver.HttpHandler.handle.

Doc from com.sun.net.httpserver.HttpHandler.handle.

Handle the given request and generate an appropriate response. See HttpExchange for a description of the steps involved in handling an exchange.

Exceptions
IOException:
if an I/O error occurs
sun.net.httpserver back to summary

pack-priv Class ServerImpl.IdleTimeoutTask

extends TimerTask
Class Inheritance

Responsible for closing connections that have been idle. TimerTask run every CLOCK_TICK ms

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
closeConnections(Set<HttpConnection> connections, long idleInterval)

public void
run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

The action to be performed by this timer task.

Inherited from java.util.TimerTask:
cancelscheduledExecutionTime

Constructor Detail

IdleTimeoutTaskback to summary
pack-priv IdleTimeoutTask()

Method Detail

closeConnectionsback to summary
private void closeConnections(Set<HttpConnection> connections, long idleInterval)
runback to summary
public void run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

Doc from java.util.TimerTask.run.

The action to be performed by this timer task.

sun.net.httpserver back to summary

pack-priv Class ServerImpl.ReqRspTimeoutTask

extends TimerTask
Class Inheritance

Responsible for closing connections which have timed out while in REQUEST or RESPONSE state

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

The action to be performed by this timer task.

Inherited from java.util.TimerTask:
cancelscheduledExecutionTime

Constructor Detail

ReqRspTimeoutTaskback to summary
pack-priv ReqRspTimeoutTask()

Method Detail

runback to summary
public void run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

Doc from java.util.TimerTask.run.

The action to be performed by this timer task.