public class HttpURLClient extends Object
This class provides a simplified API similar to HTTPBuilder
, but
uses HttpURLConnection
for I/O so that it is compatible
with Google App Engine. Features:
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
log
Logger instance defined for use by sub-classes
|
protected groovyx.net.http.HttpURLClient.OAuthWrapper |
oauth |
Constructor and Description |
---|
HttpURLClient() |
Modifier and Type | Method and Description |
---|---|
Object |
getContentType()
Get the default content-type used for parsing response data.
|
EncoderRegistry |
getEncoders()
Get the encoder registry used by this instance, which can be used
to directly modify the request serialization behavior.
|
Map<String,String> |
getHeaders()
Retrieve the default headers that will be sent in each request.
|
ParserRegistry |
getParsers()
Retrieve the parser registry used by this instance, which can be used to
directly modify the parsing behavior.
|
Object |
getRequestContentType()
Get the default content-type used to serialize the request data.
|
Object |
getUrl()
The default URL for this request.
|
boolean |
isFollowRedirects()
|
HttpResponseDecorator |
request(Map<String,?> args)
Perform a request.
|
void |
setBasicAuth(Object user,
Object pass)
Set basic user and password authorization to be used for every request.
|
void |
setContentType(Object ct)
Set the default content-type used to control response parsing and request
serialization behavior.
|
void |
setEncoders(EncoderRegistry encoderRegistry) |
void |
setFollowRedirects(boolean follow)
Control whether this instance should automatically follow redirect
responses.
|
void |
setHeaders(Map<?,?> headers)
Set default headers to be sent with every request.
|
void |
setOAuth(Object consumerKey,
Object consumerSecret,
Object accessToken,
Object accessSecret)
Sign all outbound requests with the given OAuth keys and tokens.
|
void |
setParsers(ParserRegistry parserRegistry) |
void |
setRequestContentType(Object requestContentType)
Set the default content-type used to control request body serialization.
|
void |
setUrl(Object url)
Set the default request URL.
|
protected groovyx.net.http.HttpURLClient.OAuthWrapper oauth
protected org.apache.commons.logging.Log log
public HttpURLClient()
public HttpResponseDecorator request(Map<String,?> args) throws URISyntaxException, MalformedURLException, IOException
URLConnection.setReadTimeout(int)
body
parameter is also specified.Content-Type
header is used to determine how to parse the response.Content-Type
header. This defaults to the
contentType
if unset.args
- named parametersURISyntaxException
MalformedURLException
IOException
public void setBasicAuth(Object user, Object pass) throws UnsupportedEncodingException
null
to un-set authorization for this instance.user
- pass
- UnsupportedEncodingException
public void setOAuth(Object consumerKey, Object consumerSecret, Object accessToken, Object accessSecret)
consumerKey
- null if you want to _stop_ signing requests.consumerSecret
- accessToken
- accessSecret
- public void setFollowRedirects(boolean follow)
HttpURLConnection.setInstanceFollowRedirects(boolean)
follow
- true if the connection should automatically follow
redirect responses from the server.public boolean isFollowRedirects()
public Object getUrl()
URIBuilder
which can
be used to easily manipulate portions of the request URL.public void setUrl(Object url) throws URISyntaxException
url
- any object whose toString()
produces a valid URI.URISyntaxException
URIBuilder.convertToURI(Object)
public Map<String,String> getHeaders()
public void setHeaders(Map<?,?> headers)
headers
- public EncoderRegistry getEncoders()
client.encoders.'application/xml' = {....}
.public void setEncoders(EncoderRegistry encoderRegistry)
public ParserRegistry getParsers()
public void setParsers(ParserRegistry parserRegistry)
public Object getContentType()
ContentType
object. Defaults to
ContentType.ANY
public void setContentType(Object ct)
null
is passed,
ContentType.ANY
will be used. If this value is
ContentType.ANY
, the response Content-Type
header is
used to parse the response.ct
- a String or ContentType
value.public Object getRequestContentType()
public void setRequestContentType(Object requestContentType)
contentType property
is used.
Additionally, if the contentType
is ContentType.ANY
,
a requestContentType
must be specified when
performing a POST or PUT request that sends request data.requestContentType
- String or ContentType
value.Copyright © 2008-2014. All Rights Reserved.