Search in sources :

Example 11 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class ApiStreamPipe method adjustFirstStringPart.

@Override
protected String adjustFirstStringPart(String firstStringPart, IPipeLineSession session) throws PipeRunException {
    if (firstStringPart == null) {
        return "";
    } else {
        boolean retrieveMessage = false;
        if (XmlUtils.isWellFormed(firstStringPart, "MessageID")) {
            String rootNamespace = XmlUtils.getRootNamespace(firstStringPart);
            if ("http://www.w3.org/2005/08/addressing".equals(rootNamespace)) {
                retrieveMessage = true;
            }
        }
        if (retrieveMessage) {
            String messageId = null;
            try {
                messageId = XmlUtils.evaluateXPathNodeSetFirstElement(firstStringPart, "MessageID");
            } catch (Exception e) {
                throw new PipeRunException(this, "Exception getting MessageID", e);
            }
            if (StringUtils.isEmpty(messageId)) {
                throw new PipeRunException(this, "Could not find messageId in request [" + firstStringPart + "]");
            } else {
                // TODO: create dummyQuerySender should be put in
                // configure(), but gives an error
                IbisContext ibisContext = getAdapter().getConfiguration().getIbisManager().getIbisContext();
                dummyQuerySender = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
                dummyQuerySender.setJmsRealm(jmsRealm);
                dummyQuerySender.setQuery("SELECT count(*) FROM ALL_TABLES");
                try {
                    dummyQuerySender.configure();
                } catch (ConfigurationException e) {
                    throw new PipeRunException(this, "Exception configuring dummy query sender", e);
                }
                ParameterResolutionContext prc = new ParameterResolutionContext("", session);
                String slotId = AppConstants.getInstance().getResolvedProperty("instance.name") + "/" + session.get("operation");
                String selectMessageKeyResult = null;
                try {
                    selectMessageKeyResult = selectMessageKey(slotId, messageId);
                } catch (Exception e) {
                    throw new PipeRunException(this, "Exception getting messageKey", e);
                }
                if (StringUtils.isEmpty(selectMessageKeyResult)) {
                    throw new PipeRunException(this, "Could not find message in MessageStore for slotId [" + slotId + "] and messageId [" + messageId + "]");
                } else {
                    String selectMessageResult = null;
                    try {
                        selectMessageResult = selectMessage(selectMessageKeyResult);
                    } catch (Exception e) {
                        throw new PipeRunException(this, "Exception getting message", e);
                    }
                    if (StringUtils.isEmpty(selectMessageResult)) {
                        throw new PipeRunException(this, "Could not find message in MessageStore with messageKey [" + selectMessageKeyResult + "]");
                    } else {
                        try {
                            deleteMessage(selectMessageKeyResult);
                        } catch (Exception e) {
                            throw new PipeRunException(this, "Exception deleting message", e);
                        }
                    }
                    return selectMessageResult;
                }
            }
        } else {
            return firstStringPart;
        }
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException)

Example 12 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext 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 13 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class IbisSoapServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    AppConstants appConstants = AppConstants.getInstance();
    String attributeKey = appConstants.getProperty(ConfigurationServlet.KEY_CONTEXT);
    IbisContext ibisContext = (IbisContext) config.getServletContext().getAttribute(attributeKey);
    if (ibisContext == null)
        throw new IllegalStateException("No ibis context found with " + ConfigurationServlet.KEY_CONTEXT);
    ibisManager = ibisContext.getIbisManager();
    if ("false".equals(appConstants.getProperty("wsdl.caching"))) {
        caching = false;
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 14 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class ConfigurationServlet method init.

@Override
public void init() throws ServletException {
    super.init();
    ServletContext servletContext = getServletContext();
    AppConstants appConstants = AppConstants.getInstance();
    String realPath = servletContext.getRealPath("/");
    if (realPath != null) {
        appConstants.put("webapp.realpath", realPath);
    } else {
        log.warn("Could not determine webapp.realpath");
    }
    String projectBaseDir = Misc.getProjectBaseDir();
    if (projectBaseDir != null) {
        appConstants.put("project.basedir", projectBaseDir);
    } else {
        log.info("Could not determine project.basedir");
    }
    setUploadPathInServletContext();
    ibisContext = new IbisContext();
    setDefaultApplicationServerType(ibisContext);
    String attributeKey = appConstants.getResolvedProperty(KEY_CONTEXT);
    servletContext.setAttribute(attributeKey, ibisContext);
    log.debug("stored IbisContext [" + ClassUtils.nameOf(ibisContext) + "][" + ibisContext + "] in ServletContext under key [" + attributeKey + "]");
    ibisContext.init();
    if (ibisContext.getIbisManager() == null)
        log.warn("Servlet init finished without successfully initializing the ibisContext");
    else
        log.debug("Servlet init finished");
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ServletContext(javax.servlet.ServletContext) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 15 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext 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)

Aggregations

IbisContext (nl.nn.adapterframework.configuration.IbisContext)15 AppConstants (nl.nn.adapterframework.util.AppConstants)3 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 ServletContext (javax.servlet.ServletContext)2 Configuration (nl.nn.adapterframework.configuration.Configuration)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IbisManager (nl.nn.adapterframework.configuration.IbisManager)2 IAdapter (nl.nn.adapterframework.core.IAdapter)2 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)2 RunStateEnum (nl.nn.adapterframework.util.RunStateEnum)2 File (java.io.File)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1