Search in sources :

Example 1 with IFSAMessage

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

the class PullingIfsaProviderListener method getIdFromRawMessage.

/**
 * Extracts ID-string from message obtained from {@link #getRawMessage(Map)}.
 * Puts also the following parameters  in the threadContext:
 * <ul>
 *   <li>id</li>
 *   <li>cid</li>
 *   <li>timestamp</li>
 *   <li>replyTo</li>
 *   <li>messageText</li>
 *   <li>fullIfsaServiceName</li>
 *   <li>ifsaServiceName</li>
 *   <li>ifsaGroup</li>
 *   <li>ifsaOccurrence</li>
 *   <li>ifsaVersion</li>
 * </ul>
 * @return ID-string of message for adapter.
 */
public String getIdFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    IFSAMessage message = null;
    if (rawMessage instanceof IMessageWrapper) {
        return getIdFromWrapper((IMessageWrapper) rawMessage, threadContext);
    }
    try {
        message = (IFSAMessage) rawMessage;
    } catch (ClassCastException e) {
        log.error(getLogPrefix() + "message received was not of type IFSAMessage, but [" + rawMessage.getClass().getName() + "]", e);
        return null;
    }
    String mode = "unknown";
    String id = "unset";
    String cid = "unset";
    Date tsSent = null;
    Destination replyTo = null;
    String messageText = null;
    String fullIfsaServiceName = null;
    IFSAServiceName requestedService = null;
    String ifsaServiceName = null, ifsaGroup = null, ifsaOccurrence = null, ifsaVersion = null;
    try {
        if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
            mode = "NON_PERSISTENT";
        } else if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT) {
            mode = "PERSISTENT";
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        cid = message.getJMSCorrelationID();
        if (cid == null) {
            cid = id;
            log.debug("Setting correlation ID to MessageId");
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        messageText = ((TextMessage) message).getText();
    } catch (Throwable ignore) {
    }
    // --------------------------
    try {
        fullIfsaServiceName = message.getServiceString();
        requestedService = message.getService();
        ifsaServiceName = requestedService.getServiceName();
        ifsaGroup = requestedService.getServiceGroup();
        ifsaOccurrence = requestedService.getServiceOccurance();
        ifsaVersion = requestedService.getServiceVersion();
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting serviceparameter", e);
    }
    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "got message for [" + fullIfsaServiceName + "] with JMSDeliveryMode=[" + mode + "] \n  JMSMessageID=[" + id + "] \n  JMSCorrelationID=[" + cid + "] \n  ifsaServiceName=[" + ifsaServiceName + "] \n  ifsaGroup=[" + ifsaGroup + "] \n  ifsaOccurrence=[" + ifsaOccurrence + "] \n  ifsaVersion=[" + ifsaVersion + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent) + "] \n  ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n  MessageHeaders=[" + displayHeaders(message) + "\n" + "] \n  Message=[" + message.toString() + "\n]");
    }
    PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", ((replyTo == null) ? "none" : replyTo.toString()));
    threadContext.put("messageText", messageText);
    threadContext.put("fullIfsaServiceName", fullIfsaServiceName);
    threadContext.put("ifsaServiceName", ifsaServiceName);
    threadContext.put("ifsaGroup", ifsaGroup);
    threadContext.put("ifsaOccurrence", ifsaOccurrence);
    threadContext.put("ifsaVersion", ifsaVersion);
    Map udz = (Map) message.getIncomingUDZObject();
    if (udz != null) {
        String contextDump = "ifsaUDZ:";
        for (Iterator it = udz.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = (String) udz.get(key);
            contextDump = contextDump + "\n " + key + "=[" + value + "]";
            threadContext.put(key, value);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + contextDump);
        }
    }
    return id;
}
Also used : Destination(javax.jms.Destination) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) IFSAMessage(com.ing.ifsa.IFSAMessage) IFSAServiceName(com.ing.ifsa.IFSAServiceName) Iterator(java.util.Iterator) JMSException(javax.jms.JMSException) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 2 with IFSAMessage

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

the class PushingIfsaProviderListener method getIdFromRawMessage.

/**
 * Extracts ID-string from message obtained from {@link #getRawMessage(Map)}.
 * Puts also the following parameters  in the threadContext:
 * <ul>
 *   <li>id</li>
 *   <li>cid</li>
 *   <li>timestamp</li>
 *   <li>replyTo</li>
 *   <li>messageText</li>
 *   <li>fullIfsaServiceName</li>
 *   <li>ifsaServiceName</li>
 *   <li>ifsaGroup</li>
 *   <li>ifsaOccurrence</li>
 *   <li>ifsaVersion</li>
 *   <li>ifsaBifName</li>
 *   <li>ifsaBtcData</li>
 * </ul>
 * @return ID-string of message for adapter.
 */
