Java Reference
In-Depth Information
Figure 11-5.
Echoing an incoming request's headers back to the client.
Before invoking
start()
, you can specify a
HTTPrequests.Thistaskisaccomplishedbycalling
HttpServer
's
void setEx-
ecutor(Executor executor)
method.Youcanalsocall
Executor getEx-
ecutor()
to return the current executor (the return value is null when no executor
hasbeenset).Ifyoudonotcall
setExecutor()
beforestartingtheserver,orifyou
pass
null
to this method, a default implementation based on the thread created by
start()
is used.
You can stop a started server by invoking
HttpServer
's
void stop(int
delay)
method.Thismethodclosesthelisteningsocketandpreventsanyqueuedex-
changes from being processed. It then blocks until all current exchange handlers have
finished or
delay
seconds have elapsed (whichever comes first). An instance of the
java.lang.IllegalArgumentException
classisthrownwhen
delay
isless
than zero. Continuing, all open TCP connections are closed, and the thread created by
the
start()
method finishes. A stopped
HttpServer
cannot be restarted.
Most of this chapter's examples rely on the default lightweight HTTP server that's
created whenever you call one of
javax.xml.ws.EndPoint
class's
publish()
methods. However, I'll also show you how to create and install a custom lightweight
HTTP server to perform authentication later in this chapter.