Search in sources :

Example 6 with ITransactionalStorage

use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.

the class MessageSendingPipe method configure.

/**
 * Checks whether a sender is defined for this pipe.
 */
@Override
public void configure() throws ConfigurationException {
    super.configure();
    if (StringUtils.isNotEmpty(getStubFileName())) {
        URL stubUrl;
        try {
            stubUrl = ClassUtils.getResourceURL(classLoader, getStubFileName());
        } catch (Throwable e) {
            throw new ConfigurationException(getLogPrefix(null) + "got exception finding resource for stubfile [" + getStubFileName() + "]", e);
        }
        if (stubUrl == null) {
            throw new ConfigurationException(getLogPrefix(null) + "could not find resource for stubfile [" + getStubFileName() + "]");
        }
        try {
            returnString = Misc.resourceToString(stubUrl, SystemUtils.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new ConfigurationException(getLogPrefix(null) + "got exception loading stubfile [" + getStubFileName() + "] from resource [" + stubUrl.toExternalForm() + "]", e);
        }
    } else {
        propagateName();
        if (getSender() == null) {
            throw new ConfigurationException(getLogPrefix(null) + "no sender defined ");
        }
        try {
            if (getSender() instanceof PipeAware) {
                ((PipeAware) getSender()).setPipe(this);
            }
            getSender().configure();
        } catch (ConfigurationException e) {
            throw new ConfigurationException(getLogPrefix(null) + "while configuring sender", e);
        }
        if (getSender() instanceof HasPhysicalDestination) {
            log.info(getLogPrefix(null) + "has sender on " + ((HasPhysicalDestination) getSender()).getPhysicalDestinationName());
        }
        if (getListener() != null) {
            if (getSender().isSynchronous()) {
                throw new ConfigurationException(getLogPrefix(null) + "cannot have listener with synchronous sender");
            }
            try {
                getListener().configure();
            } catch (ConfigurationException e) {
                throw new ConfigurationException(getLogPrefix(null) + "while configuring listener", e);
            }
            if (getListener() instanceof HasPhysicalDestination) {
                log.info(getLogPrefix(null) + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
            }
        }
        if (!(getLinkMethod().equalsIgnoreCase("MESSAGEID")) && (!(getLinkMethod().equalsIgnoreCase("CORRELATIONID")))) {
            throw new ConfigurationException(getLogPrefix(null) + "Invalid argument for property LinkMethod [" + getLinkMethod() + "]. it should be either MESSAGEID or CORRELATIONID");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix(null) + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (isCheckXmlWellFormed() || StringUtils.isNotEmpty(getCheckRootTag())) {
            if (findForward(ILLEGAL_RESULT_FORWARD) == null)
                throw new ConfigurationException(getLogPrefix(null) + "has no forward with name [illegalResult]");
        }
        if (!ConfigurationUtils.stubConfiguration()) {
            if (StringUtils.isNotEmpty(getTimeOutOnResult())) {
                throw new ConfigurationException(getLogPrefix(null) + "timeOutOnResult only allowed in stub mode");
            }
            if (StringUtils.isNotEmpty(getExceptionOnResult())) {
                throw new ConfigurationException(getLogPrefix(null) + "exceptionOnResult only allowed in stub mode");
            }
        }
        if (getMaxRetries() > 0) {
            ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
            if (getRetryMinInterval() < MIN_RETRY_INTERVAL) {
                String msg = "retryMinInterval [" + getRetryMinInterval() + "] should be greater than or equal to [" + MIN_RETRY_INTERVAL + "], assuming the lower limit";
                configWarnings.add(log, msg);
                setRetryMinInterval(MIN_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() > MAX_RETRY_INTERVAL) {
                String msg = "retryMaxInterval [" + getRetryMaxInterval() + "] should be less than or equal to [" + MAX_RETRY_INTERVAL + "], assuming the upper limit";
                configWarnings.add(log, msg);
                setRetryMaxInterval(MAX_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() < getRetryMinInterval()) {
                String msg = "retryMaxInterval [" + getRetryMaxInterval() + "] should be greater than or equal to [" + getRetryMinInterval() + "], assuming the lower limit";
                configWarnings.add(log, msg);
                setRetryMaxInterval(getRetryMinInterval());
            }
        }
    }
    ITransactionalStorage messageLog = getMessageLog();
    if (checkMessageLog) {
        if (!getSender().isSynchronous() && getListener() == null && !(getSender() instanceof nl.nn.adapterframework.senders.IbisLocalSender)) {
            if (messageLog == null) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                String msg = "asynchronous sender [" + getSender().getName() + "] without sibling listener has no messageLog. Integrity check not possible";
                configWarnings.add(log, msg);
            }
        }
    }
    if (messageLog != null) {
        messageLog.configure();
        if (messageLog instanceof HasPhysicalDestination) {
            String msg = getLogPrefix(null) + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName();
            log.info(msg);
            if (getAdapter() != null)
                getAdapter().getMessageKeeper().add(msg);
        }
        if (StringUtils.isNotEmpty(getAuditTrailXPath())) {
            auditTrailTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getAuditTrailNamespaceDefs(), getAuditTrailXPath(), null, "text", false, null);
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), "text", false, null);
        }
        if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
            labelTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), "text", false, null);
        }
    }
    if (StringUtils.isNotEmpty(getRetryXPath())) {
        retryTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getRetryNamespaceDefs(), getRetryXPath(), null, "text", false, null);
    }
    IPipe inputValidator = getInputValidator();
    IPipe outputValidator = getOutputValidator();
    if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
        outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
        setOutputValidator(outputValidator);
    }
    if (inputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(SUCCESS_FORWARD);
        inputValidator.registerForward(pf);
    // inputValidator.configure(); // configure is handled in PipeLine.configure()
    }
    if (outputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(SUCCESS_FORWARD);
        outputValidator.registerForward(pf);
    // outputValidator.configure(); // configure is handled in PipeLine.configure()
    }
    if (getInputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(SUCCESS_FORWARD);
        getInputWrapper().registerForward(pf);
        if (getInputWrapper() instanceof EsbSoapWrapperPipe) {
            EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getInputWrapper();
            ISender sender = getSender();
            eswPipe.retrievePhysicalDestinationFromSender(sender);
        }
    }
    if (getOutputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(SUCCESS_FORWARD);
        getOutputWrapper().registerForward(pf);
    }
    registerEvent(PIPE_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_EXCEPTION_MONITOR_EVENT);
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) EsbSoapWrapperPipe(nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe) IDualModeValidator(nl.nn.adapterframework.core.IDualModeValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) IPipe(nl.nn.adapterframework.core.IPipe) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 7 with ITransactionalStorage

