Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public static final class Web.Exchange
- Object
- Web.Exchange
One streamed HTTP exchange: the request body written as it is produced, the response read as it arrives, neither held in memory whole. The way to move a large upload or download, or to forward one (see HttpProxy).
Use it from one thread, in order: write and close getRequestBody when
the request has one, then getStatus and the headers, then read
getResponseBody. Writes block until the transport has taken the bytes
and reads until some have arrived, so a slow peer at either end slows the
producer rather than filling memory – each direction buffers a fixed
256 KiB window. close ends the exchange whatever state it is in;
before the response has been read to its end that CANCELS it, closing the
upstream connection rather than draining it. Always close it, in a finally.
Redirects are never followed here: a streamed body cannot be replayed. The request timeout of a WebClient does not apply either – a stream may legitimately run for as long as it moves – while its connect and read timeouts do, the read timeout bounding each wait for the peer. A stream has a connection of its own rather than one from the client’s pool.
Methods
public OutputStream getRequestBody()
throws IOException | Where the request body goes. |
public int getStatus()
throws IOException | The response status, waiting for the response headers. |
public String getProtocol()
throws IOException | “HTTP/1.1” or “HTTP/2”, as negotiated. |
public Map getHeaders()
throws IOException | The first value of every response header, by lower-case name. |
public Map getHeaderValueMap()
throws IOException | Every response header, by lower-case name, each a List of values in arrival order – Set-Cookie and the like keep every line. |
public String getHeader(String name)
throws IOException | |
public List getHeaderValues(String name)
throws IOException | |
public InputStream getResponseBody()
throws IOException | The response body as it arrives. |
public void close() | Ends the exchange. |
Inherited methods
Method details
getRequestBody
public OutputStream getRequestBody()
throws IOExceptionThrows
getStatus
public int getStatus()
throws IOExceptionThrows
getProtocol
public String getProtocol()
throws IOExceptionThrows
getHeaders
public Map getHeaders()
throws IOExceptionThrows
getHeaderValueMap
public Map getHeaderValueMap()
throws IOExceptionThrows
getHeader
public String getHeader(String name)
throws IOExceptionThrows
getHeaderValues
public List getHeaderValues(String name)
throws IOExceptionThrows
getResponseBody
public InputStream getResponseBody()
throws IOExceptionclose before that cancels it.Throws
close
public void close()