use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.
the class TestConfiguration method getIbisManager.
/**
* Create and register the IbisManger with the Configuration
*/
@Override
public IbisManager getIbisManager() {
if (super.getIbisManager() == null) {
IbisManager ibisManager = new MockIbisManager();
ibisManager.addConfiguration(this);
getBeanFactory().registerSingleton("ibisManager", ibisManager);
setIbisManager(ibisManager);
assertTrue("bean IbisManager not found", containsBean("ibisManager"));
}
return super.getIbisManager();
}
use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.
the class RestListenerUtils method doRestartShowConfigurationStatus.
private static boolean doRestartShowConfigurationStatus(ServletContext servletContext) {
String attributeKey = AppConstants.getInstance().getProperty(ConfigurationServlet.KEY_CONTEXT);
IbisContext ibisContext = (IbisContext) servletContext.getAttribute(attributeKey);
IAdapter adapter = null;
IReceiver receiver = null;
if (ibisContext != null) {
IbisManager ibisManager = ibisContext.getIbisManager();
if (ibisManager != null) {
Configuration configuration = ibisManager.getConfiguration(SHOW_CONFIG_STATUS_CONFIGURATION);
if (configuration != null) {
adapter = configuration.getRegisteredAdapter(SHOW_CONFIG_STATUS_ADAPTER);
if (adapter instanceof Adapter) {
receiver = ((Adapter) adapter).getReceiverByNameAndListener(SHOW_CONFIG_STATUS_RECEIVER, RestListener.class);
}
}
}
}
if (adapter == null) {
log.info("could not restart ShowConfigurationStatus, adapter [" + SHOW_CONFIG_STATUS_ADAPTER + "] not found");
return false;
}
if (receiver == null) {
log.info("could not restart ShowConfigurationStatus, receiver [" + SHOW_CONFIG_STATUS_RECEIVER + "] not found");
return false;
}
RunStateEnum adapterStatus = adapter.getRunState();
RunStateEnum receiverStatus = receiver.getRunState();
if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STARTED.equals(receiverStatus)) {
log.info("ShowConfigurationStatus is already running, will restart it");
ibisContext.getIbisManager().handleAdapter("stopadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
}
if (RunStateEnum.STOPPED.equals(adapterStatus)) {
log.info("starting adapter of ShowConfigurationStatus");
ibisContext.getIbisManager().handleAdapter("startadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
return true;
} else {
if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STOPPED.equals(receiverStatus)) {
log.info("starting receiver of ShowConfigurationStatus");
ibisContext.getIbisManager().handleAdapter("startreceiver", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
return true;
}
}
log.info("could not restart ShowConfigurationStatus with adapter status [" + adapterStatus + "] and receiver status [" + receiverStatus + "]");
return false;
}
use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.
the class TestPipeline method getIbisManager.
private IbisManager getIbisManager() {
String attributeKey = AppConstants.getInstance().getProperty(ConfigurationServlet.KEY_CONTEXT);
IbisContext ibisContext = (IbisContext) servletConfig.getServletContext().getAttribute(attributeKey);
if (ibisContext != null) {
IbisManager ibisManager = ibisContext.getIbisManager();
if (ibisManager == null) {
log.warn("Could not retrieve ibisManager from context");
} else {
log.trace("retrieved ibisManager [" + ClassUtils.nameOf(ibisManager) + "][" + ibisManager + "] from servlet context attribute [" + attributeKey + "]");
return ibisManager;
}
}
return null;
}
use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.
the class TestPipeline method postTestPipeLine.
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/test-pipeline")
@Relation("pipeline")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postTestPipeLine(MultipartFormDataInput input) throws ApiException, PipeRunException {
Map<String, Object> result = new HashMap<String, Object>();
IbisManager ibisManager = getIbisManager();
if (ibisManager == null) {
throw new ApiException("Config not found!");
}
String message = null, fileEncoding = null, fileName = null;
InputStream file = null;
IAdapter adapter = null;
Map<String, List<InputPart>> inputDataMap = input.getFormDataMap();
try {
if (inputDataMap.get("message") != null)
message = inputDataMap.get("message").get(0).getBodyAsString();
if (inputDataMap.get("encoding") != null)
fileEncoding = inputDataMap.get("encoding").get(0).getBodyAsString();
if (inputDataMap.get("adapter") != null) {
String adapterName = inputDataMap.get("adapter").get(0).getBodyAsString();
adapter = ibisManager.getRegisteredAdapter(adapterName);
}
if (inputDataMap.get("file") != null) {
file = inputDataMap.get("file").get(0).getBody(InputStream.class, null);
MultivaluedMap<String, String> headers = inputDataMap.get("file").get(0).getHeaders();
String[] contentDispositionHeader = headers.getFirst("Content-Disposition").split(";");
for (String name : contentDispositionHeader) {
if ((name.trim().startsWith("filename"))) {
String[] tmp = name.split("=");
fileName = tmp[1].trim().replaceAll("\"", "");
}
}
if (fileEncoding == null || fileEncoding.isEmpty())
fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
if (StringUtils.endsWithIgnoreCase(fileName, ".zip")) {
try {
processZipFile(result, file, fileEncoding, adapter, secLogMessage);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(null) + "exception on processing zip file", e);
}
} else {
message = Misc.streamToString(file, "\n", fileEncoding, false);
}
}
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (fileEncoding == null || StringUtils.isEmpty(fileEncoding))
fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
if (adapter == null && (message == null && file == null)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (StringUtils.isNotEmpty(message)) {
try {
PipeLineResult plr = processMessage(adapter, message, secLogMessage);
result.put("state", plr.getState());
result.put("result", plr.getResult());
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(null) + "exception on sending message", e);
}
}
return Response.status(Response.Status.CREATED).entity(result).build();
}
use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.
the class ShowConfiguration method doGet.
@Override
protected String doGet(IPipeLineSession session) throws PipeRunException {
IbisManager ibisManager = retrieveIbisManager();
String configurationName = retrieveConfigurationName(session);
Configuration configuration = null;
boolean configAll;
if (configurationName == null || configurationName.equalsIgnoreCase(CONFIG_ALL)) {
configAll = true;
} else {
configuration = ibisManager.getConfiguration(configurationName);
if (configuration == null) {
configAll = true;
} else {
configAll = false;
}
}
List<Configuration> allConfigurations = ibisManager.getConfigurations();
XmlBuilder configurationsXml = toConfigurationsXml(allConfigurations);
StringBuilder sb = new StringBuilder();
boolean showConfigurationOriginal = AppConstants.getInstance().getBoolean("showConfiguration.original", false);
if (configAll) {
sb.append("<configurations>");
for (Configuration configuration_iter : allConfigurations) {
if (showConfigurationOriginal) {
sb.append(XmlUtils.skipXmlDeclaration(configuration_iter.getOriginalConfiguration()));
} else {
sb.append(XmlUtils.skipXmlDeclaration(configuration_iter.getLoadedConfiguration()));
}
}
sb.append("</configurations>");
} else {
if (showConfigurationOriginal) {
sb.append(configuration.getOriginalConfiguration());
} else {
sb.append(configuration.getLoadedConfiguration());
}
}
XmlBuilder configSource = new XmlBuilder("configSource");
configSource.setCdataValue(sb.toString());
configSource.addAttribute("original", showConfigurationOriginal);
storeConfiguration(session, configAll, configuration);
XmlBuilder root = new XmlBuilder("root");
root.addSubElement(configurationsXml);
root.addSubElement(configSource);
return root.toXML();
}
Aggregations