use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.

the class MessageSendingPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String originalMessage = input.toString();
    String result = null;
    String correlationID = session.getMessageId();
    if (getInputWrapper() != null) {
        log.debug(getLogPrefix(session) + "wrapping input");
        PipeRunResult wrapResult = pipeProcessor.processPipe(getPipeLine(), inputWrapper, correlationID, input, session);
        if (wrapResult != null && !wrapResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
            return wrapResult;
        } else {
            input = wrapResult.getResult();
        }
        log.debug(getLogPrefix(session) + "input after wrapping [" + input.toString() + "]");
    }
    if (getInputValidator() != null) {
        log.debug(getLogPrefix(session) + "validating input");
        PipeRunResult validationResult = pipeProcessor.processPipe(getPipeLine(), inputValidator, correlationID, input, session);
        if (validationResult != null && !validationResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
            return validationResult;
        }
    }
    if (StringUtils.isNotEmpty(getStubFileName())) {
        ParameterList pl = getParameterList();
        result = returnString;
        if (pl != null) {
            ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
            Map params;
            try {
                params = prc.getValueMap(pl);
            } catch (ParameterException e1) {
                throw new PipeRunException(this, getLogPrefix(session) + "got exception evaluating parameters", e1);
            }
            String sfn = null;
            if (params != null && params.size() > 0) {
                sfn = (String) params.get(STUBFILENAME);
            }
            if (sfn != null) {
                try {
                    result = Misc.resourceToString(ClassUtils.getResourceURL(classLoader, sfn), SystemUtils.LINE_SEPARATOR);
                    log.info(getLogPrefix(session) + "returning result from dynamic stub [" + sfn + "]");
                } catch (Throwable e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "got exception loading result from stub [" + sfn + "]", e);
                }
            } else {
                log.info(getLogPrefix(session) + "returning result from static stub [" + getStubFileName() + "]");
            }
        } else {
            log.info(getLogPrefix(session) + "returning result from static stub [" + getStubFileName() + "]");
        }
    } else {
        Map threadContext = new HashMap();
        try {
            String messageID = null;
            // sendResult has a messageID for async senders, the result for sync senders
            int retryInterval = getRetryMinInterval();
            String sendResult = null;
            boolean replyIsValid = false;
            int retriesLeft = 0;
            if (getMaxRetries() > 0) {
                retriesLeft = getMaxRetries() + 1;
            } else {
                retriesLeft = 1;
            }
            while (retriesLeft-- >= 1 && !replyIsValid) {
                try {
                    sendResult = sendMessage(input, session, correlationID, getSender(), threadContext);
                    if (retryTp != null) {
                        String retry = retryTp.transform(sendResult, null);
                        if (retry.equalsIgnoreCase("true")) {
                            if (retriesLeft >= 1) {
                                retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "xpathRetry result [" + retry + "], retries left [" + retriesLeft + "]");
                            }
                        } else {
                            replyIsValid = true;
                        }
                    } else {
                        replyIsValid = true;
                    }
                } catch (TimeOutException toe) {
                    if (retriesLeft >= 1) {
                        retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "timeout occured, retries left [" + retriesLeft + "]");
                    } else {
                        throw toe;
                    }
                } catch (SenderException se) {
                    if (retriesLeft >= 1) {
                        retryInterval = increaseRetryIntervalAndWait(session, retryInterval, "exception [" + (se != null ? se.getMessage() : "") + "] occured, retries left [" + retriesLeft + "]");
                    } else {
                        throw se;
                    }
                }
            }
            if (!replyIsValid) {
                throw new PipeRunException(this, getLogPrefix(session) + "invalid reply message is received");
            }
            if (getSender().isSynchronous()) {
                if (log.isInfoEnabled()) {
                    log.info(getLogPrefix(session) + "sent message to [" + getSender().getName() + "] synchronously");
                }
                result = sendResult;
            } else {
                messageID = sendResult;
                if (log.isInfoEnabled()) {
                    log.info(getLogPrefix(session) + "sent message to [" + getSender().getName() + "] messageID [" + messageID + "] correlationID [" + correlationID + "] linkMethod [" + getLinkMethod() + "]");
                }
                // as this will be used with the listener
                if (getLinkMethod().equalsIgnoreCase("MESSAGEID")) {
                    correlationID = sendResult;
                    if (log.isDebugEnabled())
                        log.debug(getLogPrefix(session) + "setting correlationId to listen for to messageId [" + correlationID + "]");
                }
            }
            ITransactionalStorage messageLog = getMessageLog();
            if (messageLog != null) {
                long messageLogStartTime = System.currentTimeMillis();
                String messageTrail = "no audit trail";
                if (auditTrailTp != null) {
                    if (isUseInputForExtract()) {
                        messageTrail = auditTrailTp.transform(originalMessage, null);
                    } else {
                        messageTrail = auditTrailTp.transform((String) input, null);
                    }
                } else {
                    if (StringUtils.isNotEmpty(getAuditTrailSessionKey())) {
                        messageTrail = (String) (session.get(getAuditTrailSessionKey()));
                    }
                }
                String storedMessageID = messageID;
                if (storedMessageID == null) {
                    storedMessageID = "-";
                }
                if (correlationIDTp != null) {
                    if (StringUtils.isNotEmpty(getCorrelationIDSessionKey())) {
                        String sourceString = (String) (session.get(getCorrelationIDSessionKey()));
                        correlationID = correlationIDTp.transform(sourceString, null);
                    } else {
                        if (isUseInputForExtract()) {
                            correlationID = correlationIDTp.transform(originalMessage, null);
                        } else {
                            correlationID = correlationIDTp.transform((String) input, null);
                        }
                    }
                    if (StringUtils.isEmpty(correlationID)) {
                        correlationID = "-";
                    }
                }
                String label = null;
                if (labelTp != null) {
                    if (isUseInputForExtract()) {
                        label = labelTp.transform(originalMessage, null);
                    } else {
                        label = labelTp.transform((String) input, null);
                    }
                }
                if (sender instanceof MailSender) {
                    String messageInMailSafeForm = (String) session.get("messageInMailSafeForm");
                    if (hideRegex != null) {
                        if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
                            messageInMailSafeForm = Misc.hideFirstHalf(messageInMailSafeForm, hideRegex);
                        } else {
                            messageInMailSafeForm = Misc.hideAll(messageInMailSafeForm, hideRegex);
                        }
                    }
                    messageLog.storeMessage(storedMessageID, correlationID, new Date(), messageTrail, label, messageInMailSafeForm);
                } else {
                    String message = (String) input;
                    if (hideRegex != null) {
                        if (getHideMethod().equalsIgnoreCase("FIRSTHALF")) {
                            message = Misc.hideFirstHalf(message, hideRegex);
                        } else {
                            message = Misc.hideAll(message, hideRegex);
                        }
                    }
                    messageLog.storeMessage(storedMessageID, correlationID, new Date(), messageTrail, label, message);
                }
                long messageLogEndTime = System.currentTimeMillis();
                long messageLogDuration = messageLogEndTime - messageLogStartTime;
                StatisticsKeeper sk = getPipeLine().getPipeStatistics(messageLog);
                sk.addValue(messageLogDuration);
            }
            if (sender instanceof MailSender) {
                session.remove("messageInMailSafeForm");
            }
            if (getListener() != null) {
                result = listenerProcessor.getMessage(getListener(), correlationID, session);
            } else {
                result = sendResult;
            }
            if (result == null) {
                result = "";
            }
            if (timeoutPending) {
                timeoutPending = false;
                throwEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
            }
        } catch (TimeOutException toe) {
            throwEvent(PIPE_TIMEOUT_MONITOR_EVENT);
            if (!timeoutPending) {
                timeoutPending = true;
            }
            PipeForward timeoutForward = findForward(TIMEOUT_FORWARD);
            log.warn(getLogPrefix(session) + "timeout occured");
            if (timeoutForward == null) {
                if (StringUtils.isEmpty(getResultOnTimeOut())) {
                    timeoutForward = findForward(EXCEPTION_FORWARD);
                } else {
                    timeoutForward = getForward();
                }
            }
            if (timeoutForward != null) {
                String resultmsg;
                if (StringUtils.isNotEmpty(getResultOnTimeOut())) {
                    resultmsg = getResultOnTimeOut();
                } else {
                    if (input instanceof String) {
                        resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), toe, this, (String) input, session.getMessageId(), 0);
                    } else {
                        if (input == null) {
                            input = "null";
                        }
                        resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), toe, this, input.toString(), session.getMessageId(), 0);
                    }
                }
                return new PipeRunResult(timeoutForward, resultmsg);
            }
            throw new PipeRunException(this, getLogPrefix(session) + "caught timeout-exception", toe);
        } catch (Throwable t) {
            throwEvent(PIPE_EXCEPTION_MONITOR_EVENT);
            PipeForward exceptionForward = findForward(EXCEPTION_FORWARD);
            if (exceptionForward != null) {
                log.warn(getLogPrefix(session) + "exception occured, forwarding to exception-forward [" + exceptionForward.getPath() + "], exception:\n", t);
                String resultmsg;
                if (input instanceof String) {
                    resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), t, this, (String) input, session.getMessageId(), 0);
                } else {
                    if (input == null) {
                        input = "null";
                    }
                    resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), t, this, input.toString(), session.getMessageId(), 0);
                }
                return new PipeRunResult(exceptionForward, resultmsg);
            }
            throw new PipeRunException(this, getLogPrefix(session) + "caught exception", t);
        }
    }
    if (!validResult(result)) {
        PipeForward illegalResultForward = findForward(ILLEGAL_RESULT_FORWARD);
        return new PipeRunResult(illegalResultForward, result);
    }
    IPipe outputValidator = getOutputValidator();
    if (outputValidator != null) {
        log.debug(getLogPrefix(session) + "validating response");
        PipeRunResult validationResult;
        validationResult = pipeProcessor.processPipe(getPipeLine(), outputValidator, correlationID, result, session);
        if (validationResult != null && !validationResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
            return validationResult;
        }
    }
    if (getOutputWrapper() != null) {
        log.debug(getLogPrefix(session) + "wrapping response");
        PipeRunResult wrapResult = pipeProcessor.processPipe(getPipeLine(), outputWrapper, correlationID, result, session);
        if (wrapResult != null && !wrapResult.getPipeForward().getName().equals(SUCCESS_FORWARD)) {
            return wrapResult;
        }
        result = wrapResult.getResult().toString();
        log.debug(getLogPrefix(session) + "response after wrapping [" + result + "]");
    }
    if (isStreamResultToServlet()) {
        byte[] bytes = Base64.decodeBase64(new String(result));
        try {
            String contentType = (String) session.get("contentType");
            if (StringUtils.isNotEmpty(contentType)) {
                RestListenerUtils.setResponseContentType(session, contentType);
            }
            RestListenerUtils.writeToResponseOutputStream(session, bytes);
        } catch (IOException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "caught exception", e);
        }
        return new PipeRunResult(getForward(), "");
    } else {
        return new PipeRunResult(getForward(), result);
    }
}
Also used : HashMap(java.util.HashMap) MailSender(nl.nn.adapterframework.senders.MailSender) IOException(java.io.IOException) PipeForward(nl.nn.adapterframework.core.PipeForward) Date(java.util.Date) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ErrorMessageFormatter(nl.nn.adapterframework.errormessageformatters.ErrorMessageFormatter) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) HashMap(java.util.HashMap) IPipe(nl.nn.adapterframework.core.IPipe)

