|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovyx.net.http.HTTPBuilder.SendDelegate
protected class HTTPBuilder.SendDelegate
Encloses all properties and method calls used within the
HTTPBuilder.request(Object, Method, Object, Closure)
'config'
closure argument.
Field Summary | |
---|---|
protected Object |
contentType
|
protected Map<String,String> |
headers
|
protected org.apache.http.client.methods.HttpRequestBase |
request
|
protected String |
requestContentType
|
protected Map<String,Closure> |
responseHandlers
|
protected URIBuilder |
url
|
Constructor Summary | |
---|---|
HTTPBuilder.SendDelegate(org.apache.http.client.methods.HttpRequestBase request,
Object contentType,
Map<String,String> defaultRequestHeaders,
Map<String,Closure> defaultResponseHandlers)
|
Method Summary | |
---|---|
protected Closure |
findResponseHandler(int statusCode)
Get the proper response handler for the response code. |
protected Object |
getContentType()
Get the content-type of any data sent in the request body and the expected response content-type. |
Map<String,String> |
getHeaders()
Get request headers (including any default headers). |
protected org.apache.http.client.methods.HttpRequestBase |
getRequest()
|
protected String |
getRequestContentType()
The request content-type, if different from the contentType . |
Map<String,Closure> |
getResponse()
Access the response handler map to set response parsing logic. |
URIBuilder |
getURL()
Use this object to manipulate parts of the request URL, like query params and request path. |
void |
send(Object contentType,
Object requestBody)
Convenience method to set a request content-type at the same time the request body is set. |
void |
setBody(Object body)
Set the request body. |
protected void |
setContentType(Object ct)
Set the content-type used for any data in the request body, as well as the Accept content-type that will be used for parsing
the response. |
void |
setHeaders(Map<?,?> newHeaders)
Set request headers. |
protected void |
setPropertiesFromMap(Map<String,?> args)
Valid arguments: urlEither a URI, URL, or String. |
protected void |
setRequestContentType(String ct)
Assign a different content-type for the request than is expected for the response. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.apache.http.client.methods.HttpRequestBase request
protected Object contentType
protected String requestContentType
protected Map<String,Closure> responseHandlers
protected URIBuilder url
protected Map<String,String> headers
Constructor Detail |
---|
public HTTPBuilder.SendDelegate(org.apache.http.client.methods.HttpRequestBase request, Object contentType, Map<String,String> defaultRequestHeaders, Map<String,Closure> defaultResponseHandlers)
Method Detail |
---|
public URIBuilder getURL()
builder.request(GET,XML) { url.path = '../other/request.jsp' url.params = [p1:1, p2:2] ... }
URIBuilder
to manipulate the request URLprotected org.apache.http.client.methods.HttpRequestBase getRequest()
protected Object getContentType()
setContentType(Object)
or passed from the HTTPBuilder.defaultContentType
when this
SendDelegateinstance was constructed.protected void setContentType(Object ct)
Accept
content-type that will be used for parsing
the response. The value should be either a ContentType
value
or a String, i.e. "text/plain"
ct
- content-type to send and recieve contentprotected String getRequestContentType()
contentType
.
protected void setRequestContentType(String ct)
getContentType()
will always control the Accept
header, and will be used for the request content unless this
value is also explicitly set.
ct
- either a ContentType
value or a valid content-type
String.protected void setPropertiesFromMap(Map<String,?> args) throws MalformedURLException, URISyntaxException
args
- named parameters to set properties on this delegate.
MalformedURLException
URISyntaxException
public void setHeaders(Map<?,?> newHeaders)
default request headers.
(The assumption is you'll probably want to add a bunch of headers to
whatever defaults you've already set). If you only want to
use values set here, simply call headers.clear()
first.
public Map<String,String> getHeaders()
Accept
, Content-Type
,
or Content-Encoding
headers that are automatically
handled by any encoder or parsers in effect. Note that any values
set here will override any of those automatically assigned
values.
header that is a
public void send(Object contentType, Object requestBody)
setBody(Object)
that allows for a different content-type
than what is expected for the response.
Example:
http.request(POST,HTML) { /* request data is interpreted as a JsonBuilder closure in the default EncoderRegistry implementation * / send( 'text/javascript' ) { a : ['one','two','three'] } // response content-type is what was specified in the outer request() argument: response.success = { resp, html -> } }
contentType
- either a ContentType
or content-type
string like "text/xml"
requestBody
- public void setBody(Object body)
request encoder
.
body
- data or closure interpretes as the request bodysend(Object, Object)
protected Closure findResponseHandler(int statusCode)
HTTPBuilder
class in order to find the proper handler
based on the response status code.
statusCode
- HTTP response status code
public Map<String,Closure> getResponse()
builder.request( GET, XML ) { response.success = { xml -> /* for XML content type, the default parser will return an XmlSlurper * / xml.root.children().each { println it } } }
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |