Search in sources :

Example 1 with IMessageWrapper

use of nl.nn.adapterframework.core.IMessageWrapper 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 IMessageWrapper

use of nl.nn.adapterframework.core.IMessageWrapper 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 IMessageWrapper

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

the class JdbcUtil method getBlobAsString.

public static String getBlobAsString(Blob blob, String column, String charset, boolean xmlEncode, boolean blobIsCompressed, boolean blobSmartGet, boolean encodeBlobBase64) throws IOException, JdbcException, SQLException, JMSException {
    if (encodeBlobBase64) {
        InputStream blobStream = JdbcUtil.getBlobInputStream(blob, column, blobIsCompressed);
        return Misc.streamToString(new Base64InputStream(blobStream, true), null, false);
    }
    if (blobSmartGet) {
        if (blob == null) {
            log.debug("no blob found in column [" + column + "]");
            return null;
        }
        int bl = (int) blob.length();
        InputStream is = blob.getBinaryStream();
        byte[] buf = new byte[bl];
        int bl1 = is.read(buf);
        Inflater decompressor = new Inflater();
        decompressor.setInput(buf);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(buf.length);
        byte[] bufDecomp = new byte[1024];
        boolean decompresOK = true;
        while (!decompressor.finished()) {
            try {
                int count = decompressor.inflate(bufDecomp);
                if (count == 0) {
                    break;
                }
                bos.write(bufDecomp, 0, count);
            } catch (DataFormatException e) {
                log.debug("message in column [" + column + "] is not compressed");
                decompresOK = false;
                break;
            }
        }
        bos.close();
        if (decompresOK)
            buf = bos.toByteArray();
        Object result = null;
        ObjectInputStream ois = null;
        boolean objectOK = true;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(buf);
            ois = new ObjectInputStream(bis);
            result = ois.readObject();
        } catch (Exception e) {
            log.debug("message in column [" + column + "] is probably not a serialized object: " + e.getClass().getName());
            objectOK = false;
        }
        if (ois != null)
            ois.close();
        String rawMessage;
        if (objectOK) {
            if (result instanceof IMessageWrapper) {
                rawMessage = ((IMessageWrapper) result).getText();
            } else if (result instanceof TextMessage) {
                rawMessage = ((TextMessage) result).getText();
            } else {
                rawMessage = (String) result;
            }
        } else {
            rawMessage = new String(buf, charset);
        }
        String message = XmlUtils.encodeCdataString(rawMessage);
        return message;
    }
    return Misc.readerToString(getBlobReader(blob, column, charset, blobIsCompressed), null, xmlEncode);
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) DataFormatException(java.util.zip.DataFormatException) ByteArrayInputStream(java.io.ByteArrayInputStream) Inflater(java.util.zip.Inflater) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) TextMessage(javax.jms.TextMessage) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with IMessageWrapper

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

the class JMSFacade method getStringFromRawMessage.

/**
 * Extracts string from message obtained from {@link #getRawMessage(Map)}. May also extract
 * other parameters from the message and put those in the threadContext.
 * @return String  input message for adapter.
 */
public String getStringFromRawMessage(Object rawMessage, Map context, boolean soap, String soapHeaderSessionKey, SoapWrapper soapWrapper) throws JMSException, DomBuilderException, TransformerException, IOException {
    TextMessage message = null;
    String rawMessageText;
    /*
		try {
			message = (TextMessage) rawMessage;
		} catch (ClassCastException e) {
			log.error("message received by listener on ["+ getDestinationName()+ "] was not of type TextMessage, but ["+rawMessage.getClass().getName()+"]", e);
			return null;
		}
		rawMessageText= message.getText();
*/
    if (rawMessage instanceof IMessageWrapper) {
        rawMessageText = ((IMessageWrapper) rawMessage).getText();
    } else if (rawMessage instanceof TextMessage) {
        rawMessageText = ((TextMessage) rawMessage).getText();
    } else {
        rawMessageText = (String) rawMessage;
    }
    if (!soap) {
        return rawMessageText;
    }
    String messageText = extractMessageBody(rawMessageText, context, soapWrapper);
    if (StringUtils.isNotEmpty(soapHeaderSessionKey)) {
        String soapHeader = soapWrapper.getHeader(rawMessageText);
        context.put(soapHeaderSessionKey, soapHeader);
    }
    return messageText;
}
Also used : IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) TextMessage(javax.jms.TextMessage)

Example 5 with IMessageWrapper

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

the class PullingIfsaProviderListener method getStringFromRawMessage.

/**
 * Extracts string from message obtained from {@link #getRawMessage(Map)}. May also extract
 * other parameters from the message and put those in the threadContext.
 * @return input message for adapter.
 */
public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
    if (rawMessage instanceof IMessageWrapper) {
        return getStringFromWrapper((IMessageWrapper) rawMessage, threadContext);
    }
    if (rawMessage instanceof IFSAPoisonMessage) {
        IFSAPoisonMessage pm = (IFSAPoisonMessage) rawMessage;
        IFSAHeader header = pm.getIFSAHeader();
        String source;
        try {
            source = header.getIFSA_Source();
        } catch (Exception e) {
            source = "unknown due to exeption:" + e.getMessage();
        }
        return "<poisonmessage>" + "  <source>" + source + "</source>" + "  <contents>" + XmlUtils.encodeChars(ToStringBuilder.reflectionToString(pm)) + "</contents>" + "</poisonmessage>";
    }
    TextMessage message = null;
    try {
        message = (TextMessage) rawMessage;
    } catch (ClassCastException e) {
        log.warn(getLogPrefix() + "message received was not of type TextMessage, but [" + rawMessage.getClass().getName() + "]", e);
        return null;
    }
    try {
        return message.getText();
    } catch (JMSException e) {
        throw new ListenerException(getLogPrefix(), e);
    }
}
Also used : IFSAHeader(com.ing.ifsa.IFSAHeader) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) ListenerException(nl.nn.adapterframework.core.ListenerException) JMSException(javax.jms.JMSException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) IFSATextMessage(com.ing.ifsa.IFSATextMessage) TextMessage(javax.jms.TextMessage) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage)

Aggregations

IMessageWrapper (nl.nn.adapterframework.core.IMessageWrapper)6 JMSException (javax.jms.JMSException)5 TextMessage (javax.jms.TextMessage)4 IFSAHeader (com.ing.ifsa.IFSAHeader)2 IFSAMessage (com.ing.ifsa.IFSAMessage)2 IFSAPoisonMessage (com.ing.ifsa.IFSAPoisonMessage)2 IFSAServiceName (com.ing.ifsa.IFSAServiceName)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Destination (javax.jms.Destination)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 ListenerException (nl.nn.adapterframework.core.ListenerException)2 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)2 IFSATextMessage (com.ing.ifsa.IFSATextMessage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1