public final class HttpContext extends Object
It will also act as a way for the client to pass any additional headers or client certificates to the WebSocket handshake.
To create an HttpContext, use the following builder pattern:
HttpContext.Builder.create()
.withHeader(headerName1, headerValue1)
.withHeader(headerName2, headerValue2)
.withSslContext(sslContext)
.build();
Code sample for using HttpContext with Guest authentication:
javax.net.ssl.SSLContext sslContext = ... // Build the SSL Context using keyManager, TrustManager if any
HttpContext httpContext = HttpContext.Builder.create().withSslContext(sslContext).build();
Code sample for using HttpContext with BasicAuthentication:
java.net.URL url = new URL("http://server:port/login?wsc_app_uri=/ws/webrtc/someapp");
java.net.HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
String authHeader = ...; // Get header in basic auth form
urlConnection.setRequestProperty(HttpContext.AUTHORIZATION_HEADER, authHeader);
java.net.CookieManager cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
java.net.CookieHandler.CookieHandler.setDefault(cookieManager);
urlConnection.connect();
javax.net.ssl.SSLContext sslContext = ... // Build the SSL Context using keyManager, TrustManager if any using standard Java API.
Map<String, List<String>> headers = new HashMap<String, List<String>>();
HttpContext httpContext = HttpContext.Builder.create()
.withHeaders(cookieManager.get(url.toURI(), headers))
.withSslContext(sslContext)
.build();
Modifier and Type | Class and Description |
---|---|
static class |
HttpContext.Builder
Builder for creating the HttpContext.
|
Modifier and Type | Field and Description |
---|---|
static String |
AUTHORIZATION_HEADER
The Constant AUTHORIZATION_HEADER.
|
static String |
COOKIE_HEADER
The Constant COOKIE_HEADER.
|
static String |
SET_COOKIE_HEADER
The Constant SET_COOKIE_HEADER.
|
Modifier and Type | Method and Description |
---|---|
List |
getHeader(String headerName)
Gets all possible values of the header indicated by headerName.
|
Map |
getHeaders()
Returns a map of the header fields and values.
|
SSLContext |
getSslContext()
Gets the
SSLContext . |
public static final String AUTHORIZATION_HEADER
public static final String SET_COOKIE_HEADER
public static final String COOKIE_HEADER
public SSLContext getSslContext()
SSLContext
.public List getHeader(String headerName)
headerName
- header namepublic Map getHeaders()