Search in sources :

Example 81 with BRefValueArray

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);
        }
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BString(org.ballerinalang.model.values.BString)

Example 82 with BRefValueArray

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();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 83 with BRefValueArray

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);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Channel(org.ballerinalang.nativeimpl.io.channels.base.Channel) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Aggregations

BRefValueArray (org.ballerinalang.model.values.BRefValueArray)83 BValue (org.ballerinalang.model.values.BValue)45 Test (org.testng.annotations.Test)40 BStruct (org.ballerinalang.model.values.BStruct)37 BString (org.ballerinalang.model.values.BString)22 BInteger (org.ballerinalang.model.values.BInteger)18 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)9 BeforeTest (org.testng.annotations.BeforeTest)9 BIntArray (org.ballerinalang.model.values.BIntArray)7 BMap (org.ballerinalang.model.values.BMap)7 BStringArray (org.ballerinalang.model.values.BStringArray)7 BXML (org.ballerinalang.model.values.BXML)7 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)7 HashMap (java.util.HashMap)6 BStructType (org.ballerinalang.model.types.BStructType)6 BRefType (org.ballerinalang.model.values.BRefType)5 SQLDatasource (org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)5 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)4 BFloatArray (org.ballerinalang.model.values.BFloatArray)4 IOException (java.io.IOException)3