Search in sources :

Example 76 with ListenerException

use of nl.nn.adapterframework.core.ListenerException 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 77 with ListenerException

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

the class PullingIfsaProviderListener method afterMessageProcessed.

public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException {
    try {
        if (isJmsTransacted() && !(getMessagingSource().isXaEnabledForSure() && JtaUtil.inTransaction())) {
            QueueSession session = (QueueSession) threadContext.get(THREAD_CONTEXT_SESSION_KEY);
            try {
                session.commit();
            } catch (JMSException e) {
                log.error(getLogPrefix() + "got error committing the received message", e);
            }
            if (isSessionsArePooled()) {
                threadContext.remove(THREAD_CONTEXT_SESSION_KEY);
                releaseSession(session);
            }
        }
    } catch (Exception e) {
        log.error(getLogPrefix() + "exception in closing or releasing session", e);
    }
    // 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 id = (String) threadContext.get(IPipeLineSession.messageIdKey);
            String cid = (String) threadContext.get(IPipeLineSession.businessCorrelationIdKey);
            log.warn(getLogPrefix() + "no original raw message found for messageId [" + id + "] correlationId [" + cid + "], cannot send result");
        } else {
            QueueSession session = getSession(threadContext);
            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);
            } finally {
                releaseSession(session);
            }
        }
    }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage) Message(javax.jms.Message) IFSAMessage(com.ing.ifsa.IFSAMessage) IFSATextMessage(com.ing.ifsa.IFSATextMessage) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) 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)

Example 78 with ListenerException

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

Example 79 with ListenerException

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

the class EjbListenerPortConnector method start.

/**
 * Start Listener-port to which the Listener is connected.
 *
 * Sets internal stated to closed=false
 *
 * @throws nl.nn.adapterframework.core.ListenerException
 */
public void start() throws ListenerException {
    try {
        if (listenerPortMBean != null) {
            getAdminService().invoke(listenerPortMBean, "start", null, null);
            // Register again, to be sure, b/c a registration can have been
            // removed by some other controlling code.
            listenerPortPoller.registerEjbListenerPortConnector(this);
        }
        closed = false;
    } catch (Exception ex) {
        throw new ListenerException(ex);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 80 with ListenerException

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

the class IfsaEjbBeanBase method processRequest.

protected String processRequest(ServiceRequest request) throws ServiceException {
    log.debug(">>> processRequest() Processing IFSA Request, generic handling");
    Map threadContext = new HashMap();
    try {
        // listener.populateThreadContext(request, threadContext, null);
        String message = listener.getStringFromRawMessage(request, threadContext);
        String cid = listener.getIdFromRawMessage(request, threadContext);
        String replyText = listener.getHandler().processRequest(listener, cid, message, threadContext);
        if (log.isDebugEnabled()) {
            log.debug("processRequest(): ReplyText=[" + replyText + "]");
        }
        return replyText;
    } catch (ListenerException ex) {
        log.error(ex, ex);
        listener.getExceptionListener().exceptionThrown(listener, ex);
        // Do not invoke rollback, but let IFSA take care of that
        throw new ServiceException(ex);
    } finally {
        log.debug("<<< processRequest() finished generic handling");
    // listener.destroyThreadContext(threadContext);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) ServiceException(com.ing.ifsa.exceptions.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ListenerException (nl.nn.adapterframework.core.ListenerException)84 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)19 HashMap (java.util.HashMap)18 Map (java.util.Map)18 JMSException (javax.jms.JMSException)16 SenderException (nl.nn.adapterframework.core.SenderException)14 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)11 Session (javax.jms.Session)10 LinkedHashMap (java.util.LinkedHashMap)9 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)9 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 QueueSession (javax.jms.QueueSession)8 File (java.io.File)7 MessageConsumer (javax.jms.MessageConsumer)7 Message (javax.jms.Message)6