|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovyx.net.http.HttpURLClient
public class HttpURLClient
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:
Field Summary | |
---|---|
protected org.apache.commons.logging.Log |
log
Logger instance defined for use by sub-classes |
protected groovyx.net.http.HttpURLClient.OAuthWrapper |
oauth
|
Constructor Summary | |
---|---|
HttpURLClient()
|
Method Summary | |
---|---|
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()
See setFollowRedirects(boolean) |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected groovyx.net.http.HttpURLClient.OAuthWrapper oauth
protected org.apache.commons.logging.Log log
Constructor Detail |
---|
public HttpURLClient()
Method Detail |
---|
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 parameters
URISyntaxException
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()
setFollowRedirects(boolean)
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |