io.undertow.websockets.spi

## Interface WebSocketHttpExchange

All Superinterfaces:
  AutoCloseable, Closeable

All Known Implementing Classes:
  AsyncWebSocketHttpServerExchange, BlockingWebSocketHttpServerExchange

    public interface WebSocketHttpExchange
    extends Closeable

An abstraction for a Http exchange. Undertow uses 3 different types of exchanges:

- async - blocking - servlet

This class provides a way to operate on the underling exchange while providing the correct semantics regardless of the underlying exchange type.

The main use case for this is web sockets. Web sockets should be able to perform a handshake regardless of the nature of the underlying request, while still respecting servlet filters, security etc.

Author:
  Stuart Douglas

### Method Summary

All Methods Instance Methods Abstract Methods
`void` `close()` Forcibly close the exchange.
`void` `endExchange()` End the exchange normally.
`<T> T` `getAttachment(AttachmentKey<T> key)`
`ByteBufferPool` `getBufferPool()`
`org.xnio.OptionMap` `getOptions()`
`Set<WebSocketChannel>` `getPeerConnections()`
`String` `getQueryString()`
`String` `getRequestHeader(String headerName)` gets the first request header with the specified name
`Map<String,List<String>>` `getRequestHeaders()`
`Map<String,List<String>>` `getRequestParameters()`
`String` `getRequestScheme()` Get the request scheme, usually http or https
`String` `getRequestURI()`
`String` `getResponseHeader(String headerName)` get a response header
`Map<String,List<String>>` `getResponseHeaders()`
`Object` `getSession()` Gets the session, if any
`Principal` `getUserPrincipal()`
`boolean` `isUserInRole(String role)`
`<T> void` `putAttachment(AttachmentKey<T> key, T value)`
`org.xnio.IoFuture<byte[]>` `readRequestData()` Gets the body of the request.
`org.xnio.IoFuture<Void>` `sendData(ByteBuffer data)` Send some data
`void` `setResponseHeader(String headerName, String headerValue)` Set a response header
`void` `setResponseHeaders(Map<String,List<String>> headers)` Sets the response headers
`void` `upgradeChannel(HttpUpgradeListener upgradeCallback)` Upgrade the underlying channel

### Method Detail

#### putAttachment

    <T> void putAttachment(AttachmentKey<T> key,
                           T value)

#### getAttachment

    <T> T getAttachment(AttachmentKey<T> key)

#### getRequestHeader

    String getRequestHeader(String headerName)

gets the first request header with the specified name

Parameters:
  `headerName` - The header name
Returns:
  The header value, or null

#### getRequestHeaders

    Map<String,List<String>> getRequestHeaders()

Returns:
  An unmodifiable map of request headers

#### getResponseHeader

    String getResponseHeader(String headerName)

get a response header

Parameters:
  `headerName` - The header name
Returns:
  The header value, or null

#### getResponseHeaders

    Map<String,List<String>> getResponseHeaders()

Returns:
  An unmodifiable map of response headers

#### setResponseHeaders

    void setResponseHeaders(Map<String,List<String>> headers)

Sets the response headers

#### setResponseHeader

    void setResponseHeader(String headerName,
                           String headerValue)

Set a response header

Parameters:
  `headerName` - The header name
  `headerValue` - The header value

#### upgradeChannel

    void upgradeChannel(HttpUpgradeListener upgradeCallback)

Upgrade the underlying channel

Parameters:
  `upgradeCallback` -

#### sendData

    org.xnio.IoFuture<Void> sendData(ByteBuffer data)

Send some data

Parameters:
  `data` - The data

#### readRequestData

    org.xnio.IoFuture<byte[]> readRequestData()

Gets the body of the request.

#### endExchange

    void endExchange()

End the exchange normally. If this is a blocking exchange this may be a noop, and the exchange will actually end when the call stack returns

#### close

    void close()

Forcibly close the exchange.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

#### getRequestScheme

    String getRequestScheme()

Get the request scheme, usually http or https

Returns:
  The request scheme

#### getRequestURI

    String getRequestURI()

Returns:
  The request URI, including the query string

#### getBufferPool

    ByteBufferPool getBufferPool()

Returns:
  The buffer pool

#### getQueryString

    String getQueryString()

Returns:
  The query string

#### getSession

    Object getSession()

Gets the session, if any

Returns:
  The session object, or null

#### getRequestParameters

    Map<String,List<String>> getRequestParameters()

#### getUserPrincipal

    Principal getUserPrincipal()

#### isUserInRole

    boolean isUserInRole(String role)

#### getPeerConnections

    Set<WebSocketChannel> getPeerConnections()

#### getOptions

    org.xnio.OptionMap getOptions()