Search in sources :

Example 11 with ISender

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

the class Receiver method moveInProcessToError.

public void moveInProcessToError(String originalMessageId, String correlationId, ThrowingSupplier<Message, ListenerException> messageSupplier, Date receivedDate, String comments, Object rawMessage, TransactionDefinition txDef) {
    if (getListener() instanceof IHasProcessState) {
        ProcessState targetState = knownProcessStates.contains(ProcessState.ERROR) ? ProcessState.ERROR : ProcessState.DONE;
        try {
            changeProcessState(rawMessage, targetState, comments);
        } catch (ListenerException e) {
            log.error(getLogPrefix() + "Could not set process state to ERROR", e);
        }
    }
    ISender errorSender = getErrorSender();
    ITransactionalStorage<Serializable> errorStorage = getErrorStorage();
    if (errorSender == null && errorStorage == null && knownProcessStates().isEmpty()) {
        log.debug(getLogPrefix() + "has no errorSender, errorStorage or knownProcessStates, will not move message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
        return;
    }
    throwEvent(RCV_MESSAGE_TO_ERRORSTORE_EVENT);
    log.debug(getLogPrefix() + "moves message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to errorSender/errorStorage");
    TransactionStatus txStatus = null;
    try {
        txStatus = txManager.getTransaction(txDef);
    } catch (Exception e) {
        log.error(getLogPrefix() + "Exception preparing to move input message with id [" + originalMessageId + "] to error sender", e);
        // no use trying again to send message on errorSender, will cause same exception!
        return;
    }
    Message message = null;
    try {
        if (errorSender != null) {
            message = messageSupplier.get();
            errorSender.sendMessage(message, null);
        }
        if (errorStorage != null) {
            Serializable sobj;
            if (rawMessage == null) {
                if (message == null) {
                    message = messageSupplier.get();
                }
                if (message.isBinary()) {
                    sobj = message.asByteArray();
                } else {
                    sobj = message.asString();
                }
            } else {
                if (rawMessage instanceof Serializable) {
                    sobj = (Serializable) rawMessage;
                } else {
                    try {
                        sobj = new MessageWrapper(rawMessage, getListener());
                    } catch (ListenerException e) {
                        log.error(getLogPrefix() + "could not wrap non serializable message for messageId [" + originalMessageId + "]", e);
                        if (message == null) {
                            message = messageSupplier.get();
                        }
                        sobj = message;
                    }
                }
            }
            errorStorage.storeMessage(originalMessageId, correlationId, receivedDate, comments, null, sobj);
        }
        txManager.commit(txStatus);
    } catch (Exception e) {
        log.error(getLogPrefix() + "Exception moving message with id [" + originalMessageId + "] correlationId [" + correlationId + "] to error sender or error storage, original message: [" + message + "]", e);
        try {
            if (!txStatus.isCompleted()) {
                txManager.rollback(txStatus);
            }
        } catch (Exception rbe) {
            log.error(getLogPrefix() + "Exception while rolling back transaction for message  with id [" + originalMessageId + "] correlationId [" + correlationId + "], original message: [" + message + "]", rbe);
        }
    }
}
Also used : IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ProcessState(nl.nn.adapterframework.core.ProcessState) ListenerException(nl.nn.adapterframework.core.ListenerException) Serializable(java.io.Serializable) Message(nl.nn.adapterframework.stream.Message) IHasProcessState(nl.nn.adapterframework.core.IHasProcessState) ISender(nl.nn.adapterframework.core.ISender) TransactionStatus(org.springframework.transaction.TransactionStatus) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SenderException(nl.nn.adapterframework.core.SenderException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 12 with ISender

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

the class TestTool method executeSenderWrite.

private static int executeSenderWrite(String stepDisplayName, Map<String, Map<String, Object>> queues, Map<String, Object> writers, String queueName, String senderType, String fileContent) {
    int result = RESULT_ERROR;
    Map senderInfo = (Map) queues.get(queueName);
    ISender sender = (ISender) senderInfo.get(senderType + "Sender");
    Boolean convertExceptionToMessage = (Boolean) senderInfo.get("convertExceptionToMessage");
    PipeLineSession session = (PipeLineSession) senderInfo.get("session");
    SenderThread senderThread = new SenderThread(sender, fileContent, session, convertExceptionToMessage.booleanValue());
    senderThread.start();
    senderInfo.put(senderType + "SenderThread", senderThread);
    debugPipelineMessage(stepDisplayName, "Successfully started thread writing to '" + queueName + "':", fileContent, writers);
    logger.debug("Successfully started thread writing to '" + queueName + "'");
    result = RESULT_OK;
    return result;
}
Also used : ISender(nl.nn.adapterframework.core.ISender) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with ISender

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

the class IbisDebuggerAdvice method debugProvideOutputStream.

/**
 * Provides advice for {@link IOutputStreamingSupport#provideOutputStream(PipeLineSession session, IForwardTarget next)}
 */
public MessageOutputStream debugProvideOutputStream(ProceedingJoinPoint proceedingJoinPoint, PipeLineSession session) throws Throwable {
    if (!isEnabled()) {
        return (MessageOutputStream) proceedingJoinPoint.proceed();
    }
    String correlationId = session == null ? null : session.getMessageId();
    if (log.isDebugEnabled())
        log.debug("debugProvideOutputStream thread id [" + Thread.currentThread().getId() + "] thread name [" + Thread.currentThread().getName() + "] correlationId [" + correlationId + "]");
    if (proceedingJoinPoint.getTarget() instanceof ISender) {
        ISender sender = (ISender) proceedingJoinPoint.getTarget();
        // Use WriterPlaceHolder to make the contents that is later written to the MessageOutputStream appear as input of the Sender
        WriterPlaceHolder writerPlaceHolder = ibisDebugger.senderInput(sender, correlationId, new WriterPlaceHolder());
        MessageOutputStream resultStream = (MessageOutputStream) proceedingJoinPoint.proceed();
        String resultMessage = handleMessageOutputStream(writerPlaceHolder, resultStream);
        ibisDebugger.senderOutput(sender, correlationId, resultMessage);
        return resultStream;
    }
    if (proceedingJoinPoint.getTarget() instanceof IPipe) {
        IPipe pipe = (IPipe) proceedingJoinPoint.getTarget();
        PipeLine pipeLine = pipe instanceof AbstractPipe ? ((AbstractPipe) pipe).getPipeLine() : new PipeLine();
        // Use WriterPlaceHolder to make the contents that is later written to the MessageOutputStream appear as input of the Pipe
        WriterPlaceHolder writerPlaceHolder = ibisDebugger.pipeInput(pipeLine, pipe, correlationId, new WriterPlaceHolder());
        MessageOutputStream resultStream = (MessageOutputStream) proceedingJoinPoint.proceed();
        String resultMessage = handleMessageOutputStream(writerPlaceHolder, resultStream);
        ibisDebugger.pipeOutput(pipeLine, pipe, correlationId, resultMessage);
        return resultStream;
    }
    log.warn("Could not identify outputstream provider [" + proceedingJoinPoint.getTarget().getClass().getName() + "] as pipe or sender");
    return (MessageOutputStream) proceedingJoinPoint.proceed();
}
Also used : MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) ISender(nl.nn.adapterframework.core.ISender) PipeLine(nl.nn.adapterframework.core.PipeLine) IPipe(nl.nn.adapterframework.core.IPipe)

Example 14 with ISender

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

the class IbisDebuggerAdvice method debugSenderInputOutputAbort.

private <M> M debugSenderInputOutputAbort(ProceedingJoinPoint proceedingJoinPoint, Message message, PipeLineSession session, int messageParamIndex, boolean expectPipeRunResult) throws Throwable {
    if (!isEnabled()) {
        return (M) proceedingJoinPoint.proceed();
    }
    ISender sender = (ISender) proceedingJoinPoint.getTarget();
    if (!sender.isSynchronous() && sender instanceof JmsSender) {
        // Ignore JmsSenders within JmsListeners (calling JmsSender without ParameterResolutionContext) within Receivers.
        return (M) proceedingJoinPoint.proceed();
    }
    String messageId = session == null ? null : session.getMessageId();
    message = ibisDebugger.senderInput(sender, messageId, message);
    // result can be PipeRunResult (for StreamingSenders) or Message (for all other Senders)
    M result = null;
    // debugSenderGetInputFrom will be called.
    if (!ibisDebugger.stubSender(sender, messageId) || sender instanceof SenderWrapperBase) {
        try {
            Object[] args = proceedingJoinPoint.getArgs();
            args[messageParamIndex] = message;
            result = (M) proceedingJoinPoint.proceed(args);
        } catch (Throwable throwable) {
            throw ibisDebugger.senderAbort(sender, messageId, throwable);
        }
    } else {
        // resolve parameters itself
        if (sender instanceof IWithParameters) {
            ParameterList parameterList = ((IWithParameters) sender).getParameterList();
            if (parameterList != null) {
                parameterList.getValues(message, session);
            }
        }
    }
    if (sender instanceof SenderWrapperBase && ((SenderWrapperBase) sender).isPreserveInput()) {
        // signal in the debugger that the result of the sender has been replaced with the original input
        result = (M) ibisDebugger.preserveInput(messageId, (Message) result);
    }
    if (expectPipeRunResult) {
        // Create PipeRunResult when streaming sender is stubbed, this will forward to the next pipe and process the
        // message in a streaming.auto=false way (also when at the time of the original report the message was
        // processed with streaming.auto=true)
        PipeRunResult prr = result != null ? (PipeRunResult) result : new PipeRunResult();
        prr.setResult(ibisDebugger.senderOutput(sender, messageId, prr.getResult()));
        return (M) prr;
    }
    return (M) ibisDebugger.senderOutput(sender, messageId, Message.asMessage(result));
}
Also used : SenderWrapperBase(nl.nn.adapterframework.senders.SenderWrapperBase) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ISender(nl.nn.adapterframework.core.ISender) IWithParameters(nl.nn.adapterframework.core.IWithParameters) ParameterList(nl.nn.adapterframework.parameters.ParameterList) INamedObject(nl.nn.adapterframework.core.INamedObject) JmsSender(nl.nn.adapterframework.jms.JmsSender)

Example 15 with ISender

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

the class ShadowSender method configure.

@Override
public void configure() throws ConfigurationException {
    boolean hasShadowSender = false;
    boolean hasResultSender = false;
    boolean hasOriginalSender = false;
    if (originalSender == null)
        throw new ConfigurationException("no originalSender defined");
    if (resultSender == null)
        throw new ConfigurationException("no resultSender defined");
    for (ISender sender : getSenders()) {
        if (sender.getName() != null && sender.getName().equalsIgnoreCase(getOriginalSender())) {
            if (hasOriginalSender)
                throw new ConfigurationException("originalSender can only be defined once");
            hasOriginalSender = true;
        } else if (sender.getName() != null && sender.getName().equalsIgnoreCase(getResultSender())) {
            if (hasResultSender)
                throw new ConfigurationException("resultSender can only be defined once");
            hasResultSender = true;
            resultISender = sender;
        } else
            hasShadowSender = true;
    }
    if (!hasOriginalSender)
        throw new ConfigurationException("no originalSender found");
    if (!hasResultSender)
        throw new ConfigurationException("no resultSender found");
    if (!hasShadowSender)
        throw new ConfigurationException("no shadowSender found");
    if (getSenderList().size() == 0)
        throw new ConfigurationException("this is not supposed to happen, like ever");
    super.configure();
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender)

Aggregations

ISender (nl.nn.adapterframework.core.ISender)32 HashMap (java.util.HashMap)7 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)7 SenderException (nl.nn.adapterframework.core.SenderException)7 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 ISenderWithParameters (nl.nn.adapterframework.core.ISenderWithParameters)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)6 IOException (java.io.IOException)5 LinkedHashMap (java.util.LinkedHashMap)5 HasSender (nl.nn.adapterframework.core.HasSender)5 Serializable (java.io.Serializable)4 IPipe (nl.nn.adapterframework.core.IPipe)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 PipeLine (nl.nn.adapterframework.core.PipeLine)4 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)4 Message (nl.nn.adapterframework.stream.Message)4 IListener (nl.nn.adapterframework.core.IListener)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3