public static class HTTPServer.VirtualHost extends Object
VirtualHost class represents a virtual host in the server.| 限定符和类型 | 类和说明 |
|---|---|
class |
HTTPServer.VirtualHost.ContextInfo
The
ContextInfo class holds a single context's information. |
| 限定符和类型 | 字段和说明 |
|---|---|
protected Set<String> |
aliases |
protected boolean |
allowGeneratedIndex |
protected ConcurrentMap<String,HTTPServer.VirtualHost.ContextInfo> |
contexts |
protected String |
directoryIndex |
protected HTTPServer.VirtualHost.ContextInfo |
emptyContext |
protected Set<String> |
methods |
protected String |
name |
| 构造器和说明 |
|---|
VirtualHost(String name)
Constructs a VirtualHost with the given name.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addAlias(String alias)
Adds an alias for this host.
|
void |
addContext(String path,
HTTPServer.ContextHandler handler,
String... methods)
Adds a context and its corresponding context handler to this server.
|
void |
addContexts(Object o)
Adds contexts for all methods of the given object that
are annotated with the
HTTPServer.Context annotation. |
Set<String> |
getAliases()
Returns this host's aliases.
|
HTTPServer.VirtualHost.ContextInfo |
getContext(String path)
Returns the context handler for the given path.
|
String |
getDirectoryIndex()
Gets this host's directory index file.
|
Set<String> |
getMethods()
Returns all HTTP methods explicitly supported by at least one context
(this may or may not include the methods with required or built-in support).
|
String |
getName()
Returns this host's name.
|
boolean |
isAllowGeneratedIndex()
Returns whether auto-generated indices are allowed.
|
void |
setAllowGeneratedIndex(boolean allowed)
Sets whether auto-generated indices are allowed.
|
void |
setDirectoryIndex(String directoryIndex)
Sets the directory index file.
|
protected final String name
protected volatile String directoryIndex
protected volatile boolean allowGeneratedIndex
protected final HTTPServer.VirtualHost.ContextInfo emptyContext
protected final ConcurrentMap<String,HTTPServer.VirtualHost.ContextInfo> contexts
public VirtualHost(String name)
name - the host's name, or null if it is the default hostpublic String getName()
public void addAlias(String alias)
alias - the aliaspublic Set<String> getAliases()
public void setDirectoryIndex(String directoryIndex)
a generated index is allowed, otherwise an error is returned.
The default directory index file is "index.html".directoryIndex - the directory index file, or null if no
index file should be usedpublic String getDirectoryIndex()
public void setAllowGeneratedIndex(boolean allowed)
allowed - specifies whether generated indices are allowedpublic boolean isAllowGeneratedIndex()
public Set<String> getMethods()
public HTTPServer.VirtualHost.ContextInfo getContext(String path)
If a context is not found for the given path, the search is repeated for its parent path, and so on until a base context is found. If neither the given path nor any of its parents has a context, an empty context is returned.
path - the context's pathpublic void addContext(String path, HTTPServer.ContextHandler handler, String... methods)
path - the context's path (must start with '/')handler - the context handler for the given pathmethods - the HTTP methods supported by the context handler (default is "GET")IllegalArgumentException - if path is malformedpublic void addContexts(Object o) throws IllegalArgumentException
HTTPServer.Context annotation.o - the object whose annotated methods are addedIllegalArgumentException - if a Context-annotated
method has an invalid signatureCopyright © 2021. All rights reserved.