public class HttpTunnelServer extends Object
[ CLIENT ] [ SERVER ] | (a) Initial empty request | |------------------------------>| | (b) Data I | -->|------------------------------>|---> | Response I (a) | <--|<------------------------------|<--- | | | (c) Data II | -->|------------------------------>|---> | Response II (b) | <--|<------------------------------|<--- . . . .Each incoming request is held open to be used to carry the next available response. The server will hold at most two connections open at any given time.
Requests should be made using HTTP GET or POST (depending if there is a payload), with any payload contained in the body. The following response codes can be returned from the server:
Status | Meaning |
---|---|
200 (OK) | Data payload response. |
204 (No Content) | The long poll has timed out and the client should start a new request. |
429 (Too many requests) | There are already enough connections open, this one can be dropped. |
410 (Gone) | The target server has disconnected. |
503 (Service Unavailable) | The target server is unavailable |
Requests and responses that contain payloads include a x-seq
header that
contains a running sequence number (used to ensure data is applied in the correct
order). The first request containing a payload should have a x-seq
value of
1
.
HttpTunnelConnection
Modifier and Type | Class and Description |
---|---|
protected static class |
HttpTunnelServer.HttpConnection
Encapsulates a HTTP request/response pair.
|
protected class |
HttpTunnelServer.ServerThread
The main server thread used to transfer tunnel traffic.
|
Constructor and Description |
---|
HttpTunnelServer(TargetServerConnection serverConnection)
Creates a new
HttpTunnelServer instance. |
Modifier and Type | Method and Description |
---|---|
protected HttpTunnelServer.ServerThread |
getServerThread()
Returns the active server thread, creating and starting it if necessary.
|
protected void |
handle(HttpTunnelServer.HttpConnection httpConnection)
Handle an incoming HTTP connection.
|
void |
handle(ServerHttpRequest request,
ServerHttpResponse response)
Handle an incoming HTTP connection.
|
void |
setDisconnectTimeout(long disconnectTimeout)
Set the maximum amount of time to wait for a client before closing the connection.
|
void |
setLongPollTimeout(int longPollTimeout)
Set the long poll timeout for the server.
|
public HttpTunnelServer(TargetServerConnection serverConnection)
HttpTunnelServer
instance.serverConnection
- the connection to the target serverpublic void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException
request
- the HTTP requestresponse
- the HTTP responseIOException
- in case of I/O errorsprotected void handle(HttpTunnelServer.HttpConnection httpConnection) throws IOException
httpConnection
- the HTTP connectionIOException
- in case of I/O errorsprotected HttpTunnelServer.ServerThread getServerThread() throws IOException
ServerThread
(never null
)IOException
- in case of I/O errorspublic void setLongPollTimeout(int longPollTimeout)
longPollTimeout
- the long poll timeout in millisecondspublic void setDisconnectTimeout(long disconnectTimeout)
disconnectTimeout
- the disconnect timeout in milliseconds