use of org.ballerinalang.model.values.BString in project carbon-apimgt by wso2.
the class Analyze method execute.
@Override
public BValue[] execute(Context context) {
String payloadType = getStringArgument(context, 0);
String payload = getStringArgument(context, 1);
String apiContext = getStringArgument(context, 2);
String policyId = getStringArgument(context, 3);
APIMThreatAnalyzer analyzer = AnalyzerHolder.getAnalyzer(payloadType, policyId);
if (analyzer == null) {
return getBValues(new BBoolean(false), new BString("Unknown Payload Type"));
}
boolean noThreatsDetected = true;
String errMessage = null;
try {
analyzer.analyze(payload, apiContext);
} catch (APIMThreatAnalyzerException e) {
noThreatsDetected = false;
errMessage = e.getMessage();
}
AnalyzerHolder.returnObject(analyzer);
return getBValues(new BBoolean(noThreatsDetected), new BString(errMessage));
}
use of org.ballerinalang.model.values.BString in project carbon-apimgt by wso2.
the class PutCacheEntry method execute.
@Override
public BValue[] execute(Context context) {
String cacheName = getStringArgument(context, 0);
String cacheKey = getStringArgument(context, 1);
BValue cacheEntry = getRefArgument(context, 0);
// TODO If cache is not created then need to send proper message or create and put entry.
CacheManagerHolder.getInstance().getCacheManager().getCache(cacheName).put(cacheKey, cacheEntry);
return getBValues(new BString(cacheName));
}
use of org.ballerinalang.model.values.BString in project carbon-apimgt by wso2.
the class CacheTest method testCacheForNonExistence.
@Test
public void testCacheForNonExistence() {
ProgramFile bLangProgram1 = BTestUtils.parseBalFile("samples/cache/nonExistenceEntryCacheTest.bal");
// Create arguments to initiate cache
BValue[] args = { new BString("cacheName"), new BString("15"), new BString("cacheKey") };
// Test ballerina cache create, put and get for BString
BValue[] returns = BLangFunctions.invokeNew(bLangProgram1, "testCacheForNonExistence", args);
Assert.assertTrue(returns[0] instanceof BBoolean);
BBoolean value = (BBoolean) returns[0];
Assert.assertFalse(value.booleanValue());
}
use of org.ballerinalang.model.values.BString in project carbon-apimgt by wso2.
the class MapRemoveTestCase method testCacheOperations.
@Test
public void testCacheOperations() {
// Create arguments to initiate map put
BValue[] args = { new BString("testMapEntry"), new BString("testMapValue") };
// Test ballerina map put, remove and get
BValue[] returns = BLangFunctions.invokeNew(bLangProgram, "testMapRemove", args);
// Assert if cache entry is BValue
Assert.assertTrue(returns[0] instanceof BValue);
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class Replace method execute.
@Override
public void execute(Context context) {
String mainString = context.getStringArgument(0);
String replacePattern = context.getStringArgument(1);
String replaceWith = context.getStringArgument(2);
String replacedString = mainString.replace(replacePattern, replaceWith);
context.setReturnValues(new BString(replacedString));
}
Aggregations