|
|||||||||
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 cotnent-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 HttpEntity |
createEntity(ContentType ct,
String data)
|
HttpEntity |
encodeForm(Map<String,Object> params)
Set the request body as a url-encoded list of parameters. |
HttpEntity |
encodeJSON(Object model)
Accepts a Map or a JavaBean object which is converted to JSON. |
HttpEntity |
encodeStream(Object data)
Default request encoder for a binary stream. |
HttpEntity |
encodeText(Object data)
Default handler used for a text content-type. |
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)
|
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)
public HttpEntity encodeStream(Object data) throws UnsupportedEncodingException
data
-
UnsupportedEncodingException
public 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
-
IOException
public HttpEntity encodeForm(Map<String,Object> params) throws UnsupportedEncodingException
params
-
UnsupportedEncodingException
public HttpEntity encodeXML(Closure xmlBuilder) throws UnsupportedEncodingException
StreamingMarkupBuilder
.
xmlBuilder
-
UnsupportedEncodingException
public 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
-
UnsupportedEncodingException
protected HttpEntity createEntity(ContentType ct, String data) throws UnsupportedEncodingException
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 |