public String getIdFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    IFSAMessage message = null;
    if (rawMessage instanceof IMessageWrapper) {
        return getIdFromWrapper((IMessageWrapper) rawMessage, threadContext);
    }
    try {
        message = (IFSAMessage) rawMessage;
    } catch (ClassCastException e) {
        log.error(getLogPrefix() + "message received was not of type IFSAMessage, but [" + rawMessage.getClass().getName() + "]", e);
        return null;
    }
    String mode = "unknown";
    String id = "unset";
    String cid = "unset";
    Date tsSent = null;
    Destination replyTo = null;
    String messageText = null;
    String fullIfsaServiceName = null;
    IFSAServiceName requestedService = null;
    String ifsaServiceName = null, ifsaGroup = null, ifsaOccurrence = null, ifsaVersion = null;
    try {
        if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
            mode = "NON_PERSISTENT";
        } else if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT) {
            mode = "PERSISTENT";
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        cid = message.getJMSCorrelationID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();
    } catch (JMSException ignore) {
    }
    // --------------------------
    try {
        messageText = ((TextMessage) message).getText();
    } catch (Throwable ignore) {
    }
    // --------------------------
    try {
        fullIfsaServiceName = message.getServiceString();
        requestedService = message.getService();
        ifsaServiceName = requestedService.getServiceName();
        ifsaGroup = requestedService.getServiceGroup();
        ifsaOccurrence = requestedService.getServiceOccurance();
        ifsaVersion = requestedService.getServiceVersion();
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting serviceparameter", e);
    }
    String BIFname = null;
    try {
        BIFname = message.getBifName();
        if (StringUtils.isNotEmpty(BIFname)) {
            threadContext.put(THREAD_CONTEXT_BIFNAME_KEY, BIFname);
        }
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting BIFname", e);
    }
    byte[] btcData = null;
    try {
        btcData = message.getBtcData();
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting btcData", e);
    }
    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "got message for [" + fullIfsaServiceName + "] with JMSDeliveryMode=[" + mode + "] \n  JMSMessageID=[" + id + "] \n  JMSCorrelationID=[" + cid + "] \n  BIFname=[" + BIFname + "] \n  ifsaServiceName=[" + ifsaServiceName + "] \n  ifsaGroup=[" + ifsaGroup + "] \n  ifsaOccurrence=[" + ifsaOccurrence + "] \n  ifsaVersion=[" + ifsaVersion + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent) + "] \n  ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n  MessageHeaders=[" + displayHeaders(message) + "\n" + // + "] \n  btcData=["+ btcData
        "] \n  Message=[" + message.toString() + "\n]");
    }
    // if (cid == null) {
    // if (StringUtils.isNotEmpty(BIFname)) {
    // cid = BIFname;
    // if (log.isDebugEnabled()) log.debug("Setting correlation ID to BIFname ["+cid+"]");
    // } else {
    // cid = id;
    // if (log.isDebugEnabled()) log.debug("Setting correlation ID to MessageId ["+cid+"]");
    // }
    // }
    PipeLineSessionBase.setListenerParameters(threadContext, id, BIFname, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", ((replyTo == null) ? "none" : replyTo.toString()));
    threadContext.put("messageText", messageText);
    threadContext.put("fullIfsaServiceName", fullIfsaServiceName);
    threadContext.put("ifsaServiceName", ifsaServiceName);
    threadContext.put("ifsaGroup", ifsaGroup);
    threadContext.put("ifsaOccurrence", ifsaOccurrence);
    threadContext.put("ifsaVersion", ifsaVersion);
    threadContext.put("ifsaBifName", BIFname);
    threadContext.put("ifsaBtcData", btcData);
    Map udz = (Map) message.getIncomingUDZObject();
    if (udz != null) {
        String contextDump = "ifsaUDZ:";
        for (Iterator it = udz.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = (String) udz.get(key);
            contextDump = contextDump + "\n " + key + "=[" + value + "]";
            threadContext.put(key, value);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + contextDump);
        }
    }
    return BIFname;
}
Also used : Destination(javax.jms.Destination) JMSException(javax.jms.JMSException) Date(java.util.Date) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) IFSAMessage(com.ing.ifsa.IFSAMessage) IFSAServiceName(com.ing.ifsa.IFSAServiceName) Iterator(java.util.Iterator) Map(java.util.Map)

Example 3 with IFSAMessage

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

IFSAMessage (com.ing.ifsa.IFSAMessage)3 Map (java.util.Map)3 JMSException (javax.jms.JMSException)3 IFSAServiceName (com.ing.ifsa.IFSAServiceName)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Destination (javax.jms.Destination)2 IMessageWrapper (nl.nn.adapterframework.core.IMessageWrapper)2 IFSAQueue (com.ing.ifsa.IFSAQueue)1 IFSATextMessage (com.ing.ifsa.IFSATextMessage)1 HashMap (java.util.HashMap)1 Queue (javax.jms.Queue)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IbisException (nl.nn.adapterframework.core.IbisException)1 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)1