public class UserAgent
extends java.lang.Object
Constructor and Description |
---|
UserAgent() |
UserAgent(java.net.Proxy proxy) |
Modifier and Type | Method and Description |
---|---|
UserAgent |
addHeader(java.lang.String name,
java.lang.String value)
Add a header value to the header with the given name.
|
protected void |
adjustForSSL(java.net.HttpURLConnection connection) |
protected void |
applyRequestHeaders(java.net.HttpURLConnection connection,
Headers headerDef) |
protected void |
applyUserAgent(java.net.HttpURLConnection connection) |
protected boolean |
canHaveContent(int responseCode) |
static UserAgent |
create()
Creates a new instance of a UserAgent with no proxy and not following redirects.
|
protected ServerResponse |
executeRequest(ClientRequest request,
IResponseStreamHandler responseStreamHandler)
Sends a request based on the given request definition and the user agent's
own state.
|
int |
getConnectTimeout() |
java.lang.String |
getHeader(java.lang.String name)
Returns a single value (the first) of the header with the given name.
|
protected Headers |
getHeaders() |
javax.net.ssl.HostnameVerifier |
getHostnameVerifier() |
protected Logger |
getLogger() |
java.net.Proxy |
getProxy()
Returns the user agent's proxy.
|
int |
getReadTimeout() |
java.lang.String |
getUserAgentName() |
protected ServerResponse |
handleRedirectResponse(ClientRequest request,
IResponseStreamHandler responseStreamHandler,
ServerResponse response) |
boolean |
hasProxy() |
boolean |
isFollowRedirects() |
protected boolean |
isSupposedToHaveContent(ServerResponse response) |
protected java.net.HttpURLConnection |
openHttpConnection(java.net.URL url) |
UserAgent |
removeHeader(java.lang.String name)
Returns the header with the given name and all its associated values.
|
protected ServerResponse |
retrieveResponse(java.net.HttpURLConnection connection,
IResponseStreamHandler responseStreamHandler) |
UserAgent |
self() |
ServerResponse |
sendRequest(ClientRequest request)
Sends a request based on the given request definition and the user agent's
own state.
|
ServerResponse |
sendRequest(ClientRequest request,
IResponseStreamHandler responseStreamHandler)
Sends a request based on the given request definition and the user agent's
own state.
|
protected void |
sendRequestBody(java.net.HttpURLConnection connection,
ClientRequest request) |
UserAgent |
setConnectTimeout(int connectTimeout) |
UserAgent |
setFollowRedirects(boolean followRedirects) |
UserAgent |
setHeader(java.lang.String name,
java.lang.String value)
A a header with a single value.
|
UserAgent |
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier) |
UserAgent |
setProxy(java.net.Proxy proxy)
Sets the user agent's proxy.
|
UserAgent |
setReadTimeout(int readTimeout) |
UserAgent |
setUserAgentName(java.lang.String userAgentName) |
java.lang.String |
toString() |
public static UserAgent create()
public java.net.Proxy getProxy()
public UserAgent setProxy(java.net.Proxy proxy)
public UserAgent addHeader(java.lang.String name, java.lang.String value)
public UserAgent setHeader(java.lang.String name, java.lang.String value)
public java.lang.String getHeader(java.lang.String name)
public UserAgent removeHeader(java.lang.String name)
public ServerResponse sendRequest(ClientRequest request) throws java.io.IOException
request
- The definition of the request to be sent (must not be null).java.io.IOException
- Any problem during remote communication.public ServerResponse sendRequest(ClientRequest request, IResponseStreamHandler responseStreamHandler) throws java.io.IOException
request
- The definition of the request to be sent (must not be null).responseStreamHandler
- An optional (may be null) handler for the response stream.
If provided the ServerResponse methods hasContentData(), getContentData(), getConentText(),
getContentReader() must not be used anymore!java.io.IOException
- Any problem during remote communication.public int getReadTimeout()
public UserAgent setReadTimeout(int readTimeout)
public int getConnectTimeout()
public UserAgent setConnectTimeout(int connectTimeout)
public java.lang.String getUserAgentName()
public UserAgent setUserAgentName(java.lang.String userAgentName)
public boolean isFollowRedirects()
public UserAgent setFollowRedirects(boolean followRedirects)
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
public UserAgent setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
public boolean hasProxy()
public UserAgent self()
public java.lang.String toString()
toString
in class java.lang.Object
protected java.net.HttpURLConnection openHttpConnection(java.net.URL url) throws java.io.IOException
java.io.IOException
protected void sendRequestBody(java.net.HttpURLConnection connection, ClientRequest request) throws java.io.IOException
java.io.IOException
protected void applyUserAgent(java.net.HttpURLConnection connection)
protected void applyRequestHeaders(java.net.HttpURLConnection connection, Headers headerDef)
protected ServerResponse executeRequest(ClientRequest request, IResponseStreamHandler responseStreamHandler) throws java.io.IOException
request
- The definition of the request to be sent (must not be null).responseStreamHandler
- An optional (may be null) handler for the response stream.
If provided the ServerResponse methods hasContentData(), getContentData(), getConentText(),
getContentReader() must not be used anymore!java.io.IOException
- Any problem during remote communication.protected ServerResponse retrieveResponse(java.net.HttpURLConnection connection, IResponseStreamHandler responseStreamHandler) throws java.io.IOException
java.io.IOException
protected ServerResponse handleRedirectResponse(ClientRequest request, IResponseStreamHandler responseStreamHandler, ServerResponse response) throws java.io.IOException
java.io.IOException
protected boolean isSupposedToHaveContent(ServerResponse response)
protected boolean canHaveContent(int responseCode)
protected void adjustForSSL(java.net.HttpURLConnection connection)
protected Headers getHeaders()
protected Logger getLogger()