Constructor and Description |
---|
HttpServer() |
Modifier and Type | Method and Description |
---|---|
protected void |
addDefaultFilterTokens() |
HttpServer |
addResources(String contextRoot,
String baseDirectory,
String... filteredExtensions)
Adds resources to the server.
|
HttpServer |
addSecuredRealm(String pathSpec,
String... roles)
Sets up a security realm.
|
HttpServer |
addUser(String username,
String password,
String... roles)
Registers a user.
|
HttpServer |
enableRecording(String... patterns)
Enables request recording for the specified URI patterns.
|
int |
getHttpPort()
Gets the port number of the server's HTTP connector.
|
int |
getHttpsPort()
Gets the port number of the server's HTTPS connector.
|
String |
getHttpsUrl()
Gets the base URL to the server's HTTPS connector, e.g.
|
String |
getHttpUrl()
Gets the base URL to the server's HTTP connector, e.g.
|
Map<String,String> |
getRecordedHeaders(String uri)
Gets the headers sent in the most recent request to the specified path.
|
List<String> |
getRecordedRequests()
Gets the sequence of requests that have been issued against context roots for which
enableRecording(String...) was called. |
protected org.eclipse.jetty.server.Connector |
newHttpConnector() |
protected org.eclipse.jetty.server.Connector |
newHttpsConnector() |
protected org.eclipse.jetty.server.Handler |
newProxyHandler() |
protected org.eclipse.jetty.server.Handler |
newResourceHandler() |
protected org.eclipse.jetty.server.Handler |
newSecurityHandler() |
protected org.eclipse.jetty.server.Handler |
newSleepHandler(long millis) |
protected org.eclipse.jetty.server.Handler |
newSslRedirectHandler() |
void |
resetRecording() |
HttpServer |
setFilterToken(String token,
String value)
Sets a token to replace during resource filtering.
|
HttpServer |
setHttpPort(int httpPort)
Sets the port to use for HTTP connections.
|
HttpServer |
setHttpsPort(int httpsPort)
Sets the port to use for HTTPS connections.
|
HttpServer |
setKeyStore(String path,
String password)
Sets the keystore to use for the server certificate on the SSL connector.
|
HttpServer |
setLatency(long millis)
Sets the latency of the server.
|
HttpServer |
setNeedClientAuth(boolean needClientAuth)
Enables/disables client-side certificate authentication.
|
HttpServer |
setProxyAuth(String username,
String password)
Sets the credentials to use for proxy authentication.
|
HttpServer |
setRedirectToHttps(boolean redirectToHttps)
Enforces redirection from HTTP to HTTPS.
|
HttpServer |
setStorePassword(String password)
Sets the password to use for the SSL connector store.
|
HttpServer |
setTrustStore(String path,
String password)
Sets the truststore to use for validating client credentials via the SSL connector.
|
HttpServer |
start()
Starts the server.
|
void |
stop()
Stops the server.
|
protected void |
waitForConnectors() |
protected org.eclipse.jetty.server.Connector newHttpConnector()
protected org.eclipse.jetty.server.Connector newHttpsConnector()
public HttpServer setHttpPort(int httpPort)
httpPort
- The port to use, may be 0
to pick a random port (default), if negative the HTTP connector
will be disabled.null
.public int getHttpPort()
public String getHttpUrl()
"http://localhost:8080"
.null
.public HttpServer setHttpsPort(int httpsPort)
httpPort
- The port to use, may be 0
to pick a random port, if negative the HTTPS connector will be
disabled (default).null
.public int getHttpsPort()
public String getHttpsUrl()
"https://localhost:8080"
.null
.public HttpServer setKeyStore(String path, String password)
path
- The path to the keystore to use for the server certificate, may be null
.password
- The password for the keystore, may be null
.null
.public HttpServer setTrustStore(String path, String password)
path
- The path to the truststore to use for the trusted client certificates, may be null
.password
- The password for the truststore, may be null
.null
.public HttpServer setStorePassword(String password)
password
- The password for the store, may be null
.null
.public HttpServer setNeedClientAuth(boolean needClientAuth)
needClientAuth
- Whether the server should reject clients whose certificate can't be verified via the
truststore.null
.public HttpServer setProxyAuth(String username, String password)
null
, no proxy
authentication is required.username
- The username, may be null
.password
- The password, may be null
.null
.protected org.eclipse.jetty.server.Handler newProxyHandler()
public HttpServer setRedirectToHttps(boolean redirectToHttps)
redirectToHttps
- true
to redirect any HTTP requests to HTTPS, false
to handle HTTP normally.null
.protected org.eclipse.jetty.server.Handler newSslRedirectHandler()
public HttpServer addUser(String username, String password, String... roles)
username
- The username, must not be null
.password
- The password, must not be null
.roles
- The roles of the user, may be empty or null
.null
.public HttpServer addSecuredRealm(String pathSpec, String... roles)
pathSpec
- The path to secure, e.g. "/files/*"
, must not be null
.roles
- The roles that have access to the realm, may be empty or null
.null
.protected org.eclipse.jetty.server.Handler newSecurityHandler()
public HttpServer addResources(String contextRoot, String baseDirectory, String... filteredExtensions)
setFilterToken(String, String)
. The directory mounted into the server via this method will also be used to
store files sent via PUT. Upon requests, the server will try to match the context roots in reverse alphabetical
order, thereby giving longer path prefix matches precedence.contextRoot
- The context root to make the resources accessible at, must not be null
.baseDirectory
- The local base directory whose files should be served, must not be null
.filteredExtensions
- A list of extensions for files to filter, e.g. "xml, "properties"
, may be
null
.null
.public HttpServer enableRecording(String... patterns)
getRecordedRequests()
.patterns
- The regular expressions denoting URIs to monitor, e.g. "/context/.*"
, must not be
null
.null
.public List<String> getRecordedRequests()
enableRecording(String...)
was called. A request is encoded in the form <METHOD> <URI>
, e.g.
GET /context/some.jar
.null
.public Map<String,String> getRecordedHeaders(String uri)
uri
- the pathpublic HttpServer setFilterToken(String token, String value)
@basedir@
, @baseurl@
, @baseuri@
, @port.http@
and
@port.https@
.token
- The token to replace, e.g. @basedir@
, must not be null
.value
- The replacement text of the token, may be null
.null
.protected org.eclipse.jetty.server.Handler newResourceHandler()
public HttpServer setLatency(long millis)
millis
- The latency in milliseconds, maybe negative for infinite delay.null
.protected org.eclipse.jetty.server.Handler newSleepHandler(long millis)
public HttpServer start() throws Exception
null
.Exception
- If the server could not be started.protected void addDefaultFilterTokens()
public void stop()
public void resetRecording()
Copyright © 2005–2015 Sonatype, Inc.. All rights reserved.