Search in sources :

Example 66 with TimeoutException

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

the class ForEachChildElementPipe method iterateOverInput.

@Override
protected StopReason iterateOverInput(Message input, PipeLineSession session, Map<String, Object> threadContext, ItemCallback callback) throws SenderException, TimeoutException {
    InputSource src;
    if (isProcessFile()) {
        try {
            String filename;
            try {
                filename = input.asString();
            } catch (IOException e) {
                throw new SenderException(getLogPrefix(session) + "cannot find filename", e);
            }
            src = new InputSource(new FileInputStream(filename));
        } catch (FileNotFoundException e) {
            throw new SenderException("could not find file [" + input + "]", e);
        }
    } else {
        try {
            src = input.asInputSource();
        } catch (IOException e) {
            throw new SenderException("could not get InputSource", e);
        }
    }
    HandlerRecord handlerRecord = new HandlerRecord();
    try (ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null) {
        try {
            createHandler(handlerRecord, threadConnector, session, callback);
        } catch (TransformerException e) {
            throw new SenderException(handlerRecord.errorMessage, e);
        }
        try {
            XmlUtils.parseXml(src, handlerRecord.inputHandler);
        } catch (Exception e) {
            try {
                if (e instanceof SaxTimeoutException) {
                    if (e.getCause() != null && e.getCause() instanceof TimeoutException) {
                        throw (TimeoutException) e.getCause();
                    }
                    throw new TimeoutException(e);
                }
                if (!(e instanceof SaxAbortException)) {
                    throw new SenderException(e);
                }
            } finally {
                try {
                    handlerRecord.inputHandler.endDocument();
                } catch (Exception e2) {
                    log.warn("Exception in endDocument()", e2);
                }
            }
        }
    } catch (IOException e) {
        throw new SenderException(e);
    }
    return handlerRecord.itemHandler.stopReason;
// 2020-06-12 removing below 'rethrowTransformerException()', as it does not break the tests, and cannot be implemented when providing an OutputStream.
// However, if cases popup of errors not being signaled, this modification could be the cause.
// rethrowTransformerException(handlerRecord.transformerErrorListener, handlerRecord.errorMessage);
}
Also used : InputSource(org.xml.sax.InputSource) FileNotFoundException(java.io.FileNotFoundException) ThreadConnector(nl.nn.adapterframework.stream.ThreadConnector) IOException(java.io.IOException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) FileInputStream(java.io.FileInputStream) TransformerException(javax.xml.transform.TransformerException) SaxException(nl.nn.adapterframework.xml.SaxException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamingException(nl.nn.adapterframework.stream.StreamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException)

Example 67 with TimeoutException

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

the class IbisLocalSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String correlationID = session == null ? null : session.getMessageId();
    Message result = null;
    HashMap<String, Object> context = null;
    if (paramList != null) {
        try {
            context = (HashMap<String, Object>) paramList.getValues(message, session).getValueMap();
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
        }
    }
    if (context == null) {
        context = new HashMap<>();
    }
    String serviceIndication;
    if (StringUtils.isNotEmpty(getServiceName())) {
        serviceIndication = "service [" + getServiceName() + "]";
        try {
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling " + serviceIndication + " in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
                } else {
                    log.debug(getLogPrefix() + "calling " + serviceIndication + " in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling " + serviceIndication + " in same Thread");
                result = new Message(ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message.asString(), context));
            }
        } catch (ListenerException | IOException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeoutException) {
                throw new TimeoutException(getLogPrefix() + "timeout calling " + serviceIndication + "", e);
            }
            throw new SenderException(getLogPrefix() + "exception calling " + serviceIndication + "", e);
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (session != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, session, this);
            }
        }
    } else {
        String javaListener;
        if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
            try {
                javaListener = session.getMessage(getJavaListenerSessionKey()).asString();
            } catch (IOException e) {
                throw new SenderException("unable to resolve session key [" + getJavaListenerSessionKey() + "]", e);
            }
        } else {
            javaListener = getJavaListener();
        }
        serviceIndication = "JavaListener [" + javaListener + "]";
        try {
            JavaListener listener = JavaListener.getListener(javaListener);
            if (listener == null) {
                String msg = "could not find JavaListener [" + javaListener + "]";
                if (isThrowJavaListenerNotFoundException()) {
                    throw new SenderException(msg);
                }
                log.info(getLogPrefix() + msg);
                return new Message("<error>" + msg + "</error>");
            }
            if (isIsolated()) {
                if (isSynchronous()) {
                    log.debug(getLogPrefix() + "calling " + serviceIndication + " in separate Thread");
                    result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
                } else {
                    log.debug(getLogPrefix() + "calling " + serviceIndication + " in asynchronously");
                    isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
                    result = message;
                }
            } else {
                log.debug(getLogPrefix() + "calling " + serviceIndication + " in same Thread");
                result = new Message(listener.processRequest(correlationID, message.asString(), context));
            }
        } catch (ListenerException | IOException e) {
            if (ExceptionUtils.getRootCause(e) instanceof TimeoutException) {
                throw new TimeoutException(getLogPrefix() + "timeout calling " + serviceIndication, e);
            }
            throw new SenderException(getLogPrefix() + "exception calling " + serviceIndication, e);
        } finally {
            if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
                log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
            }
            if (session != null) {
                Misc.copyContext(getReturnedSessionKeys(), context, session, this);
            }
        }
    }
    ExitState exitState = (ExitState) context.remove(PipeLineSession.EXIT_STATE_CONTEXT_KEY);
    Object exitCode = context.remove(PipeLineSession.EXIT_CODE_CONTEXT_KEY);
    if (exitState != null && exitState != ExitState.SUCCESS) {
        context.put("originalResult", result);
        throw new SenderException(getLogPrefix() + "call to " + serviceIndication + " resulted in exitState [" + exitState + "] exitCode [" + exitCode + "]");
    }
    return result;
}
Also used : Message(nl.nn.adapterframework.stream.Message) IOException(java.io.IOException) ListenerException(nl.nn.adapterframework.core.ListenerException) ExitState(nl.nn.adapterframework.core.PipeLine.ExitState) JavaListener(nl.nn.adapterframework.receivers.JavaListener) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 68 with TimeoutException

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

