public final class HttpServerEndpoint extends Object implements ServerEndpoint
ServerEndpoint abstraction that
uses HTTP messages sent over TCP sockets (instances of ServerSocket) for the underlying communication mechanism.
HttpServerEndpoint instances contain a host name
and a TCP port number, as well as an optional ServerSocketFactory for customizing the type of
ServerSocket to use and an optional SocketFactory for customizing the type of Socket that
client endpoints will use. The port number is the local TCP port
to bind to when listening for incoming socket connections. If the
port number is zero, then each listen operation will bind to a free
(non-zero) port, which will be the port number contained in the
resulting HttpEndpoint. The host name contained in an
HttpServerEndpoint controls the host name that will be
contained in the HttpEndpoint instances produced when
enumerateListenEndpoints is
invoked to listen on the HttpServerEndpoint (this host
name does not affect the behavior of listen operations themselves).
If the host name in an HttpServerEndpoint is
null, then the host name in the
HttpEndpoint instances that it produces will be the IP
address string obtained from InetAddress.getLocalHost when enumerateListenEndpoints is invoked.
HttpServerEndpoint instances map incoming HTTP
messages to requests; when possible, underlying TCP connections are
persisted to accommodate multiple non-overlapping incoming
requests. Inbound request data is received as the
entity-body of an HTTP POST request; outbound response
data is sent as the entity-body of the corresponding
HTTP return message. For information on HTTP, refer to RFC 2616. Note that
providing socket factories that produce SSL sockets does not result
in endpoints that are fully HTTPS capable.
A ServerSocketFactory used with an
HttpServerEndpoint must implement Object.equals to obey the guidelines that are specified for
equals methods of ListenEndpoint
instances. A SocketFactory used with a
HttpServerEndpoint should be serializable and must
implement Object.equals to obey the guidelines that
are specified for equals methods of Endpoint
instances.
HttpEndpointServerEndpoint.ListenContext, ServerEndpoint.ListenCookie, ServerEndpoint.ListenEndpoint, ServerEndpoint.ListenHandle| Modifier and Type | Method and Description |
|---|---|
InvocationConstraints |
checkConstraints(InvocationConstraints constraints)
Verifies that this instance supports the transport layer
aspects of all of the specified requirements (both in general
and in the current security context), and returns the
requirements that must be at least partially implemented by
higher layers in order to fully satisfy all of the specified
requirements.
|
Endpoint |
enumerateListenEndpoints(ServerEndpoint.ListenContext listenContext)
Passes the
ListenEndpoint for this HttpServerEndpoint to
listenContext, which will ensure an active listen
operation on the endpoint, and returns an
HttpEndpoint instance corresponding to the listen
operation chosen by listenContext. |
boolean |
equals(Object obj)
Compares the specified object with this
HttpServerEndpoint for equality. |
String |
getHost()
Returns the host name that will be used in
HttpEndpoint instances produced by listening on
this HttpServerEndpoint, or null if
the IP address string obtained from InetAddress.getLocalHost will be
used. |
static HttpServerEndpoint |
getInstance(int port)
Returns an
HttpServerEndpoint instance for the
given TCP port number. |
static HttpServerEndpoint |
getInstance(String host,
int port)
Returns an
HttpServerEndpoint instance for the given
host name and TCP port number. |
static HttpServerEndpoint |
getInstance(String host,
int port,
SocketFactory sf,
ServerSocketFactory ssf)
Returns an
HttpServerEndpoint instance for the
given host name and TCP port number that contains the given
SocketFactory and
ServerSocketFactory. |
int |
getPort()
Returns the TCP port that this
HttpServerEndpoint
listens on. |
ServerSocketFactory |
getServerSocketFactory()
Returns the
ServerSocketFactory that this endpoint
uses to create ServerSocket objects. |
SocketFactory |
getSocketFactory()
Returns the
SocketFactory that
HttpEndpoint objects produced by listening on this
HttpServerEndpoint will use to create
Socket objects. |
int |
hashCode()
Returns the hash code value for this
HttpServerEndpoint. |
String |
toString()
Returns a string representation of this
HttpServerEndpoint. |
public static HttpServerEndpoint getInstance(int port)
HttpServerEndpoint instance for the
given TCP port number.
The host name contained in the returned
HttpServerEndpoint will be null, so
that when its enumerateListenEndpoints method produces an HttpEndpoint, the HttpEndpoint's host name will
be the IP address string obtained from InetAddress.getLocalHost.
The ServerSocketFactory contained in the
returned HttpServerEndpoint will be
null, indicating that this endpoint will create
ServerSocket objects directly. The
SocketFactory contained in the returned
HttpServerEndpoint will also be null.
port - the TCP port on the local host to listen onHttpServerEndpoint instanceIllegalArgumentException - if the port number is out of
the range 0 to 65535 (inclusive)public static HttpServerEndpoint getInstance(String host, int port)
HttpServerEndpoint instance for the given
host name and TCP port number.
If host is null, then when the
returned HttpServerEndpoint's enumerateListenEndpoints method
produces an HttpEndpoint, the
HttpEndpoint's host name will be the IP address
string obtained from InetAddress.getLocalHost.
The ServerSocketFactory contained in the
returned HttpServerEndpoint will be
null, indicating that this endpoint will create
ServerSocket objects directly. The
SocketFactory contained in the returned
HttpServerEndpoint will also be null.
host - the host name to be used in
HttpEndpoint instances produced by listening on
the returned HttpServerEndpoint, or
nullport - the TCP port on the local host to listen onHttpServerEndpoint instanceIllegalArgumentException - if the port number is out of
the range 0 to 65535 (inclusive)public static HttpServerEndpoint getInstance(String host, int port, SocketFactory sf, ServerSocketFactory ssf)
HttpServerEndpoint instance for the
given host name and TCP port number that contains the given
SocketFactory and
ServerSocketFactory.
If host is null, then when the
returned HttpServerEndpoint's enumerateListenEndpoints method
produces an HttpEndpoint, the
HttpEndpoint's host name will be the IP address
string obtained from InetAddress.getLocalHost.
If the server socket factory argument is null,
then this endpoint will create ServerSocket
objects directly.
host - the host name to be used in
HttpEndpoint instances produced by listening on
the returned HttpServerEndpoint, or
nullport - the TCP port on the local host to listen onsf - the SocketFactory to use for this
HttpServerEndpoint, or nullssf - the ServerSocketFactory to use for this
HttpServerEndpoint, or nullHttpServerEndpoint instanceIllegalArgumentException - if the port number is out of
the range 0 to 65535 (inclusive)public String getHost()
HttpEndpoint instances produced by listening on
this HttpServerEndpoint, or null if
the IP address string obtained from InetAddress.getLocalHost will be
used.HttpEndpoint
instances produced from this object, or nullpublic int getPort()
HttpServerEndpoint
listens on.public SocketFactory getSocketFactory()
SocketFactory that
HttpEndpoint objects produced by listening on this
HttpServerEndpoint will use to create
Socket objects.null if no factory will be usedpublic ServerSocketFactory getServerSocketFactory()
ServerSocketFactory that this endpoint
uses to create ServerSocket objects.null if no factory is usedpublic InvocationConstraints checkConstraints(InvocationConstraints constraints) throws UnsupportedConstraintException
For any given constraint, there must be a clear delineation
of which aspects (if any) must be implemented by the transport
layer. This method must not return a constraint (as a
requirement or a preference, directly or as an element of
another constraint) unless this instance can implement all of
those aspects. Also, this method must not return a constraint
for which all aspects must be implemented by the transport
layer. Most of the constraints in the net.jini.core.constraint package must be fully implemented by
the transport layer and thus must not be returned by this
method; the two exceptions are Integrity and
AtomicInputValidation, for which the
transport layer is responsible for the data integrity aspect
and higher layers are responsible for the code integrity
and atomic input validation aspects.
For any ConstraintAlternatives in the specified
constraints, this method should only return a corresponding
constraint if all of the alternatives supported by this
instance need to be at least partially implemented by higher
layers in order to be fully satisfied.
The constraints passed to this method may include constraints based on relative time.
checkConstraints in interface ServerCapabilitiesconstraints - the constraints that must be supportedNullPointerException - if constraints is
nullUnsupportedConstraintException - if the transport layer
aspects of any of the specified requirements are not supported
by this instance (either in general or in the current security
context)public Endpoint enumerateListenEndpoints(ServerEndpoint.ListenContext listenContext) throws IOException
ListenEndpoint for this HttpServerEndpoint to
listenContext, which will ensure an active listen
operation on the endpoint, and returns an
HttpEndpoint instance corresponding to the listen
operation chosen by listenContext.
If this HttpServerEndpoint's host name is not
null, then the returned HttpEndpoint
will contain that host name. If this
HttpServerEndpoint's host name is
null, then this method invokes InetAddress.getLocalHost to obtain an
InetAddress for the local host. If
InetAddress.getLocalHost throws an UnknownHostException, this method throws an
UnknownHostException. The returned
HttpEndpoint's host name will be the string
returned by invoking getHostAddress on that InetAddress. If there is
a security manager, its checkConnect method
will be invoked with the string returned by invoking getHostName on that same
InetAddress as the host argument and
-1 as the port argument; this could result in a
SecurityException.
This method invokes addListenEndpoint on
listenContext once, passing a
ListenEndpoint as described below. If
addListenEndpoint throws an exception, then this
method throws that exception. Otherwise, this method returns
an HttpEndpoint instance with the host name
described above, the TCP port number bound by the listen
operation represented by the ListenHandle
returned by addListenEndpoint, and the same
SocketFactory as this
HttpServerEndpoint.
The ListenEndpoint passed to
addListenEndpoint represents the TCP port number
and ServerSocketFactory of this
HttpServerEndpoint. Its methods behave as
follows:
ListenHandle listen(RequestDispatcher):
Listens for requests received on this endpoint's TCP port, dispatching them to the suppliedRequestDispatcherin the form ofInboundRequestinstances.When the implementation of this method needs to create a new
ServerSocket, it will do so by invoking one of thecreateServerSocketmethods that returns a bound server socket on the containedServerSocketFactoryif non-null, or it will create aServerSocketdirectly otherwise.If there is a security manager, its
checkListenmethod will be invoked with this endpoint's TCP port; this could result in aSecurityException. Furthermore, before a givenInboundRequestgets dispatched to the supplied request dispatcher, the security manager'scheckAcceptmethod must have been successfully invoked in the security context of thislisteninvocation with the remote IP address and port of theSocketused to receive the request. ThecheckPermissionsmethod of the dispatchedInboundRequestalso performs this latter security check. (Note that in some cases, the implementation may carry out these security checks indirectly, such as through invocations ofServerSocket's constructors oracceptmethod.)Requests will be dispatched in a
PrivilegedActionwrapped by aSecurityContextobtained when this method was invoked, with theAccessControlContextof thatSecurityContextin effect.Dispatched requests will implement
populateContextto populate the supplied collection with context information representing the request.Throws
IOExceptionif an I/O exception occurs while performing this operation, such as if the TCP port is already in use.Throws
SecurityExceptionif there is a security manager and the invocation of itscheckListenmethod fails.Throws
NullPointerExceptionifrequestDispatcherisnull
Verifies that the calling context has all of the security permissions necessary to listen for requests on this endpoint.If there is a security manager, its
checkListenmethod will be invoked with this endpoint's TCP port; this could result in aSecurityException.Throws
SecurityExceptionif there is a security manager and the invocation of itscheckListenmethod fails.
Compares the specified object with thisListenEndpointfor equality.This method returns
trueif and only if
- the specified object is also a
ListenEndpointproduced by anHttpServerEndpoint,- the port in the specified object is equal to the port in this object, and
- either this object and the specified object both have no
ServerSocketFactoryor theServerSocketFactoryin the specified object has the same class and is equal to the one in this object.
enumerateListenEndpoints in interface ServerEndpointlistenContext - the ListenContext to pass
this HttpServerEndpoint's
ListenEndpoint toHttpEndpoint instance for sending
requests to this HttpServerEndpoint's endpoint
being listened onUnknownHostException - if this
HttpServerEndpoint's host name is
null and InetAddress.getLocalHost
throws an UnknownHostExceptionIOException - if an I/O exception occurs while performing
this operation, such as if the TCP port is already in useSecurityException - if there is a security manager and
either the invocation of its checkListen method
fails or this HttpServerEndpoint's host name is
null and the invocation of the security manager's
checkConnect method failsIllegalArgumentException - if an invocation of the
addListenEndpoint method on the supplied
ListenContext returns a ListenCookie
that does not correspond to the ListenEndpoint
that was passed to itNullPointerException - if listenContext is
nullpublic int hashCode()
HttpServerEndpoint.public boolean equals(Object obj)
HttpServerEndpoint for equality.
This method returns true if and only if
HttpServerEndpoint,
SocketFactory or the ServerFactory in
the specified object has the same class and is equal to the one
in this object, and
ServerSocketFactory or the
ServerSocketFactory in the specified object has
the same class and is equal to the one in this object.
Copyright © 2016–2018. All rights reserved.