Example 8 with ITransactionalStorage

use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.

the class DefaultIbisManager method handleAdapter.

/**
 * Utility function to give commands to Adapters and Receivers
 */
public void handleAdapter(String action, String configurationName, String adapterName, String receiverName, String commandIssuedBy, boolean isAdmin) {
    if (action.equalsIgnoreCase("STOPADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Stopping all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    stopAdapters(configuration);
                }
            } else {
                log.info("Stopping all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                stopAdapters(getConfiguration(configurationName));
            }
        } else {
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    log.info("Stopping adapter [" + adapterName + "], on request of [" + commandIssuedBy + "]");
                    configuration.getRegisteredAdapter(adapterName).stopRunning();
                }
            }
        }
    } else if (action.equalsIgnoreCase("STARTADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Starting all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    startAdapters(configuration);
                }
            } else {
                log.info("Starting all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                startAdapters(getConfiguration(configurationName));
            }
        } else {
            try {
                for (Configuration configuration : configurations) {
                    if (configuration.getRegisteredAdapter(adapterName) != null) {
                        log.info("Starting adapter [" + adapterName + "] on request of [" + commandIssuedBy + "]");
                        configuration.getRegisteredAdapter(adapterName).startRunning();
                    }
                }
            } catch (Exception e) {
                log.error("error in execution of command [" + action + "] for adapter [" + adapterName + "]", e);
            // errors.add("", new ActionError("errors.generic", e.toString()));
            }
        }
    } else if (action.equalsIgnoreCase("STOPRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.stopRunning();
                log.info("receiver [" + receiverName + "] stopped by webcontrol on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("STARTRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.startRunning();
                log.info("receiver [" + receiverName + "] started by " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("RELOAD")) {
        String msg = "Reload configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]";
        log.info(msg);
        secLog.info(msg);
        ibisContext.reload(configurationName);
    } else if (action.equalsIgnoreCase("FULLRELOAD")) {
        if (isAdmin) {
            String msg = "Full reload on request of [" + commandIssuedBy + "]";
            log.info(msg);
            secLog.info(msg);
            ibisContext.fullReload();
        } else {
            log.warn("Full reload not allowed for [" + commandIssuedBy + "]");
        }
    } else if (action.equalsIgnoreCase("INCTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.increaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] increased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("DECTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.decreaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] decreased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("SENDMESSAGE")) {
        try {
            // send job
            IbisLocalSender localSender = new IbisLocalSender();
            localSender.setJavaListener(receiverName);
            localSender.setIsolated(false);
            localSender.setName("AdapterJob");
            localSender.configure();
            localSender.open();
            try {
                localSender.sendMessage(null, "");
            } finally {
                localSender.close();
            }
        } catch (Exception e) {
            log.error("Error while sending message (as part of scheduled job execution)", e);
        }
    } else if (action.equalsIgnoreCase("MOVEMESSAGE")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof ReceiverBase) {
                    ReceiverBase rb = (ReceiverBase) receiver;
                    ITransactionalStorage errorStorage = rb.getErrorStorage();
                    if (errorStorage == null) {
                        log.error("action [" + action + "] is only allowed for receivers with an ErrorStorage");
                    } else {
                        if (errorStorage instanceof JdbcTransactionalStorage) {
                            JdbcTransactionalStorage jdbcErrorStorage = (JdbcTransactionalStorage) rb.getErrorStorage();
                            IListener listener = rb.getListener();
                            if (listener instanceof EsbJmsListener) {
                                EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                EsbUtils.receiveMessageAndMoveToErrorStorage(esbJmsListener, jdbcErrorStorage);
                            } else {
                                log.error("action [" + action + "] is currently only allowed for EsbJmsListener, not for type [" + listener.getClass().getName() + "]");
                            }
                        } else {
                            log.error("action [" + action + "] is currently only allowed for JdbcTransactionalStorage, not for type [" + errorStorage.getClass().getName() + "]");
                        }
                    }
                }
            }
        }
    }
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) IbisLocalSender(nl.nn.adapterframework.senders.IbisLocalSender) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) IListener(nl.nn.adapterframework.core.IListener) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) IAdapter(nl.nn.adapterframework.core.IAdapter) SchedulerException(org.quartz.SchedulerException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage)

