public class CookieInterceptor extends java.lang.Object implements HttpConnectionRequestInterceptor, HttpConnectionResponseInterceptor
HttpConnection
.
If a response has a response code of 401, it will fetch a cookie from
the server using provided credentials and tell HttpConnection
to reply
the request by setting HttpConnectionInterceptorContext.replayRequest
property to true.
If the request to get the cookie for use in future request fails with a 401 status code
(or any status that indicates client error) cookie authentication will not be attempted again.Constructor and Description |
---|
CookieInterceptor(java.lang.String username,
java.lang.String password)
Constructs a cookie interceptor.
|
Modifier and Type | Method and Description |
---|---|
HttpConnectionInterceptorContext |
interceptRequest(HttpConnectionInterceptorContext context)
Intercept the request.
|
HttpConnectionInterceptorContext |
interceptResponse(HttpConnectionInterceptorContext context)
Intercept the response
This method must not do any of the following
Return null
Read the response stream
|
public CookieInterceptor(java.lang.String username, java.lang.String password)
username
- The username to use when getting the cookiepassword
- The password to use when getting the cookiepublic HttpConnectionInterceptorContext interceptRequest(HttpConnectionInterceptorContext context)
HttpConnectionRequestInterceptor
HttpURLConnection
which
initiate a request such as HttpURLConnection.getResponseCode()
interceptRequest
in interface HttpConnectionRequestInterceptor
context
- Input contextpublic HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context)
HttpConnectionResponseInterceptor
interceptResponse
in interface HttpConnectionResponseInterceptor
context
- Input context