APIdia Launch Partner
Top Fields Constructors Methods
sun.net.httpserver

public abstract Class DelegatingHttpExchange

extends HttpExchange
Class Inheritance
Imports
com.sun.net.httpserver.Headers, .HttpContext, .HttpExchange, .HttpPrincipal, java.io.IOException, .InputStream, .OutputStream, java.net.InetSocketAddress, .URI

Field Summary

Modifier and TypeField and Description
private final HttpExchange
Inherited from com.sun.net.httpserver.HttpExchange:
RSPBODY_CHUNKEDRSPBODY_EMPTY

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract com.sun.net.httpserver.HttpExchange.close.

Implements java.lang.AutoCloseable.close.

Ends this exchange by doing the following in sequence:

  1. close the request InputStream, if not already closed.
  2. close the response OutputStream, if not already closed.
public Object
getAttribute(String name)

Implements abstract com.sun.net.httpserver.HttpExchange.getAttribute.

Filter modules may store arbitrary objects with HttpExchange instances as an out-of-band communication mechanism.

public HttpContext
getHttpContext()

Implements abstract com.sun.net.httpserver.HttpExchange.getHttpContext.

Returns the HttpContext for this exchange.

public InetSocketAddress
getLocalAddress()

Implements abstract com.sun.net.httpserver.HttpExchange.getLocalAddress.

Returns the local address on which the request was received.

public HttpPrincipal
getPrincipal()

Implements abstract com.sun.net.httpserver.HttpExchange.getPrincipal.

If an authenticator is set on the HttpContext that owns this exchange, then this method will return the HttpPrincipal that represents the authenticated user for this HttpExchange.

public String
getProtocol()

Implements abstract com.sun.net.httpserver.HttpExchange.getProtocol.

Returns the protocol string from the request in the form protocol/majorVersion.minorVersion.

public InetSocketAddress
getRemoteAddress()

Implements abstract com.sun.net.httpserver.HttpExchange.getRemoteAddress.

Returns the address of the remote entity invoking this request.

public InputStream
getRequestBody()

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestBody.

Returns a stream from which the request body can be read.

public abstract Headers
getRequestHeaders()

Redeclares com.sun.net.httpserver.Request.getRequestHeaders.

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestHeaders.

Returns an immutable Headers containing the HTTP headers that were included with this request.

public abstract String
public abstract URI
public OutputStream
getResponseBody()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseBody.

Returns a stream to which the response body must be written.

public int
getResponseCode()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseCode.

Returns the response code, if it has already been set.

public Headers
getResponseHeaders()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseHeaders.

Returns a mutable Headers into which the HTTP response headers can be stored and which will be transmitted as part of this response.

public void
sendResponseHeaders(int rCode, long contentLen)

Implements abstract com.sun.net.httpserver.HttpExchange.sendResponseHeaders.

Starts sending the response back to the client using the current set of response headers and the numeric response code as specified in this method.

public void
setAttribute(String name, Object value)

Implements abstract com.sun.net.httpserver.HttpExchange.setAttribute.

Filter modules may store arbitrary objects with HttpExchange instances as an out-of-band communication mechanism.

public void
setStreams(InputStream i, OutputStream o)

Implements abstract com.sun.net.httpserver.HttpExchange.setStreams.

Used by Filters to wrap either (or both) of this exchange's InputStream and OutputStream, with the given filtered streams so that subsequent calls to getRequestBody() will return the given InputStream, and calls to getResponseBody() will return the given OutputStream.

Field Detail

exchangeback to summary
private final HttpExchange exchange

Constructor Detail

DelegatingHttpExchangeback to summary
public DelegatingHttpExchange(HttpExchange ex)

Method Detail

closeback to summary
public void close()

Implements abstract com.sun.net.httpserver.HttpExchange.close.

Implements java.lang.AutoCloseable.close.

Doc from com.sun.net.httpserver.HttpExchange.close.

Ends this exchange by doing the following in sequence:

  1. close the request InputStream, if not already closed.
  2. close the response OutputStream, if not already closed.
getAttributeback to summary
public Object getAttribute(String name)

Implements abstract com.sun.net.httpserver.HttpExchange.getAttribute.

Doc from com.sun.net.httpserver.HttpExchange.getAttribute.

Filter modules may store arbitrary objects with HttpExchange instances as an out-of-band communication mechanism. Other filters or the exchange handler may then access these objects.

Each Filter class will document the attributes which they make available.

getHttpContextback to summary
public HttpContext getHttpContext()

Implements abstract com.sun.net.httpserver.HttpExchange.getHttpContext.

Doc from com.sun.net.httpserver.HttpExchange.getHttpContext.

Returns the HttpContext for this exchange.

getLocalAddressback to summary
public InetSocketAddress getLocalAddress()

Implements abstract com.sun.net.httpserver.HttpExchange.getLocalAddress.

Doc from com.sun.net.httpserver.HttpExchange.getLocalAddress.

Returns the local address on which the request was received.

getPrincipalback to summary
public HttpPrincipal getPrincipal()

Implements abstract com.sun.net.httpserver.HttpExchange.getPrincipal.

Doc from com.sun.net.httpserver.HttpExchange.getPrincipal.

If an authenticator is set on the HttpContext that owns this exchange, then this method will return the HttpPrincipal that represents the authenticated user for this HttpExchange.

getProtocolback to summary
public String getProtocol()

Implements abstract com.sun.net.httpserver.HttpExchange.getProtocol.

