Search in sources :

Example 1 with StreamingMarkupBuilder

use of groovy.xml.StreamingMarkupBuilder in project rest-assured by rest-assured.

the class EncoderRegistry method encodeXML.

/**
 * Encode the content as XML.  The argument may be either an object whose
 * <code>toString</code> produces valid markup, or a Closure which will be
 * interpreted as a builder definition.
 *
 * @param xml data that defines the XML structure
 * @return an {@link HttpEntity} encapsulating this request data
 * @throws UnsupportedEncodingException
 */
public HttpEntity encodeXML(Object contentType, Object xml) throws UnsupportedEncodingException {
    String contentTypeAsString = contentTypeToString(contentType);
    if (xml instanceof Closure) {
        StreamingMarkupBuilder smb = new StreamingMarkupBuilder();
        xml = smb.bind(xml);
    } else if (xml instanceof File) {
        xml = toString((File) xml, contentTypeAsString);
    }
    return createEntity(contentTypeAsString, xml);
}
Also used : StreamingMarkupBuilder(groovy.xml.StreamingMarkupBuilder) MethodClosure(org.codehaus.groovy.runtime.MethodClosure) Closure(groovy.lang.Closure) FileReader.readToString(io.restassured.internal.support.FileReader.readToString) GString(groovy.lang.GString)

Aggregations

Closure (groovy.lang.Closure)1 GString (groovy.lang.GString)1 StreamingMarkupBuilder (groovy.xml.StreamingMarkupBuilder)1 FileReader.readToString (io.restassured.internal.support.FileReader.readToString)1 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)1