Search in sources :

Example 1 with IFSATextMessage

use of com.ing.ifsa.IFSATextMessage in project iaf by ibissource.

the class PullingIfsaProviderListener method getRawMessage.

/**
 * Retrieves messages to be processed by the server, implementing an IFSA-service, but does no processing on it.
 */
public Object getRawMessage(Map threadContext) throws ListenerException {
    Object result = null;
    QueueSession session = null;
    QueueReceiver receiver = null;
    threadContext.remove(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
    try {
        session = getSession(threadContext);
        try {
            receiver = getReceiver(threadContext, session);
            result = receiver.receive(getTimeOut());
            while (result == null && canGoOn() && !JtaUtil.inTransaction()) {
                result = receiver.receive(getTimeOut());
            }
        } catch (Exception e) {
            throw new ListenerException(getLogPrefix(), e);
        } finally {
            releaseReceiver(receiver);
        }
    } finally {
        if (sessionNeedsToBeSavedForAfterProcessMessage(result)) {
            threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
        } else {
            releaseSession(session);
        }
    }
    if (result instanceof IFSAPoisonMessage) {
        IFSAHeader header = ((IFSAPoisonMessage) result).getIFSAHeader();
        String source;
        try {
            source = header.getIFSA_Source();
        } catch (Exception e) {
            source = "unknown due to exeption:" + e.getMessage();
        }
        String msg = getLogPrefix() + "received IFSAPoisonMessage " + "source [" + source + "]" + "content [" + ToStringBuilder.reflectionToString((IFSAPoisonMessage) result) + "]";
        log.warn(msg);
    }
    try {
        if ((result instanceof IFSATextMessage || result instanceof IFSAPoisonMessage) && JtaUtil.inTransaction()) {
            threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, result);
            result = new MessageWrapper(result, this);
        }
    } catch (Exception e) {
        throw new ListenerException("cannot wrap non serialzable message in wrapper", e);
    }
    return result;
}
Also used : IFSAHeader(com.ing.ifsa.IFSAHeader) ListenerException(nl.nn.adapterframework.core.ListenerException) QueueReceiver(javax.jms.QueueReceiver) INamedObject(nl.nn.adapterframework.core.INamedObject) MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) QueueSession(javax.jms.QueueSession) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage) IFSATextMessage(com.ing.ifsa.IFSATextMessage)

Example 2 with IFSATextMessage

use of com.ing.ifsa.IFSATextMessage 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

IFSATextMessage (com.ing.ifsa.IFSATextMessage)2 JMSException (javax.jms.JMSException)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)2 IFSAHeader (com.ing.ifsa.IFSAHeader)1 IFSAMessage (com.ing.ifsa.IFSAMessage)1 IFSAPoisonMessage (com.ing.ifsa.IFSAPoisonMessage)1 IFSAQueue (com.ing.ifsa.IFSAQueue)1 Map (java.util.Map)1 Queue (javax.jms.Queue)1 QueueReceiver (javax.jms.QueueReceiver)1 QueueSession (javax.jms.QueueSession)1 IMessageWrapper (nl.nn.adapterframework.core.IMessageWrapper)1 INamedObject (nl.nn.adapterframework.core.INamedObject)1 IbisException (nl.nn.adapterframework.core.IbisException)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 MessageWrapper (nl.nn.adapterframework.receivers.MessageWrapper)1