use of com.tremolosecurity.config.xml.MessageListenerType in project OpenUnison by TremoloSecurity.
the class LoadQueueListenersFromK8s method createQueue.
private void createQueue(TremoloType tremolo, String name, JSONObject item) throws ProvisioningException {
JSONObject spec = (JSONObject) item.get("spec");
MessageListenerType mlt = new MessageListenerType();
mlt.setQueueName(name);
StringBuffer b = new StringBuffer();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("className"));
mlt.setClassName(b.toString());
JSONArray params = (JSONArray) spec.get("params");
for (Object o : params) {
JSONObject param = (JSONObject) o;
ParamType pt = new ParamType();
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("name"));
pt.setName(b.toString());
b.setLength(0);
OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("value"));
pt.setValue(b.toString());
mlt.getParams().add(pt);
}
HttpCon nonwatchHttp = null;
JSONArray secretParams = (JSONArray) spec.get("secretParams");
if (secretParams != null) {
try {
nonwatchHttp = this.k8sWatch.getK8s().createClient();
String token = this.k8sWatch.getK8s().getAuthToken();
for (Object o : secretParams) {
JSONObject secretParam = (JSONObject) o;
String paramName = (String) secretParam.get("name");
String secretName = (String) secretParam.get("secretName");
String secretKey = (String) secretParam.get("secretKey");
String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
ParamType pt = new ParamType();
pt.setName(paramName);
pt.setValue(secretValue);
mlt.getParams().add(pt);
}
} catch (Exception e) {
throw new ProvisioningException("Could not load secrets for '" + name + "'");
} finally {
if (nonwatchHttp != null) {
try {
nonwatchHttp.getHttp().close();
} catch (IOException e) {
}
nonwatchHttp.getBcm().close();
}
}
}
try {
this.cfgMgr.getProvisioningEngine().addMessageListener(mlt);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ProvisioningException | JMSException e) {
logger.warn("Could not create listener " + name, e);
}
}
use of com.tremolosecurity.config.xml.MessageListenerType in project OpenUnison by TremoloSecurity.
the class SendMessageThread method initListeners.
@Override
public void initListeners() throws ProvisioningException {
this.listenerSessions = new HashMap<String, JMSSessionHolder>();
if (this.cfgMgr.getCfg().getProvisioning() == null || this.cfgMgr.getCfg().getProvisioning().getListeners() == null) {
logger.warn("No listeners defined");
return;
}
try {
for (MessageListenerType mlt : this.cfgMgr.getCfg().getProvisioning().getListeners().getListener()) {
addMessageListener(mlt);
}
if (cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners() != null && cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners().isEnabled()) {
DynamicPortalUrlsType dynamicMessageListeners = cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners();
String className = dynamicMessageListeners.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicMessageListeners.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicQueueListeners dynamicQueueListener = (DynamicQueueListeners) Class.forName(className).newInstance();
dynamicQueueListener.loadDynamicQueueListeners(cfgMgr, this, cfgAttrs);
}
} catch (Exception e) {
logger.warn("Could not initialize listeners", e);
}
}
Aggregations