Search in sources :

Example 26 with PipeLine

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

the class MessageSendingPipe method sendMessage.

protected PipeRunResult sendMessage(Message input, PipeLineSession session, ISender sender, Map<String, Object> threadContext) throws SenderException, TimeoutException, IOException, InterruptedException {
    long startTime = System.currentTimeMillis();
    PipeRunResult sendResult = null;
    String exitState = null;
    try {
        PipeLine pipeline = getPipeLine();
        if (pipeline != null) {
            Adapter adapter = pipeline.getAdapter();
            if (adapter != null) {
                if (getPresumedTimeOutInterval() >= 0 && !isConfigurationStubbed) {
                    long lastExitIsTimeoutDate = adapter.getLastExitIsTimeoutDate(getName());
                    if (lastExitIsTimeoutDate > 0) {
                        long duration = startTime - lastExitIsTimeoutDate;
                        if (duration < (1000L * getPresumedTimeOutInterval())) {
                            exitState = PRESUMED_TIMEOUT_FORWARD;
                            throw new TimeoutException(getLogPrefix(session) + exitState);
                        }
                    }
                }
            }
        }
        try {
            if (sender instanceof IStreamingSender && canStreamToNextPipe() && getOutputValidator() == null && getOutputWrapper() == null && !isStreamResultToServlet()) {
                sendResult = ((IStreamingSender) sender).sendMessage(input, session, getNextPipe());
            } else {
                // sendResult has a messageID for async senders, the result for sync senders
                Message result = sender.sendMessage(input, session);
                sendResult = new PipeRunResult(null, result);
            }
        } catch (SenderException se) {
            exitState = PipeForward.EXCEPTION_FORWARD_NAME;
            throw se;
        } catch (TimeoutException toe) {
            exitState = TIMEOUT_FORWARD;
            throw toe;
        }
        if (Thread.currentThread().isInterrupted()) {
            exitState = INTERRUPT_FORWARD;
            throw new InterruptedException();
        }
        Message sendResultMessage = sendResult.getResult();
        if (sendResultMessage.asObject() instanceof String) {
            String result = (String) sendResultMessage.asObject();
            if (StringUtils.isNotEmpty(getTimeOutOnResult()) && getTimeOutOnResult().equals(result)) {
                exitState = TIMEOUT_FORWARD;
                throw new TimeoutException(getLogPrefix(session) + "timeOutOnResult [" + getTimeOutOnResult() + "]");
            }
            if (StringUtils.isNotEmpty(getExceptionOnResult()) && getExceptionOnResult().equals(result)) {
                exitState = PipeForward.EXCEPTION_FORWARD_NAME;
                throw new SenderException(getLogPrefix(session) + "exceptionOnResult [" + getExceptionOnResult() + "]");
            }
        }
    } finally {
        if (exitState == null) {
            exitState = PipeForward.SUCCESS_FORWARD_NAME;
        }
        PipeLine pipeline = getPipeLine();
        if (pipeline != null) {
            Adapter adapter = pipeline.getAdapter();
            if (adapter != null) {
                if (getPresumedTimeOutInterval() >= 0 && !ConfigurationUtils.isConfigurationStubbed(getConfigurationClassLoader())) {
                    if (!PRESUMED_TIMEOUT_FORWARD.equals(exitState)) {
                        adapter.setLastExitState(getName(), System.currentTimeMillis(), exitState);
                    }
                }
                String duration;
                if (msgLogHumanReadable) {
                    duration = Misc.getAge(startTime);
                } else {
                    duration = Misc.getDurationInMs(startTime);
                }
                if (msgLog.getLevel().isMoreSpecificThan(MSGLOG_LEVEL_TERSE)) {
                    msgLog.log(MSGLOG_LEVEL_TERSE, String.format("Sender [%s] class [%s] duration [%s] got exit-state [%s]", sender.getName(), ClassUtils.nameOf(sender), duration, exitState));
                }
            }
        }
    }
    return sendResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) SenderException(nl.nn.adapterframework.core.SenderException) IStreamingSender(nl.nn.adapterframework.stream.IStreamingSender) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 27 with PipeLine

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

the class WsdlGeneratorTest method testInputValidatorWithSchemaAttribute.

@Test(expected = IllegalStateException.class)
public void testInputValidatorWithSchemaAttribute() throws Exception {
    PipeLine pipeline = createPipeline();
    XmlValidator inputValidator = new XmlValidator();
    inputValidator.setSchema(validateResource("/OpenApi/simple.xsd"));
    pipeline.setInputValidator(inputValidator);
    WsdlGenerator generator = new WsdlGenerator(pipeline);
    assertNotNull(generator);
}
Also used : XmlValidator(nl.nn.adapterframework.pipes.XmlValidator) WsdlXmlValidator(nl.nn.adapterframework.pipes.WsdlXmlValidator) PipeLine(nl.nn.adapterframework.core.PipeLine) Test(org.junit.Test)

Example 28 with PipeLine

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

the class WsdlGeneratorTest method createPipeline.

private PipeLine createPipeline() throws Exception {
    EchoPipe pipe = new EchoPipe();
    pipe.registerForward(new PipeForward("success", null));
    pipe.setName(pipe.getClass().getSimpleName().concat("4WsdlGeneratorTest"));
    PipeLine pipeline = new PipeLine();
    pipeline.addPipe(pipe);
    PipeLineExit exit = new PipeLineExit();
    exit.setPath("exit");
    exit.setState(ExitState.SUCCESS);
    pipeline.registerPipeLineExit(exit);
    Adapter adapter = new Adapter();
    adapter.setName(pipe.getClass().getSimpleName().concat("4WsdlGeneratorTest"));
    adapter.setPipeLine(pipeline);
    pipeline.setAdapter(adapter);
    return pipeline;
}
Also used : EchoPipe(nl.nn.adapterframework.pipes.EchoPipe) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit)

