Search in sources :

Example 1 with EntityWrapper

use of org.ballerinalang.mime.util.EntityWrapper 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)

Example 2 with EntityWrapper

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

the class Util method getBinaryBodyPart.

/**
 * Get a binary body part from a given blob content.
 *
 * @param result Result of ballerina file compilation
 * @return A ballerina struct that represent a body part
 */
static BStruct getBinaryBodyPart(CompileResult result) {
    BStruct bodyPart = getEntityStruct(result);
    EntityWrapper byteChannel = EntityBodyHandler.getEntityWrapper("Ballerina binary part");
    bodyPart.addNativeData(ENTITY_BYTE_CHANNEL, byteChannel);
    MimeUtil.setContentType(getMediaTypeStruct(result), bodyPart, OCTET_STREAM);
    return bodyPart;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) EntityWrapper(org.ballerinalang.mime.util.EntityWrapper)

Example 3 with EntityWrapper

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

the class Util method getJsonBodyPart.

/**
 * Get a json body part from a given json content.
 *
 * @param result Result of ballerina file compilation
 * @return A ballerina struct that represent a body part
 */
static BStruct getJsonBodyPart(CompileResult result) {
    String key = "bodyPart";
    String value = "jsonPart";
    String jsonContent = "{\"" + key + "\":\"" + value + "\"}";
    BStruct bodyPart = getEntityStruct(result);
    EntityWrapper byteChannel = EntityBodyHandler.getEntityWrapper(jsonContent);
    bodyPart.addNativeData(ENTITY_BYTE_CHANNEL, byteChannel);
    MimeUtil.setContentType(getMediaTypeStruct(result), bodyPart, APPLICATION_JSON);
    return bodyPart;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) EntityWrapper(org.ballerinalang.mime.util.EntityWrapper) BString(org.ballerinalang.model.values.BString)

Aggregations

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