use of org.ballerinalang.model.values.BMap in project carbon-apimgt by wso2.
the class Publish method execute.
@Override
public BValue execute(Context context) {
log.info("publishing event to DAS");
BConnector bConnector = (BConnector) getRefArgument(context, 0);
BJSON json = (BJSON) getRefArgument(context, 1);
String streamName = json.value().get(Constants.STREAM_NAME).asText();
String streamVersion = json.value().get(Constants.STREAM_VERSION).asText();
ArrayNode metaData = (ArrayNode) json.value().get(Constants.META_DATA);
ArrayNode correlationData = (ArrayNode) json.value().get(Constants.CORRELATION_DATA);
ArrayNode payloadData = (ArrayNode) json.value().get(Constants.PAYLOAD_DATA);
Object[] metaDataArr = new Object[metaData.size()];
JSONArray jsonMetaData = new JSONArray(metaData.toString());
for (int i = 0; i < jsonMetaData.length(); i++) {
metaDataArr[i] = jsonMetaData.get(i);
}
Object[] correlationDataArr = new Object[correlationData.size()];
JSONArray jsonCorrelationData = new JSONArray(correlationData.toString());
for (int i = 0; i < jsonCorrelationData.length(); i++) {
correlationDataArr[i] = jsonCorrelationData.get(i);
}
Object[] payloadDataArr = new Object[payloadData.size()];
JSONArray jsonPayloadData = new JSONArray(payloadData.toString());
for (int i = 0; i < jsonPayloadData.length(); i++) {
payloadDataArr[i] = jsonPayloadData.get(i);
}
BMap sharedMap = (BMap) bConnector.getRefField(1);
EventPublisher pub = (EventPublisher) sharedMap.get(Constants.PUBLISHER_INSTANCE);
Event event = new Event();
event.setStreamId(DataBridgeCommonsUtils.generateStreamId(streamName, streamVersion));
event.setMetaData(metaDataArr);
event.setCorrelationData(correlationDataArr);
event.setPayloadData(payloadDataArr);
pub.publish(event);
return null;
}
use of org.ballerinalang.model.values.BMap in project carbon-apimgt by wso2.
the class Init method execute.
@Override
public BValue execute(Context context) {
BConnector bConnector = (BConnector) getRefArgument(context, 0);
BMap optionMap = (BMap) bConnector.getRefField(0);
BMap sharedMap = (BMap) bConnector.getRefField(1);
System.setProperty("javax.net.ssl.trustStore", System.getProperty("ballerina.home") + File.separator + "bre" + File.separator + "security" + File.separator + "wso2carbon.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
String type = optionMap.get(Constants.TYPE).stringValue();
String receiverURLSet = optionMap.get(Constants.RECEIVER_URL_SET).stringValue();
String authURLSet = optionMap.get(Constants.AUTH_URL_SET).stringValue();
String username = optionMap.get(Constants.USERNAME).stringValue();
String password = optionMap.get(Constants.PASSWORD).stringValue();
String configPath = optionMap.get(Constants.CONFIG_PATH).stringValue();
configPath = System.getProperty("ballerina.home") + File.separator + configPath;
try {
initDataPublisher(type, receiverURLSet, authURLSet, username, password, configPath);
sharedMap.put(Constants.PUBLISHER_INSTANCE, this);
} catch (DataEndpointAuthenticationException e) {
log.error("Error occurred while authenticating.", e);
} catch (DataEndpointAgentConfigurationException e) {
log.error("Error occurred while configuring the publisher.", e);
} catch (TransportException e) {
log.error("Transport level exception occurred.", e);
} catch (DataEndpointException e) {
log.error("Data endpoint exception occurred.", e);
} catch (DataEndpointConfigurationException e) {
log.error("Data endpoint configuration exception occurred.", e);
}
return null;
}
Aggregations