use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class MultipartDataSource method checkForNestedParts.
/**
* If child part has nested parts, get a new boundary string and set it to Content-Type. After that write the
* child part headers to outputstream and serialize its nested parts if it has any.
*
* @param writer Represent the outputstream writer
* @param childPart Represent a child part
* @throws IOException When an error occurs while writing child part headers
*/
private void checkForNestedParts(Writer writer, BStruct childPart) throws IOException {
String childBoundaryString = null;
if (MimeUtil.isNestedPartsAvailable(childPart)) {
childBoundaryString = MimeUtil.getNewMultipartDelimiter();
BStruct mediaType = (BStruct) childPart.getRefField(MEDIA_TYPE_INDEX);
BMap<String, BValue> paramMap = (mediaType.getRefField(PARAMETER_MAP_INDEX) != null) ? (BMap<String, BValue>) mediaType.getRefField(PARAMETER_MAP_INDEX) : new BMap<>();
paramMap.put(BOUNDARY, new BString(childBoundaryString));
mediaType.setRefField(PARAMETER_MAP_INDEX, paramMap);
}
writeBodyPartHeaders(writer, childPart);
// Serialize nested parts
if (childBoundaryString != null) {
BRefValueArray nestedParts = (BRefValueArray) childPart.getNativeData(BODY_PARTS);
if (nestedParts != null && nestedParts.size() > 0) {
serializeBodyPart(this.outputStream, childBoundaryString, childPart);
}
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class SetBodyParts method execute.
@Override
public void execute(Context context) {
BStruct entityStruct = (BStruct) context.getRefArgument(FIRST_PARAMETER_INDEX);
BRefValueArray bodyParts = (BRefValueArray) context.getRefArgument(SECOND_PARAMETER_INDEX);
entityStruct.addNativeData(BODY_PARTS, bodyParts);
context.setReturnValues();
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class GetBodyParts method execute.
@Override
public void execute(Context context) {
BRefValueArray partsArray = new BRefValueArray();
try {
BStruct entityStruct = (BStruct) context.getRefArgument(FIRST_PARAMETER_INDEX);
// Get the body parts from entity's multipart data field, if they've been already been decoded
partsArray = EntityBodyHandler.getBodyPartArray(entityStruct);
if (partsArray == null || partsArray.size() < 1) {
Channel byteChannel = EntityBodyHandler.getByteChannel(entityStruct);
if (byteChannel != null) {
EntityBodyHandler.decodeEntityBody(context, entityStruct, byteChannel);
// Check the body part availability for the second time, since the parts will be by this
// time populated from bytechannel
partsArray = EntityBodyHandler.getBodyPartArray(entityStruct);
// Set byte channel that belongs to parent entity to null, once the message body parts have
// been decoded
entityStruct.addNativeData(ENTITY_BYTE_CHANNEL, null);
}
}
} catch (Throwable e) {
context.setReturnValues(MimeUtil.createEntityError(context, "Error occurred while extracting body parts from entity: " + e.getMessage()));
}
context.setReturnValues(partsArray);
}
Aggregations