the class IbisJavaSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String result = null;
    HashMap context = null;
    try {
        if (paramList != null) {
            context = (HashMap) paramList.getValues(message, session).getValueMap();
        } else {
            context = new HashMap();
        }
        DispatcherManager dm = null;
        Class c = Class.forName("nl.nn.adapterframework.dispatcher.DispatcherManagerFactory");
        if (getDispatchType().equalsIgnoreCase("DLL")) {
            String version = nl.nn.adapterframework.dispatcher.Version.version;
            if (version.contains("IbisServiceDispatcher 1.3"))
                throw new SenderException("IBIS-ServiceDispatcher out of date! Please update to version 1.4 or higher");
            Method getDispatcherManager = c.getMethod("getDispatcherManager", String.class);
            dm = (DispatcherManager) getDispatcherManager.invoke(null, getDispatchType());
        } else {
            Method getDispatcherManager = c.getMethod("getDispatcherManager");
            dm = (DispatcherManager) getDispatcherManager.invoke(null, (Object[]) null);
        }
        String serviceName;
        if (StringUtils.isNotEmpty(getServiceNameSessionKey())) {
            serviceName = session.getMessage(getServiceNameSessionKey()).asString();
        } else {
            serviceName = getServiceName();
        }
        String correlationID = session == null ? null : session.getMessage(PipeLineSession.businessCorrelationIdKey).asString();
        result = dm.processRequest(serviceName, correlationID, message.asString(), context);
        if (isMultipartResponse()) {
            return HttpSender.handleMultipartResponse(multipartResponseContentType, new ByteArrayInputStream(result.getBytes(multipartResponseCharset)), session);
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "exception processing message using request processor [" + serviceName + "]", e);
    } finally {
        if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
            log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
        }
        if (session != null) {
            Misc.copyContext(getReturnedSessionKeys(), context, session, this);
        }
    }
    return new Message(result);
}
Also used : Message(nl.nn.adapterframework.stream.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DispatcherManager(nl.nn.adapterframework.dispatcher.DispatcherManager) ParameterException(nl.nn.adapterframework.core.ParameterException) Method(java.lang.reflect.Method) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 69 with TimeoutException

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

the class MailSenderTest method createSender.

@Override
public MailSender createSender() throws Exception {
    MailSender mailSender = new MailSender() {

        Session mailSession;

        @Override
        protected Session createSession() throws SenderException {
            try {
                mailSession = super.createSession();
                Provider provider = new Provider(Type.TRANSPORT, "smtp", TransportMock.class.getCanonicalName(), "IbisSource.org", "1.0");
                mailSession.setProvider(provider);
                return mailSession;
            } catch (Exception e) {
                e.printStackTrace();
                throw new SenderException(e);
            }
        }

        @Override
        public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
            super.sendMessage(message, session);
            session.put("mailSession", mailSession);
            String correlationID = session.getMessageId();
            return new Message(correlationID);
        }
    };
    mailSender.setSmtpHost("localhost");
    mailSender.setSmtpUserid("user123");
    mailSender.setSmtpPassword("secret321");
    return mailSender;
}
Also used : Message(nl.nn.adapterframework.stream.Message) TransportMock(nl.nn.adapterframework.senders.mail.TransportMock) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Session(javax.mail.Session) Provider(javax.mail.Provider)

