Search in sources :

Example 1 with BMap

use of org.ballerinalang.jvm.values.api.BMap in project product-microgateway by wso2.

the class MGWJWTGeneratorInvoker method getRetrievedClaims.

public static BMap<String, Object> getRetrievedClaims(BMap<String, Object> authContext) {
    try {
        List<ClaimDTO> claimList = abstractMGWClaimRetriever.retrieveClaims(convertBMapToMap(authContext));
        if (claimList == null) {
            return null;
        }
        BPackage packageId = new BPackage("wso2", "gateway", "3.2.1");
        BMap<String, Object> bMap = BValueCreator.createRecordValue(packageId, "RetrievedUserClaimsListDTO");
        bMap.put("count", claimList.size());
        BArray bArray = (BArray) bMap.get("list");
        for (Object claimDTO : claimList) {
            bArray.append(BValueCreator.createRecordValue(packageId, "ClaimDTO", (Map<String, Object>) claimDTO));
        }
        return bMap;
    // Not to break the flow if an exception occured during claim retrieval
    } catch (Exception e) {
        log.error("Error while retrieving user claims from remote url.", e);
        return null;
    }
}
Also used : ClaimDTO(org.wso2.micro.gateway.jwt.generator.ClaimDTO) HashMap(java.util.HashMap) Map(java.util.Map) BMap(org.ballerinalang.jvm.values.api.BMap) BArray(org.ballerinalang.jvm.values.api.BArray) InvocationTargetException(java.lang.reflect.InvocationTargetException) BPackage(org.ballerinalang.jvm.types.BPackage)

Example 2 with BMap

use of org.ballerinalang.jvm.values.api.BMap in project product-microgateway by wso2.

the class Request method getQueryParamValue.

/**
 * Gets the query param value associated with the given key.
 *
 * @param key Represents the query param key.
 * @return Returns the query param value associated with the given key as a string. If multiple param values are
 * present, then the first value is returned. Null is returned if no key is found.
 */
public String getQueryParamValue(String key) {
    BMap mapValue = getNativeQueryParams();
    BArray arrayValue = ((MapValue) mapValue).getArrayValue(key);
    if (arrayValue != null) {
        return arrayValue.get(0).toString();
    }
    return null;
}
Also used : BMap(org.ballerinalang.jvm.values.api.BMap) MapValue(org.ballerinalang.jvm.values.MapValue) BArray(org.ballerinalang.jvm.values.api.BArray)

Example 3 with BMap

use of org.ballerinalang.jvm.values.api.BMap in project product-microgateway by wso2.

the class Request method getPathParams.

/**
 * Gets the path parameters of the request as a map.
 *
 * @return {@link Map} Map of path parameters. Map with size 0 is returned if path parameters does not present.
 */
public Map<String, String> getPathParams() {
    Map<String, String> pathParamMap = new HashMap<>();
    Map<String, Object> attributes = Utils.getInvocationContextAttributes();
    if (attributes.containsKey(Constants.REQUEST_PATH_PARAMS)) {
        BMap mapValues = (BMap) attributes.get(Constants.REQUEST_PATH_PARAMS);
        pathParamMap = InterceptorUtils.convertBMapToMap(mapValues);
    }
    return pathParamMap;
}
Also used : HashMap(java.util.HashMap) BMap(org.ballerinalang.jvm.values.api.BMap) JSONObject(org.json.JSONObject)

Example 4 with BMap

use of org.ballerinalang.jvm.values.api.BMap in project product-microgateway by wso2.

the class Request method getQueryParamValues.

/**
 * Gets all the query param values associated with the given key.
 *
 * @param key Represents the query param key.
 * @return Returns all the query param values associated with the given key as a `String[]`.
 * Null is returned if no key is found.
 */
public String[] getQueryParamValues(String key) {
    BMap mapValue = getNativeQueryParams();
    BArray arrayValue = ((MapValue) mapValue).getArrayValue(key);
    if (arrayValue != null) {
        return arrayValue.getStringArray();
    }
    return null;
}
Also used : BMap(org.ballerinalang.jvm.values.api.BMap) MapValue(org.ballerinalang.jvm.values.MapValue) BArray(org.ballerinalang.jvm.values.api.BArray)

Example 5 with BMap

use of org.ballerinalang.jvm.values.api.BMap in project product-microgateway by wso2.

the class Utils method addDataToContextAttributes.

/**
 * Add the data to invocation context attributes map as key, value pairs.
 *
 * @param key The string type key used in the attribute map.
 * @param value The value to be inserted in to the attribute map.
 */
public static void addDataToContextAttributes(String key, Object value) {
    BMap attributesMap = (BMap) GetInvocationContext.getInvocationContext().get("attributes");
    attributesMap.put(key, value);
}
Also used : BMap(org.ballerinalang.jvm.values.api.BMap)

Aggregations

BMap (org.ballerinalang.jvm.values.api.BMap)5 BArray (org.ballerinalang.jvm.values.api.BArray)3 HashMap (java.util.HashMap)2 MapValue (org.ballerinalang.jvm.values.MapValue)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 BPackage (org.ballerinalang.jvm.types.BPackage)1 JSONObject (org.json.JSONObject)1 ClaimDTO (org.wso2.micro.gateway.jwt.generator.ClaimDTO)1