Search in sources :

Example 1 with IfsaException

use of nl.nn.adapterframework.extensions.ifsa.IfsaException 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 Message getRawReplyMessage(QueueSession session, IFSAQueue queue, TextMessage sentMessage) throws SenderException, TimeOutException {
    String selector = null;
    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 : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) IFSAReportMessage(com.ing.ifsa.IFSAReportMessage) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueReceiver(javax.jms.QueueReceiver) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) SenderException(nl.nn.adapterframework.core.SenderException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 2 with IfsaException

use of nl.nn.adapterframework.extensions.ifsa.IfsaException in project iaf by ibissource.

the class PullingIfsaProviderListener method openThread.

public Map openThread() throws ListenerException {
    Map threadContext = new HashMap();
    try {
        if (!isSessionsArePooled()) {
            QueueSession session = createSession();
            threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
            QueueReceiver receiver;
            receiver = getServiceReceiver(session);
            threadContext.put(THREAD_CONTEXT_RECEIVER_KEY, receiver);
        }
        return threadContext;
    } catch (IfsaException e) {
        throw new ListenerException(getLogPrefix() + "exception in openThread()", e);
    }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) HashMap(java.util.HashMap) QueueReceiver(javax.jms.QueueReceiver) HashMap(java.util.HashMap) Map(java.util.Map) QueueSession(javax.jms.QueueSession)

Example 3 with IfsaException

use of nl.nn.adapterframework.extensions.ifsa.IfsaException in project iaf by ibissource.

the class PushingIfsaProviderListener method close.

public void close() throws ListenerException {
    try {
        jmsConnector.stop();
        closeService();
    } catch (IfsaException e) {
        throw new ListenerException(getLogPrefix(), e);
    }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 4 with IfsaException

use of nl.nn.adapterframework.extensions.ifsa.IfsaException in project iaf by ibissource.

the class PushingIfsaProviderListener method afterMessageProcessed.

public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException {
    QueueSession session = (QueueSession) threadContext.get(IListenerConnector.THREAD_CONTEXT_SESSION_KEY);
    // on request-reply send the reply.
    if (getMessageProtocolEnum().equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) {
        Message originalRawMessage;
        if (rawMessage instanceof Message) {
            originalRawMessage = (Message) rawMessage;
        } else {
            originalRawMessage = (Message) threadContext.get(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
        }
        if (originalRawMessage == null) {
            String cid = (String) threadContext.get(IPipeLineSession.businessCorrelationIdKey);
            log.warn(getLogPrefix() + "no original raw message found for correlationId [" + cid + "], cannot send result");
        } else {
            if (session == null) {
                throw new ListenerException(getLogPrefix() + "no session found in context, cannot send result");
            }
            try {
                String result = "<exception>no result</exception>";
                if (plr != null && plr.getResult() != null) {
                    result = plr.getResult();
                }
                sendReply(session, originalRawMessage, result);
            } catch (IfsaException e) {
                try {
                    sendReply(session, originalRawMessage, "<exception>" + e.getMessage() + "</exception>");
                } catch (IfsaException e2) {
                    log.warn(getLogPrefix() + "exception sending errormessage as reply", e2);
                }
                throw new ListenerException(getLogPrefix() + "Exception on sending result", e);
            }
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage) Message(javax.jms.Message) IFSAMessage(com.ing.ifsa.IFSAMessage) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession)

Example 5 with IfsaException

use of nl.nn.adapterframework.extensions.ifsa.IfsaException in project iaf by ibissource.

the class IfsaFacade method sendMessage.

/**
 * Sends a message,and if transacted, the queueSession is committed.
 * <p>This method is intended for <b>clients</b>, as <b>server</b>s
 * will use the <code>sendReply</code>.
 * @return the correlationID of the sent message
 */
public TextMessage sendMessage(QueueSession session, QueueSender sender, String message, Map udzMap, String bifName, byte[] btcData) throws IfsaException {
    try {
        if (!isRequestor()) {
            throw new IfsaException(getLogPrefix() + "Provider cannot use sendMessage, should use sendReply");
        }
        IFSATextMessage msg = (IFSATextMessage) session.createTextMessage();
        msg.setText(message);
        if (udzMap != null && msg instanceof IFSAMessage) {
            // Handle UDZs
            log.debug(getLogPrefix() + "add UDZ map to IFSAMessage");
            // process the udzMap
            Map udzObject = (Map) ((IFSAMessage) msg).getOutgoingUDZObject();
            udzObject.putAll(udzMap);
        }
        String replyToQueueName = "-";
        // Client side
        if (messageProtocol.equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) {
            // set reply-to address
            Queue replyTo = getMessagingSource().getClientReplyQueue(session);
            msg.setJMSReplyTo(replyTo);
            replyToQueueName = replyTo.getQueueName();
        }
        if (messageProtocol.equals(IfsaMessageProtocolEnum.FIRE_AND_FORGET)) {
        // not applicable
        }
        if (StringUtils.isNotEmpty(bifName)) {
            msg.setBifName(bifName);
        }
        if (btcData != null && btcData.length > 0) {
            msg.setBtcData(btcData);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message [" + message + "]");
        } else {
            if (log.isInfoEnabled()) {
                log.info(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message");
            }
        }
        // send the message
        sender.send(msg);
        // perform commit
        if (isJmsTransacted() && !(messagingSource.isXaEnabledForSure() && JtaUtil.inTransaction())) {
            session.commit();
            log.debug(getLogPrefix() + "committing (send) transaction");
        }
        return msg;
    } catch (Exception e) {
        throw new IfsaException(e);
    }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) IFSAMessage(com.ing.ifsa.IFSAMessage) Map(java.util.Map) IFSAQueue(com.ing.ifsa.IFSAQueue) Queue(javax.jms.Queue) IbisException(nl.nn.adapterframework.core.IbisException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) IFSATextMessage(com.ing.ifsa.IFSATextMessage)

Aggregations

IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)14 JMSException (javax.jms.JMSException)9 IFSAQueue (com.ing.ifsa.IFSAQueue)6 Queue (javax.jms.Queue)5 TextMessage (javax.jms.TextMessage)5 Message (javax.jms.Message)4 QueueSession (javax.jms.QueueSession)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 IFSAMessage (com.ing.ifsa.IFSAMessage)3 IFSATextMessage (com.ing.ifsa.IFSATextMessage)3 Map (java.util.Map)3 QueueReceiver (javax.jms.QueueReceiver)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 IbisException (nl.nn.adapterframework.core.IbisException)3 IFSAPoisonMessage (com.ing.ifsa.IFSAPoisonMessage)2 IFSAReportMessage (com.ing.ifsa.IFSAReportMessage)2 IFSATimeOutMessage (com.ing.ifsa.IFSATimeOutMessage)2 HashMap (java.util.HashMap)2 QueueSender (javax.jms.QueueSender)2 SenderException (nl.nn.adapterframework.core.SenderException)2