public class Client extends Object implements Closeable
Client httpClient = new Client(); User user = httpClient.url("http://localhost:8080/api/user").jsonPost(user).resource(User.class);
Modifier and Type | Class and Description |
---|---|
class |
Client.Request
Provides the bridge between the wrapper and the underlying ning request
|
class |
Client.RequestHolder
provides the User facing API for building WS request.
|
Modifier and Type | Field and Description |
---|---|
protected List<BodyReader> |
bodyReaders |
protected List<BodyWriter> |
bodyWriters |
protected com.ning.http.client.AsyncHttpClientConfig.Builder |
builder |
protected com.ning.http.client.AsyncHttpClient |
client |
protected OAuth2Config |
oAuth2Config |
protected OAuth2Config.Builder |
oAuth2ConfigBuilder |
Constructor and Description |
---|
Client()
Create an HTTP client with default configuration
|
Client(com.ning.http.client.AsyncHttpClientConfig.Builder builder)
Create an HTTP client with a pre-configured Builder
|
Modifier and Type | Method and Description |
---|---|
Client |
addBodyReader(BodyReader br)
Add a candidate BodyReader to read an HTTP response body to an object
|
Client |
addBodyWriter(BodyWriter bw)
Add a candidate BodyWriter to serialize an object to an HTTP response
body
|
void |
close() |
com.ning.http.client.AsyncHttpClient |
getNativeClient()
Return the AsyncHttpClient native client for advanced features
|
Client |
setAuth(String username,
String password,
com.ning.http.client.Realm.AuthScheme scheme)
Sets the authentication header for the current client.
|
Client |
setOAuth2(String username,
String password,
String accessTokenEndpoint,
String clientId,
String clientSecret)
Sets the OAuth2 authentication header for the current client.
|
Client |
setOAuth2Builder(OAuth2Config.Builder builder)
Set the given OAuth2Config builder for this client.
|
Client |
setProxy(String host,
int port)
Set HTTP proxy configuration
|
Client.RequestHolder |
url(String url)
Prepare a new request.
|
protected com.ning.http.client.AsyncHttpClient client
protected com.ning.http.client.AsyncHttpClientConfig.Builder builder
protected OAuth2Config.Builder oAuth2ConfigBuilder
protected OAuth2Config oAuth2Config
protected List<BodyReader> bodyReaders
protected List<BodyWriter> bodyWriters
public Client()
public Client(com.ning.http.client.AsyncHttpClientConfig.Builder builder)
AsyncHttpClientConfig.Builder
public com.ning.http.client.AsyncHttpClient getNativeClient()
public Client addBodyReader(BodyReader br)
br
- a bodyreaderBodyReader
public Client addBodyWriter(BodyWriter bw)
bw
- a bodywriterBodyWriter
public Client setAuth(String username, String password, com.ning.http.client.Realm.AuthScheme scheme)
username
- username identifierpassword
- user passwordscheme
- authentication schemepublic Client setOAuth2Builder(OAuth2Config.Builder builder)
builder
- builder to setpublic Client setOAuth2(String username, String password, String accessTokenEndpoint, String clientId, String clientSecret)
username
- The user's loginpassword
- The user's passwordaccessTokenEndpoint
- URL of the OAuth2.0 access token endpoint
serviceclientId
- id of the current application registered with the remote
OAuth2.0 providerclientSecret
- secret of the current application registered with the
remote OAuth2.0 providerpublic Client.RequestHolder url(String url)
url
- the URL to requestpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2009–2014. All rights reserved.