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;
}
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;
}
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;
}
Aggregations