Example 9 with ITransactionalStorage

use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.

the class ReceiverBase method propagateName.

protected void propagateName() {
    IListener listener = getListener();
    if (listener != null && StringUtils.isEmpty(listener.getName())) {
        listener.setName("listener of [" + getName() + "]");
    }
    ISender errorSender = getErrorSender();
    if (errorSender != null) {
        errorSender.setName("errorSender of [" + getName() + "]");
    }
    ITransactionalStorage errorStorage = getErrorStorage();
    if (errorStorage != null) {
        errorStorage.setName("errorStorage of [" + getName() + "]");
    }
    ISender answerSender = getSender();
    if (answerSender != null) {
        answerSender.setName("answerSender of [" + getName() + "]");
    }
}
Also used : ISender(nl.nn.adapterframework.core.ISender) IListener(nl.nn.adapterframework.core.IListener) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage)

Example 10 with ITransactionalStorage

use of nl.nn.adapterframework.core.ITransactionalStorage in project iaf by ibissource.

the class ReceiverBase method configure.

public void configure() throws ConfigurationException {
    configurationSucceeded = false;
    try {
        if (StringUtils.isEmpty(getName())) {
            if (getListener() != null) {
                setName(ClassUtils.nameOf(getListener()));
            } else {
                setName(ClassUtils.nameOf(this));
            }
        }
        eventHandler = MonitorManager.getEventHandler();
        registerEvent(RCV_CONFIGURED_MONITOR_EVENT);
        registerEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        registerEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
        registerEvent(RCV_SHUTDOWN_MONITOR_EVENT);
        registerEvent(RCV_SUSPENDED_MONITOR_EVENT);
        registerEvent(RCV_RESUMED_MONITOR_EVENT);
        registerEvent(RCV_THREAD_EXIT_MONITOR_EVENT);
        TXNEW_PROC = SpringTxManagerProxy.getTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW, getTransactionTimeout());
        // to use direct member variables).
        if (this.tmpInProcessStorage != null) {
            if (this.errorSender == null && this.errorStorage == null) {
                this.errorStorage = this.tmpInProcessStorage;
                info(getLogPrefix() + "has errorStorage in inProcessStorage, setting inProcessStorage's type to 'errorStorage'. Please update the configuration to change the inProcessStorage element to an errorStorage element, since the inProcessStorage is no longer used.");
                errorStorage.setType(JdbcTransactionalStorage.TYPE_ERRORSTORAGE);
            } else {
                info(getLogPrefix() + "has inProcessStorage defined but also has an errorStorage or errorSender. InProcessStorage is not used and can be removed from the configuration.");
            }
            // Set temporary in-process storage pointer to null
            this.tmpInProcessStorage = null;
        }
        // Do propagate-name AFTER changing the errorStorage!
        propagateName();
        if (getListener() == null) {
            throw new ConfigurationException(getLogPrefix() + "has no listener");
        }
        if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
            throw new ConfigurationException("cannot have both an elementToMove and an elementToMoveChain specified");
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException(getLogPrefix() + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (getListener() instanceof ReceiverAware) {
            ((ReceiverAware) getListener()).setReceiver(this);
        }
        if (getListener() instanceof IPushingListener) {
            IPushingListener pl = (IPushingListener) getListener();
            pl.setHandler(this);
            pl.setExceptionListener(this);
        }
        if (getListener() instanceof IPortConnectedListener) {
            IPortConnectedListener pcl = (IPortConnectedListener) getListener();
            pcl.setReceiver(this);
        }
        if (getListener() instanceof IPullingListener) {
            setListenerContainer(createListenerContainer());
        }
        if (getListener() instanceof JdbcFacade) {
            ((JdbcFacade) getListener()).setTransacted(isTransacted());
        }
        if (getListener() instanceof JMSFacade) {
            ((JMSFacade) getListener()).setTransacted(isTransacted());
        }
        getListener().configure();
        if (getListener() instanceof HasPhysicalDestination) {
            info(getLogPrefix() + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
        }
        if (getListener() instanceof HasSender) {
            // only informational
            ISender sender = ((HasSender) getListener()).getSender();
            if (sender instanceof HasPhysicalDestination) {
                info("Listener of receiver [" + getName() + "] has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        if (getListener() instanceof ITransactionRequirements) {
            ITransactionRequirements tr = (ITransactionRequirements) getListener();
            if (tr.transactionalRequired() && !isTransacted()) {
                String msg = getLogPrefix() + "listener type [" + ClassUtils.nameOf(getListener()) + "] requires transactional processing";
                ConfigurationWarnings.getInstance().add(msg);
            // throw new ConfigurationException(msg);
            }
        }
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
            if (sender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has answer-sender on " + ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
        }
        ISender errorSender = getErrorSender();
        if (errorSender != null) {
            errorSender.configure();
            if (errorSender instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorSender to " + ((HasPhysicalDestination) errorSender).getPhysicalDestinationName());
            }
        }
        ITransactionalStorage errorStorage = getErrorStorage();
        if (errorStorage != null) {
            errorStorage.configure();
            if (errorStorage instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has errorStorage to " + ((HasPhysicalDestination) errorStorage).getPhysicalDestinationName());
            }
            registerEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
        }
        ITransactionalStorage messageLog = getMessageLog();
        if (messageLog != null) {
            messageLog.configure();
            if (messageLog instanceof HasPhysicalDestination) {
                info(getLogPrefix() + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName());
            }
            if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
                labelTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), "text", false, null, isXslt2());
            }
        }
        if (isTransacted()) {
            if (errorSender == null && errorStorage == null) {
                ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                String msg = getLogPrefix() + "sets transactionAttribute=" + getTransactionAttribute() + ", but has no errorSender or errorStorage. Messages processed with errors will be lost";
                configWarnings.add(log, msg);
            } else {
            // if (errorSender!=null && !(errorSender instanceof IXAEnabled && ((IXAEnabled)errorSender).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorSender is not. Transactional integrity is not guaranteed");
            // }
            // if (errorStorage!=null && !(errorStorage instanceof IXAEnabled && ((IXAEnabled)errorStorage).isTransacted())) {
            // warn(getLogPrefix()+"sets transacted=true, but errorStorage is not. Transactional integrity is not guaranteed");
            // }
            }
            if (getTransactionTimeout() > 0) {
                String systemTransactionTimeout = Misc.getSystemTransactionTimeout();
                if (systemTransactionTimeout != null && StringUtils.isNumeric(systemTransactionTimeout)) {
                    int stt = Integer.parseInt(systemTransactionTimeout);
                    if (getTransactionTimeout() > stt) {
                        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                        String msg = getLogPrefix() + "has a transaction timeout [" + getTransactionTimeout() + "] which exceeds the system transaction timeout [" + stt + "]";
                        configWarnings.add(log, msg);
                    }
                }
            }
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer0(getLogPrefix(), classLoader, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), "text", false, null, isXslt2());
        }
        if (adapter != null) {
            adapter.getMessageKeeper().add(getLogPrefix() + "initialization complete");
        }
        throwEvent(RCV_CONFIGURED_MONITOR_EVENT);
        configurationSucceeded = true;
    } catch (Throwable t) {
        ConfigurationException e = null;
        if (t instanceof ConfigurationException) {
            e = (ConfigurationException) t;
        } else {
            e = new ConfigurationException("Exception configuring receiver [" + getName() + "]", t);
        }
        throwEvent(RCV_CONFIGURATIONEXCEPTION_MONITOR_EVENT);
        log.debug(getLogPrefix() + "Errors occured during configuration, setting runstate to ERROR");
        runState.setRunState(RunStateEnum.ERROR);
        throw e;
    }
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) JMSFacade(nl.nn.adapterframework.jms.JMSFacade) HasSender(nl.nn.adapterframework.core.HasSender) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IPullingListener(nl.nn.adapterframework.core.IPullingListener) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) ITransactionRequirements(nl.nn.adapterframework.core.ITransactionRequirements) IPushingListener(nl.nn.adapterframework.core.IPushingListener) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) JdbcFacade(nl.nn.adapterframework.jdbc.JdbcFacade) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Aggregations

ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)17 ISender (nl.nn.adapterframework.core.ISender)8 IPipe (nl.nn.adapterframework.core.IPipe)7 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)7 HashMap (java.util.HashMap)6 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)6 IListener (nl.nn.adapterframework.core.IListener)6 LinkedHashMap (java.util.LinkedHashMap)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5 PipeRunException (nl.nn.adapterframework.core.PipeRunException)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 Adapter (nl.nn.adapterframework.core.Adapter)4 PipeLine (nl.nn.adapterframework.core.PipeLine)4 SenderException (nl.nn.adapterframework.core.SenderException)4 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Configuration (nl.nn.adapterframework.configuration.Configuration)3