Example 29 with PipeLine

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

the class JobDef method cleanupDatabase.

private void cleanupDatabase(IbisManager ibisManager) {
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = formatter.format(date);
    List<String> jmsRealmNames = new ArrayList<String>();
    for (Configuration configuration : ibisManager.getConfigurations()) {
        List<JobDef> scheduledJobs = configuration.getScheduledJobs();
        for (JobDef jobdef : configuration.getScheduledJobs()) {
            if (jobdef.getLocker() != null) {
                String jmsRealmName = jobdef.getLocker().getJmsRealName();
                if (!jmsRealmNames.contains(jmsRealmName)) {
                    jmsRealmNames.add(jmsRealmName);
                }
            }
        }
    }
    for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
        if (adapter instanceof Adapter) {
            PipeLine pipeLine = ((Adapter) adapter).getPipeLine();
            if (pipeLine != null) {
                for (IPipe pipe : pipeLine.getPipes()) {
                    if (pipe instanceof IExtendedPipe) {
                        IExtendedPipe extendedPipe = (IExtendedPipe) pipe;
                        if (extendedPipe.getLocker() != null) {
                            String jmsRealmName = extendedPipe.getLocker().getJmsRealName();
                            if (!jmsRealmNames.contains(jmsRealmName)) {
                                jmsRealmNames.add(jmsRealmName);
                            }
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = jmsRealmNames.iterator(); iter.hasNext(); ) {
        String jmsRealmName = (String) iter.next();
        setJmsRealm(jmsRealmName);
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealmName);
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < CONVERT(datetime, '" + formattedDate + "', 120)";
        } else {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        setQuery(deleteQuery);
        qs = null;
        executeQueryJob(ibisManager);
    }
    List messageLogs = new ArrayList();
    for (IAdapter iadapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iadapter;
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                if (msp.getMessageLog() != null) {
                    ITransactionalStorage transactionStorage = msp.getMessageLog();
                    if (transactionStorage instanceof JdbcTransactionalStorage) {
                        JdbcTransactionalStorage messageLog = (JdbcTransactionalStorage) transactionStorage;
                        String jmsRealmName = messageLog.getJmsRealName();
                        String expiryDateField = messageLog.getExpiryDateField();
                        String tableName = messageLog.getTableName();
                        String keyField = messageLog.getKeyField();
                        String typeField = messageLog.getTypeField();
                        MessageLogObject mlo = new MessageLogObject(jmsRealmName, tableName, expiryDateField, keyField, typeField);
                        if (!messageLogs.contains(mlo)) {
                            messageLogs.add(mlo);
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = messageLogs.iterator(); iter.hasNext(); ) {
        MessageLogObject mlo = (MessageLogObject) iter.next();
        setJmsRealm(mlo.getJmsRealmName());
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(mlo.getJmsRealmName());
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getKeyField() + " IN (SELECT " + mlo.getKeyField() + " FROM " + mlo.getTableName() + " WITH (rowlock,updlock,readpast) WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < CONVERT(datetime, '" + formattedDate + "', 120))";
        } else {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        qs = null;
        setQuery(deleteQuery);
        setQueryTimeout(900);
        executeQueryJob(ibisManager);
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Date(java.util.Date) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage) Iterator(java.util.Iterator) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) ArrayList(java.util.ArrayList) List(java.util.List) PipeLine(nl.nn.adapterframework.core.PipeLine) SimpleDateFormat(java.text.SimpleDateFormat) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 30 with PipeLine

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

the class ShowConfigurationStatusTest method testAllConfigs.

@Test
public void testAllConfigs() throws ConfigurationException, PipeRunException, DomBuilderException, SAXException, IOException, TransformerException {
    ShowConfigurationStatus showConfigurationStatus = new ShowConfigurationStatus();
    PipeLine pipeLine = new PipeLine();
    Adapter adapter = (Adapter) ibisContext.getIbisManager().getRegisteredAdapter("WebControlShowConfigurationStatus");
    pipeLine.setAdapter(adapter);
    showConfigurationStatus.registerForward(createPipeSuccessForward());
    showConfigurationStatus.configure(pipeLine);
    session.put("configuration", "*ALL*");
    MockHttpServletRequest request = new MockHttpServletRequest();
    session.put(IPipeLineSession.HTTP_REQUEST_KEY, request);
    PipeRunResult pipeRunResult = showConfigurationStatus.doPipe(null, session);
    compareXML("webcontrol/allConfigs.xml", (String) pipeRunResult.getResult());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) Test(org.junit.Test)

Aggregations

PipeLine (nl.nn.adapterframework.core.PipeLine)43 Adapter (nl.nn.adapterframework.core.Adapter)19 Test (org.junit.Test)17 XmlValidatorTest (nl.nn.adapterframework.pipes.XmlValidatorTest)12 IPipe (nl.nn.adapterframework.core.IPipe)10 PipeLineExit (nl.nn.adapterframework.core.PipeLineExit)8 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)8 IOException (java.io.IOException)6 IValidator (nl.nn.adapterframework.core.IValidator)6 XmlValidator (nl.nn.adapterframework.pipes.XmlValidator)6 Configuration (nl.nn.adapterframework.configuration.Configuration)5 PipeForward (nl.nn.adapterframework.core.PipeForward)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)5 Message (nl.nn.adapterframework.stream.Message)5 AbstractXmlValidator (nl.nn.adapterframework.validation.AbstractXmlValidator)5 JavaxXmlValidator (nl.nn.adapterframework.validation.JavaxXmlValidator)5 XercesXmlValidator (nl.nn.adapterframework.validation.XercesXmlValidator)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4