public class Webb extends Object
Modifier and Type | Field and Description |
---|---|
static String |
APP_BINARY |
static String |
APP_FORM |
static String |
APP_JSON |
static String |
DEFAULT_USER_AGENT |
static String |
HDR_ACCEPT |
static String |
HDR_ACCEPT_ENCODING |
static String |
HDR_AUTHORIZATION |
static String |
HDR_CONTENT_ENCODING |
static String |
HDR_CONTENT_TYPE |
static String |
HDR_USER_AGENT |
static String |
TEXT_PLAIN |
Modifier | Constructor and Description |
---|---|
protected |
Webb() |
Modifier and Type | Method and Description |
---|---|
static Webb |
create()
Create an instance which can be reused for multiple requests in the same Thread.
|
Request |
delete(String pathOrUri)
Creates a DELETE HTTP request with the specified absolute or relative URI.
|
Request |
get(String pathOrUri)
Creates a GET HTTP request with the specified absolute or relative URI.
|
String |
getBaseUri()
Returns the base URI of this instance.
|
Request |
post(String pathOrUri)
Creates a POST HTTP request with the specified absolute or relative URI.
|
Request |
put(String pathOrUri)
Creates a PUT HTTP request with the specified absolute or relative URI.
|
void |
setBaseUri(String baseUri)
Set the base URI for all requests created from this instance.
|
static void |
setConnectTimeout(int globalConnectTimeout)
Set the timeout in milliseconds for connecting the server.
|
void |
setDefaultHeader(String name,
Object value)
Set the value for a named header which is valid for all requests created by this instance.
|
void |
setFollowRedirects(boolean auto)
|
static void |
setGlobalBaseUri(String globalBaseUri)
Set the base URI for all requests starting in this JVM from now.
|
static void |
setGlobalHeader(String name,
Object value)
Set the value for a named header which is valid for all requests in the running JVM.
|
void |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Set a custom
HostnameVerifier , most likely to relax host-name checking. |
static void |
setJsonIndentFactor(int indentFactor)
The number of characters to indent child properties,
-1 for "productive" code. |
static void |
setReadTimeout(int globalReadTimeout)
Set the timeout in milliseconds for getting response from the server.
|
void |
setRetryManager(RetryManager retryManager)
Registers an alternative
RetryManager . |
void |
setSSLSocketFactory(SSLSocketFactory sslSocketFactory)
Set a custom
SSLSocketFactory , most likely to relax Certification checking. |
public static final String DEFAULT_USER_AGENT
public static final String APP_FORM
public static final String APP_JSON
public static final String APP_BINARY
public static final String TEXT_PLAIN
public static final String HDR_CONTENT_TYPE
public static final String HDR_CONTENT_ENCODING
public static final String HDR_ACCEPT
public static final String HDR_ACCEPT_ENCODING
public static final String HDR_USER_AGENT
public static final String HDR_AUTHORIZATION
public static Webb create()
public static void setGlobalHeader(String name, Object value)
setDefaultHeader(String, Object)
and/or
Request.header(String, Object)
.
Request.header(String, Object)
.name
- name of the header (regarding HTTP it is not case-sensitive, but here case is important).value
- value of the header. If null
the header value is cleared (effectively not set).setDefaultHeader(String, Object)
,
Request.header(String, Object)
public static void setGlobalBaseUri(String globalBaseUri)
setBaseUri(String)
is not called or
called with null
.globalBaseUri
- the prefix for all URIs of new Requests.setBaseUri(String)
public static void setJsonIndentFactor(int indentFactor)
-1
for "productive" code.
indentFactor
- the number of spaces to indentpublic static void setConnectTimeout(int globalConnectTimeout)
HttpURLConnection
, we use a default timeout of 10 seconds, since no
timeout is odd.Request.connectTimeout(int)
.globalConnectTimeout
- the new timeout or <= 0
to use HttpURLConnection default timeout.public static void setReadTimeout(int globalReadTimeout)
HttpURLConnection
, we use a default timeout of 3 minutes, since no
timeout is odd.Request.readTimeout(int)
.globalReadTimeout
- the new timeout or <= 0
to use HttpURLConnection default timeout.public void setFollowRedirects(boolean auto)
Request.followRedirects(boolean)
.auto
- true
to automatically follow redirects (HTTP status code 3xx).
Default value comes from HttpURLConnection and should be true
.public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory)
SSLSocketFactory
, most likely to relax Certification checking.sslSocketFactory
- the factory to use (see test cases for an example).public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
HostnameVerifier
, most likely to relax host-name checking.hostnameVerifier
- the verifier (see test cases for an example).public void setBaseUri(String baseUri)
setGlobalBaseUri(String)
.baseUri
- the prefix for all URIs of new Requests.setGlobalBaseUri(String)
public String getBaseUri()
public void setDefaultHeader(String name, Object value)
setGlobalHeader(String, Object)
but can be overwritten by
Request.header(String, Object)
.
Request.header(String, Object)
.name
- name of the header (regarding HTTP it is not case-sensitive, but here case is important).value
- value of the header. If null
the header value is cleared (effectively not set).
When setting the value to null, a value from global headers can shine through.setGlobalHeader(String, Object)
,
Request.header(String, Object)
public void setRetryManager(RetryManager retryManager)
RetryManager
.retryManager
- the new manager for deciding whether it makes sense to retry a request.public Request get(String pathOrUri)
pathOrUri
- the URI (will be concatenated with global URI or default URI without further checking).
If it starts already with http:// or https:// this URI is taken and all base URIs are ignored.public Request post(String pathOrUri)
pathOrUri
- the URI (will be concatenated with global URI or default URI without further checking)
If it starts already with http:// or https:// this URI is taken and all base URIs are ignored.public Request put(String pathOrUri)
pathOrUri
- the URI (will be concatenated with global URI or default URI without further checking)
If it starts already with http:// or https:// this URI is taken and all base URIs are ignored.public Request delete(String pathOrUri)
pathOrUri
- the URI (will be concatenated with global URI or default URI without further checking)
If it starts already with http:// or https:// this URI is taken and all base URIs are ignored.Copyright © 2016. All rights reserved.