Search in sources :

Example 1 with IFSAPoisonMessage

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

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

Example 3 with IFSAPoisonMessage

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

the class PushingIfsaProviderListener 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 {
        String result = message.getText();
        threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, message);
        return result;
    } 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) TextMessage(javax.jms.TextMessage) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage)

Aggregations

IFSAHeader (com.ing.ifsa.IFSAHeader)3 IFSAPoisonMessage (com.ing.ifsa.IFSAPoisonMessage)3 JMSException (javax.jms.JMSException)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 IMessageWrapper (nl.nn.adapterframework.core.IMessageWrapper)3 ListenerException (nl.nn.adapterframework.core.ListenerException)3 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)3 IFSATextMessage (com.ing.ifsa.IFSATextMessage)2 TextMessage (javax.jms.TextMessage)2 QueueReceiver (javax.jms.QueueReceiver)1 QueueSession (javax.jms.QueueSession)1 INamedObject (nl.nn.adapterframework.core.INamedObject)1 MessageWrapper (nl.nn.adapterframework.receivers.MessageWrapper)1