Doc from com.sun.net.httpserver.HttpExchange.getProtocol.

Returns the protocol string from the request in the form protocol/majorVersion.minorVersion. For example, "HTTP/1.1".

getRemoteAddressback to summary
public InetSocketAddress getRemoteAddress()

Implements abstract com.sun.net.httpserver.HttpExchange.getRemoteAddress.

Doc from com.sun.net.httpserver.HttpExchange.getRemoteAddress.

Returns the address of the remote entity invoking this request.

getRequestBodyback to summary
public InputStream getRequestBody()

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestBody.

Doc from com.sun.net.httpserver.HttpExchange.getRequestBody.

Returns a stream from which the request body can be read. Multiple calls to this method will return the same stream. It is recommended that applications should consume (read) all of the data from this stream before closing it. If a stream is closed before all data has been read, then the InputStream#close() call will read and discard remaining data (up to an implementation specific number of bytes).

getRequestHeadersback to summary
public abstract Headers getRequestHeaders()

Redeclares com.sun.net.httpserver.Request.getRequestHeaders.

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestHeaders.

Doc from com.sun.net.httpserver.HttpExchange.getRequestHeaders.

Returns an immutable Headers containing the HTTP headers that were included with this request.

The keys in this Headers are the header names, while the values are a java.util.List of Strings containing each value that was included in the request, in the order they were included. Header fields appearing multiple times are represented as multiple string values.

The keys in Headers are case-insensitive.

getRequestMethodback to summary
public abstract String getRequestMethod()

Redeclares com.sun.net.httpserver.Request.getRequestMethod.

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestMethod.

Doc from com.sun.net.httpserver.HttpExchange.getRequestMethod.

Returns the request method.

getRequestURIback to summary
public abstract URI getRequestURI()

Redeclares com.sun.net.httpserver.Request.getRequestURI.

Implements abstract com.sun.net.httpserver.HttpExchange.getRequestURI.

Doc from com.sun.net.httpserver.HttpExchange.getRequestURI.

Returns the request URI.

getResponseBodyback to summary
public OutputStream getResponseBody()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseBody.

Doc from com.sun.net.httpserver.HttpExchange.getResponseBody.

Returns a stream to which the response body must be written. sendResponseHeaders(int, long)) must be called prior to calling this method. Multiple calls to this method (for the same exchange) will return the same stream. In order to correctly terminate each exchange, the output stream must be closed, even if no response body is being sent.

Closing this stream implicitly closes the InputStream returned from getRequestBody() (if it is not already closed).

If the call to sendResponseHeaders(int, long) specified a fixed response body length, then the exact number of bytes specified in that call must be written to this stream. If too many bytes are written, then the write method of OutputStream will throw an IOException. If too few bytes are written then the stream OutputStream#close() will throw an IOException. In both cases, the exchange is aborted and the underlying TCP connection closed.

getResponseCodeback to summary
public int getResponseCode()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseCode.

Doc from com.sun.net.httpserver.HttpExchange.getResponseCode.

Returns the response code, if it has already been set.

getResponseHeadersback to summary
public Headers getResponseHeaders()

Implements abstract com.sun.net.httpserver.HttpExchange.getResponseHeaders.

Doc from com.sun.net.httpserver.HttpExchange.getResponseHeaders.

Returns a mutable Headers into which the HTTP response headers can be stored and which will be transmitted as part of this response.

The keys in the Headers are the header names, while the values must be a java.util.List of Strings containing each value that should be included multiple times (in the order that they should be included).

The keys in Headers are case-insensitive.

sendResponseHeadersback to summary
public void sendResponseHeaders(int rCode, long contentLen) throws IOException

Implements abstract com.sun.net.httpserver.HttpExchange.sendResponseHeaders.

Doc from com.sun.net.httpserver.HttpExchange.sendResponseHeaders.

Starts sending the response back to the client using the current set of response headers and the numeric response code as specified in this method. The response body length is also specified as follows. If the response length parameter is greater than zero, this specifies an exact number of bytes to send and the application must send that exact amount of data. If the response length parameter has the value RSPBODY_CHUNKED (zero) then the response body uses chunked transfer encoding and an arbitrary amount of data may be sent. The application terminates the response body by closing the OutputStream. If response length has the value RSPBODY_EMPTY then no response body is being sent.

If the content-length response header has not already been set then this is set to the appropriate value depending on the response length parameter.

This method must be called prior to calling getResponseBody().

Exceptions
IOException:
if the response headers have already been sent or an I/O error occurs
setAttributeback to summary
public void setAttribute(String name, Object value)

Implements abstract com.sun.net.httpserver.HttpExchange.setAttribute.

Doc from com.sun.net.httpserver.HttpExchange.setAttribute.

Filter modules may store arbitrary objects with HttpExchange instances as an out-of-band communication mechanism. Other filters or the exchange handler may then access these objects.

Each Filter class will document the attributes which they make available.

setStreamsback to summary
public void setStreams(InputStream i, OutputStream o)

Implements abstract com.sun.net.httpserver.HttpExchange.setStreams.

Doc from com.sun.net.httpserver.HttpExchange.setStreams.

Used by Filters to wrap either (or both) of this exchange's InputStream and OutputStream, with the given filtered streams so that subsequent calls to getRequestBody() will return the given InputStream, and calls to getResponseBody() will return the given OutputStream. The streams provided to this call must wrap the original streams, and may be (but are not required to be) sub-classes of java.io.FilterInputStream and java.io.FilterOutputStream.