Example 70 with TimeoutException

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

the class IfsaRequesterSender method getRawReplyMessage.

/**
 * Retrieves a message with the specified correlationId from queue or other channel, but does no processing on it.
 */
private javax.jms.Message getRawReplyMessage(QueueSession session, IFSAQueue queue, TextMessage sentMessage) throws SenderException, TimeoutException {
    String selector = null;
    javax.jms.Message msg = null;
    QueueReceiver replyReceiver = null;
    try {
        replyReceiver = getReplyReceiver(session, sentMessage);
        selector = replyReceiver.getMessageSelector();
        long timeout = getExpiry(queue);
        log.debug(getLogPrefix() + "start waiting at most [" + timeout + "] ms for reply on message using selector [" + selector + "]");
        msg = replyReceiver.receive(timeout);
        if (msg == null) {
            log.info(getLogPrefix() + "received null reply");
        } else {
            log.info(getLogPrefix() + "received reply");
        }
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "got exception retrieving reply", e);
    } finally {
        try {
            closeReplyReceiver(replyReceiver);
        } catch (IfsaException e) {
            log.error(getLogPrefix() + "error closing replyreceiver", e);
        }
    }
    if (msg == null) {
        throw new TimeoutException(getLogPrefix() + " timed out waiting for reply using selector [" + selector + "]");
    }
    if (msg instanceof IFSATimeOutMessage) {
        throw new TimeoutException(getLogPrefix() + "received IFSATimeOutMessage waiting for reply using selector [" + selector + "]");
    }
    return msg;
// try {
// TextMessage result = (TextMessage)msg;
// return result;
// } catch (Exception e) {
// throw new SenderException(getLogPrefix()+"reply received for message using selector ["+selector+"] cannot be cast to TextMessage ["+msg.getClass().getName()+"]",e);
// }
}
Also used : QueueReceiver(javax.jms.QueueReceiver) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)68 TimeoutException (nl.nn.adapterframework.core.TimeoutException)45 IOException (java.io.IOException)40 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)34 TimeOutException (nl.nn.adapterframework.core.TimeOutException)28 Message (nl.nn.adapterframework.stream.Message)26 ParameterException (nl.nn.adapterframework.core.ParameterException)24 HashMap (java.util.HashMap)20 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)18 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)12 ListenerException (nl.nn.adapterframework.core.ListenerException)10 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)9 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)9 JMSException (javax.jms.JMSException)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)8 FileNotFoundException (java.io.FileNotFoundException)7 InputStream (java.io.InputStream)7 SAXException (org.xml.sax.SAXException)7 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)6