Search in sources :

Example 6 with IbisManager

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();
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager)

Example 7 with IbisManager

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;
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) IReceiver(nl.nn.adapterframework.core.IReceiver) IbisManager(nl.nn.adapterframework.configuration.IbisManager) Configuration(nl.nn.adapterframework.configuration.Configuration) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 8 with IbisManager

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;
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) IbisManager(nl.nn.adapterframework.configuration.IbisManager)

Example 9 with IbisManager

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();
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) List(java.util.List) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 10 with IbisManager

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();
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) Configuration(nl.nn.adapterframework.configuration.Configuration) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Aggregations

IbisManager (nl.nn.adapterframework.configuration.IbisManager)14 IAdapter (nl.nn.adapterframework.core.IAdapter)6 Configuration (nl.nn.adapterframework.configuration.Configuration)5 IOException (java.io.IOException)4 IbisContext (nl.nn.adapterframework.configuration.IbisContext)3 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ZipInputStream (java.util.zip.ZipInputStream)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 Adapter (nl.nn.adapterframework.core.Adapter)2 TestConfiguration (nl.nn.adapterframework.testutil.TestConfiguration)2 Before (org.junit.Before)2