use of org.ballerinalang.model.values.BStruct in project carbon-apimgt by wso2.
the class ConfigureXmlAnalyzer method execute.
@Override
public BValue[] execute(Context context) {
String event = getStringArgument(context, 0);
BStruct xmlInfo = ((BStruct) getRefArgument(context, 0));
if (xmlInfo != null) {
String xmlPolicyId = xmlInfo.getStringField(0);
switch(event) {
case THREAT_PROTECTION_POLICY_ADD:
case THREAT_PROTECTION_POLICY_UPDATE:
String name = xmlInfo.getStringField(1);
boolean dtdEnabled = xmlInfo.getBooleanField(0) != 0;
boolean externalEntitiesEnabled = xmlInfo.getBooleanField(1) != 0;
int maxXMLDepth = (int) xmlInfo.getIntField(0);
int elementCount = (int) xmlInfo.getIntField(1);
int attributeCount = (int) xmlInfo.getIntField(2);
int attributeLength = (int) xmlInfo.getIntField(3);
int entityExpansionLimit = (int) xmlInfo.getIntField(4);
int childrenPerElement = (int) xmlInfo.getIntField(5);
XMLConfig xmlConfig = new XMLConfig();
xmlConfig.setName(name);
xmlConfig.setDtdEnabled(dtdEnabled);
xmlConfig.setExternalEntitiesEnabled(externalEntitiesEnabled);
xmlConfig.setMaxDepth(maxXMLDepth);
xmlConfig.setMaxElementCount(elementCount);
xmlConfig.setMaxAttributeCount(attributeCount);
xmlConfig.setMaxAttributeLength(attributeLength);
xmlConfig.setEntityExpansionLimit(entityExpansionLimit);
xmlConfig.setMaxChildrenPerElement(childrenPerElement);
// put into ConfigurationHolder
ConfigurationHolder.addXmlConfig(xmlPolicyId, xmlConfig);
break;
case THREAT_PROTECTION_POLICY_DELETE:
ConfigurationHolder.removeXmlConfig(xmlPolicyId);
break;
default:
log.warn("Unknown event type for XML Threat Protection Policy. Event: " + event);
break;
}
}
return getBValues(new BBoolean(true));
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class BatchUpdate method execute.
@Override
public void execute(Context context) {
try {
BStruct bConnector = (BStruct) context.getRefArgument(0);
String query = context.getStringArgument(0);
BRefValueArray parameters = (BRefValueArray) context.getNullableRefArgument(1);
SQLDatasource datasource = (SQLDatasource) bConnector.getNativeData(Constants.CLIENT_CONNECTOR);
Map<String, String> tags = new HashMap<>();
tags.put(TAG_KEY_DB_STATEMENT, query);
tags.put(TAG_KEY_DB_TYPE, TAG_DB_TYPE_SQL);
TraceUtil.getTracer(context.getParentWorkerExecutionContext()).addTags(tags);
executeBatchUpdate(context, datasource, query, parameters);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class SQLDatasourceUtils method getSQLConnectorError.
public static BStruct getSQLConnectorError(Context context, Throwable throwable) {
PackageInfo sqlPackageInfo = context.getProgramFile().getPackageInfo(Constants.SQL_PACKAGE_PATH);
StructInfo errorStructInfo = sqlPackageInfo.getStructInfo(Constants.SQL_CONNECTOR_ERROR);
BStruct sqlConnectorError = new BStruct(errorStructInfo.getType());
if (throwable.getMessage() == null) {
sqlConnectorError.setStringField(0, Constants.SQL_EXCEPTION_OCCURED);
} else {
sqlConnectorError.setStringField(0, throwable.getMessage());
}
return sqlConnectorError;
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class Update method execute.
@Override
public void execute(Context context) {
try {
BStruct bConnector = (BStruct) context.getRefArgument(0);
String query = context.getStringArgument(0);
BRefValueArray parameters = (BRefValueArray) context.getNullableRefArgument(1);
SQLDatasource datasource = (SQLDatasource) bConnector.getNativeData(Constants.CLIENT_CONNECTOR);
Map<String, String> tags = new HashMap<>();
tags.put(TAG_KEY_DB_STATEMENT, query);
tags.put(TAG_KEY_DB_TYPE, TAG_DB_TYPE_SQL);
TraceUtil.getTracer(context.getParentWorkerExecutionContext()).addTags(tags);
executeUpdate(context, datasource, query, parameters);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
use of org.ballerinalang.model.values.BStruct in project ballerina by ballerina-lang.
the class GetClient method execute.
@Override
public void execute(Context context) {
BStruct clientEndPoint = (BStruct) context.getRefArgument(0);
BStruct clientConnector = (BStruct) clientEndPoint.getNativeData(Constants.B_CONNECTOR);
context.setReturnValues(clientConnector);
}
Aggregations