public class DefaultHttpClient extends java.lang.Object implements HttpClient
final HttpClient httpClient = new DefaultHttpClient.Builder(); final SomePOJORequest postPojo = new MyPOJO("id", "data"); final Response<SomePOJOResponse> postResponse = httpClient.post("http://localhost/pojo", postPojo, SomePOJOResponse.class); final Response<SomePOJOResponse> getResponse = httpClient.get("http://localhost/pojo/id", SomePOJOResponse.class); final SomePOJORequest putPojo = new MyPOJO("updated-data"); final Response<SomePOJOResponse> postResponse = httpClient.post("http://localhost/pojo/id", putPojo, SomePOJOResponse.class); final Response<Map> deleteResponse = httpClient.delete("http://localhost/pojo/id");
Modifier and Type | Class and Description |
---|---|
static class |
DefaultHttpClient.Builder
Builder for a
DefaultHttpClient , see docs for that class for example usage. |
Modifier and Type | Method and Description |
---|---|
protected java.net.HttpURLConnection |
createHttpUrlConnection(java.lang.String url)
Override this method if you would like to implement a custom URL connection.
|
<B> Response<B> |
delete(java.lang.String url,
java.util.List<Parameter> parameters,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.lang.Class<B> clazz)
Perform
DELETE operation against an endpoint. |
<B> Response<B> |
get(java.lang.String url,
java.util.List<Parameter> parameters,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.lang.Class<B> clazz)
Perform
GET operation against an endpoint. |
void |
get(java.lang.String url,
java.util.List<Parameter> parameters,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.nio.file.Path dest,
int retries)
Perform
GET operation that downloads a file to the given path. |
protected java.io.InputStream |
getInputStream(java.net.HttpURLConnection httpUrlConnection,
java.lang.String body,
java.lang.String method,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders)
Initialize the connection with the given parameters, then return the provisioned input stream.
|
<R,B> Response<B> |
post(java.lang.String url,
R request,
java.util.List<Parameter> parameters,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.lang.Class<B> clazz)
Perform
POST operation against an endpoint. |
<R,B> Response<B> |
put(java.lang.String url,
R request,
java.util.List<Parameter> parameters,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.lang.Class<B> clazz)
Perform
PUT operation against an endpoint. |
protected java.lang.String |
urlWithParameters(java.lang.String url,
java.util.List<Parameter> parameters)
Rebuild the URL with parameters appended.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
delete, delete, get, get, modifyConnection, post, put
public <B> Response<B> get(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
HttpClient
GET
operation against an endpoint.get
in interface HttpClient
B
- The response body type.url
- The URL on which to perform the operation.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.public void get(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.nio.file.Path dest, int retries) throws java.lang.InterruptedException
HttpClient
GET
operation that downloads a file to the given path.get
in interface HttpClient
url
- The URL on which to perform the operation.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.dest
- The destination to which the file will be downloaded.retries
- The retry attempt index, if download fails.java.lang.InterruptedException
- The thread was interrupted during retries.public <R,B> Response<B> post(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
HttpClient
POST
operation against an endpoint.post
in interface HttpClient
R
- The Request type.B
- The Response body type.url
- The URL on which to perform the operation.request
- The element to be serialized into the request body.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.public <R,B> Response<B> put(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
HttpClient
PUT
operation against an endpoint.put
in interface HttpClient
R
- The Request type.B
- The Response body type.url
- The URL on which to perform the operation.request
- The element to be serialized into the request body.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.public <B> Response<B> delete(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
HttpClient
DELETE
operation against an endpoint.delete
in interface HttpClient
B
- The Response body type.url
- The URL on which to perform the operation.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.protected java.net.HttpURLConnection createHttpUrlConnection(java.lang.String url) throws java.io.IOException
url
- The URL to connect to.java.io.IOException
- An I/O exception occurred.protected java.lang.String urlWithParameters(java.lang.String url, java.util.List<Parameter> parameters) throws java.io.UnsupportedEncodingException
url
- The URL to rebuild.parameters
- The parameters to append.java.io.UnsupportedEncodingException
- An encoding exception occurred.protected java.io.InputStream getInputStream(java.net.HttpURLConnection httpUrlConnection, java.lang.String body, java.lang.String method, java.util.Map<java.lang.String,java.lang.String> additionalHeaders) throws java.io.IOException
httpUrlConnection
- The connection to initialize.body
- The request body for the stream.method
- The HTTP method.additionalHeaders
- Additional headers for the request.java.io.IOException
- An I/O exception occurred.