Search in sources :

Example 1 with EntityBodyChannel

use of org.ballerinalang.mime.util.EntityBodyChannel in project ballerina by ballerina-lang.

the class Util method getXmlBodyPart.

/**
 * Get a xml body part from a given xml content.
 *
 * @param result Result of ballerina file compilation
 * @return A ballerina struct that represent a body part
 */
static BStruct getXmlBodyPart(CompileResult result) {
    BXMLItem xmlContent = new BXMLItem("<name>Ballerina</name>");
    BStruct bodyPart = getEntityStruct(result);
    EntityBodyChannel byteChannel = new EntityBodyChannel(new ByteArrayInputStream(xmlContent.getMessageAsString().getBytes(StandardCharsets.UTF_8)));
    bodyPart.addNativeData(ENTITY_BYTE_CHANNEL, new EntityWrapper(byteChannel));
    MimeUtil.setContentType(getMediaTypeStruct(result), bodyPart, APPLICATION_XML);
    return bodyPart;
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BStruct(org.ballerinalang.model.values.BStruct) EntityBodyChannel(org.ballerinalang.mime.util.EntityBodyChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityWrapper(org.ballerinalang.mime.util.EntityWrapper)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 EntityBodyChannel (org.ballerinalang.mime.util.EntityBodyChannel)1 EntityWrapper (org.ballerinalang.mime.util.EntityWrapper)1 BStruct (org.ballerinalang.model.values.BStruct)1 BXMLItem (org.ballerinalang.model.values.BXMLItem)1