|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovyx.net.http.EncoderRegistry
public class EncoderRegistry
This factory (or registry) handles request body "encoding." This is not
to be confused with HTTP content-encoding header. When a
body
is set from the builder, it is
processed based on the request content-type. For instance, if the body
is set to a map and the request content-type is JSON, the map will be
transformed to a JSON Object.
Most default encoders can handle a closure as a request body. In this
case, the closure is executed and a suitable 'builder' passed to the
closure that is used for constructing the content. In the case of
binary encoding this would be an OutputStream; for TEXT encoding it would
be a PrintWriter, and for XML it would be an already-bound
StreamingMarkupBuilder
.
Field Summary | |
---|---|
protected Map<String,Closure> |
registeredEncoders
|
Constructor Summary | |
---|---|
EncoderRegistry()
|
Method Summary | |
---|---|
protected Map<String,Closure> |
buildDefaultEncoderMap()
Returns a map of default encoders. |
protected org.apache.http.entity.StringEntity |
createEntity(ContentType ct,
String data)
Helper method used by encoder methods to creates an HttpEntity
instance that encapsulates the request data. |
org.apache.http.client.entity.UrlEncodedFormEntity |
encodeForm(Map<String,Object> params)
Set the request body as a url-encoded list of parameters. |
org.apache.http.HttpEntity |
encodeJSON(Object model)
Accepts a Map or a JavaBean object which is converted to JSON. |
org.apache.http.entity.InputStreamEntity |
encodeStream(Object data)
Default request encoder for a binary stream. |
org.apache.http.HttpEntity |
encodeText(Object data)
Default handler used for a plain text content-type. |
org.apache.http.HttpEntity |
encodeXML(Closure xmlBuilder)
Executes the given closure and passes a bound StreamingMarkupBuilder . |
void |
register(String contentType,
Closure closure)
Used to set an additional encoder for the given content type. |
void |
setCharset(String charset)
Set the charset used in the content-type header of all requests that send textual data. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Map<String,Closure> registeredEncoders
Constructor Detail |
---|
public EncoderRegistry()
Method Detail |
---|
public void setCharset(String charset)
charset
- Charset.forName(String)
public org.apache.http.entity.InputStreamEntity encodeStream(Object data) throws UnsupportedEncodingException
data
-
HttpEntity
encapsulating this request data
UnsupportedEncodingException
public org.apache.http.HttpEntity encodeText(Object data) throws IOException
PrintWriter
is passed as the single
argument to the closure. Any data sent to the writer from the
closure will be sent to the request content body.
data
-
HttpEntity
encapsulating this request data
IOException
public org.apache.http.client.entity.UrlEncodedFormEntity encodeForm(Map<String,Object> params) throws UnsupportedEncodingException
params
-
HttpEntity
encapsulating this request data
UnsupportedEncodingException
public org.apache.http.HttpEntity encodeXML(Closure xmlBuilder) throws UnsupportedEncodingException
StreamingMarkupBuilder
.
xmlBuilder
-
HttpEntity
encapsulating this request data
UnsupportedEncodingException
public org.apache.http.HttpEntity encodeJSON(Object model) throws UnsupportedEncodingException
JsonGroovyBuilder
as the closure's delegate. The closure
must return the result of the outermost builder method call.
model
- data to be converted to JSON, as specified above.
HttpEntity
encapsulating this request data
UnsupportedEncodingException
protected org.apache.http.entity.StringEntity createEntity(ContentType ct, String data) throws UnsupportedEncodingException
HttpEntity
instance that encapsulates the request data. This may be used by any
non-streaming encoder that needs to send textual data. It also sets the
charset
portion of the content-type header.
ct
- content-type of the datadata
- textual request data to be encoded
request content
UnsupportedEncodingException
public void register(String contentType, Closure closure)
HttpEntity
. It will also usually
accept a single argument, which will be the value given in
HTTPBuilder.SendDelegate.setBody(Object)
.
contentType
- closure
- protected Map<String,Closure> buildDefaultEncoderMap()
super.buildDefaultEncoderMap()
and then add or remove
from that result as well.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |