<commit_before>/*
 * $Log: PushingJmsListener.java,v $
 * Revision 1.8  2008-01-03 15:51:56  europe\L190409
 * rework port connected listener interfaces
 *
 * Revision 1.7  2007/11/23 14:22:04  <NAME> <<EMAIL>>
 * Remove code that confirms processing of message to JMS Session, because from the PushingJmsListener this is now always done by a container.
 *
 * Revision 1.6  2007/11/22 13:29:52  <NAME> <<EMAIL>>
 * some more logging
 *
 * Revision 1.5  2007/11/22 09:08:56  <NAME> <<EMAIL>>
 * update from ejb-branch
 *
 * Revision 1.1.2.6  2007/11/15 10:35:24  <NAME> <<EMAIL>>
 * Add methods new in implemented interface
 *
 * Revision 1.1.2.5  2007/11/06 13:15:10  <NAME> <<EMAIL>>
 * Move code putting properties into threadContext from 'getIdFromRawMessage' to 'populateThreadContext'
 *
 * Revision 1.1.2.4  2007/11/06 12:43:56  <NAME> <<EMAIL>>
 * Improve some JavaDoc
 *
 * Revision 1.1.2.3  2007/11/06 12:41:17  <NAME> <<EMAIL>>
 * Add original raw message as parameter to method 'createThreadContext' of 'pushingJmsListener' in preparation of adding it to interface
 *
 * Revision 1.1.2.2  2007/11/06 12:29:54  <NAME> <<EMAIL>>
 * Rename parameter 'context' to 'threadContext', in keeping with other code
 *
 * Revision 1.1.2.1  2007/11/06 09:39:14  <NAME> <<EMAIL>>
 * Merge refactoring/renaming from HEAD
 *
 * Revision 1.4  2007/11/05 13:06:55  <NAME> <<EMAIL>>
 * Rename and redefine methods in interface IListenerConnector to remove 'jms' from names
 *
 * Revision 1.3  2007/11/05 12:26:51  <NAME> <<EMAIL>>
 * * Implement new interface 'IPortConnectedListener'
 * * Rename property 'jmsConfigurator' to 'jmsConnector'
 *
 * Revision 1.2  2007/11/05 10:33:15  <NAME> <<EMAIL>>
 * Move interface 'IListenerConnector' from package 'configuration' to package 'core' in preparation of renaming it
 *
 * Revision 1.1  2007/10/16 09:52:35  <NAME> <<EMAIL>>
 * Change over JmsListener to a 'switch-class' to facilitate smoother switchover from older version to spring version
 *
 * Revision 1.25.4.7  2007/10/12 09:09:06  <NAME> <<EMAIL>>
 * Fix compilation-problems after code-merge
 *
 * Revision 1.25.4.6  2007/10/04 12:01:21  <NAME> <<EMAIL>>
 * Work on EJB version of IBIS
 *
 * Revision 1.25.4.5  2007/10/01 09:16:18  <NAME> <<EMAIL>>
 * Lazy creation of Session when not provided by caller
 *
 * Revision 1.25.4.4  2007/09/28 14:20:26  <NAME> <<EMAIL>>
 * Add destroying of thread-context; allow session to be 'null' when populating thread-context
 *
 * Revision 1.25.4.3  2007/09/26 06:05:18  <NAME> <<EMAIL>>
 * Add exception-propagation to new JMS Listener; increase robustness of JMS configuration
 *
 * Revision 1.25.4.2  2007/09/21 09:20:33  <NAME> <<EMAIL>>
 * * Remove UserTransaction from Adapter
 * * Remove InProcessStorage; refactor a lot of code in Receiver
 *
 */
package nl.nn.adapterframework.jms;

import java.util.Date;
import java.util.Map;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.IListenerConnector;
import nl.nn.adapterframework.core.IMessageHandler;
import nl.nn.adapterframework.core.IPortConnectedListener;
import nl.nn.adapterframework.core.IReceiver;
import nl.nn.adapterframework.core.ISender;
import nl.nn.adapterframework.core.IbisExceptionListener;
import nl.nn.adapterframework.core.ListenerException;
import nl.nn.adapterframework.core.PipeLineResult;

/**
 * JMSListener re-implemented as a pushing listener rather than a pulling listener.
 * The JMS messages have to come in from an external source: an MDB or a Spring
 * message container.
 * 
 * Configuration is same as JmsListener / PullingJmsListener.
 * 
 * @author  <NAME>
 * @since   4.8
 * @version Id
 */
public class PushingJmsListener extends JMSFacade implements IPortConnectedListener {
    public static final String version="$RCSfile: PushingJmsListener.java,v $ $Revision: 1.8 $ $Date: 2008-01-03 15:51:56 $";

	private final static String THREAD_CONTEXT_SESSION_KEY="session";

    private long timeOut = 3000;
    private boolean useReplyTo=true;
    private String replyMessageType=null;
    private long replyMessageTimeToLive=0;
    private int replyPriority=-1;
    private String replyDeliveryMode=MODE_NON_PERSISTENT;
    private ISender sender;
    
    private boolean forceMessageIdAsCorrelationId=false;
 
    private String commitOnState="success";

	private String listenerPort;
	private String cacheMode = "CACHE_CONSUMER"; // set to CACHE_NONE if multiple JmsListeners appear in one chain, to avoid lock up / timeout in session creation
    
    private IListenerConnector jmsConnector;
    private IMessageHandler handler;
    private IReceiver receiver;
    private IbisExceptionListener exceptionListener;
    
    

    public void configure() throws ConfigurationException {
        super.configure();
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
        }
        if (jmsConnector==null) {
        	throw new ConfigurationException(getLogPrefix()+" has no jmsConnector. It should be configured via springContext.xml");
        }
		Destination destination=null;
        try {
			destination=getDestination();
		} catch (Exception e) {
			throw new ConfigurationException(getLogPrefix()+"could not get Destination",e);
		}
        try {
			jmsConnector.configureEndpointConnection(this, getConnection().getConnectionFactory(), destination, getExceptionListener(), getCacheMode(), false, getMessageSelector());
		} catch (JmsException e) {
			throw new ConfigurationException(e);
		}
    }

    public void open() throws ListenerException {
        // DO NOT open JMSFacade!
        jmsConnector.start();
    }

    public void close() throws ListenerException {
        try {
            // DO close JMSFacade - it might have been opened via other calls
            jmsConnector.stop();
            closeFacade();
			if (sender != null) {
				sender.close();
			}
        } catch (Exception ex) {
            throw new ListenerException(ex);
        }
    }<commit_msg>copy jmsTransacted to jmsConnector<commit_after>/*
 * $Log: PushingJmsListener.java,v $
 * Revision 1.9  2008-01-11 09:45:08  europe\L190409
 * copy jmsTransacted to jmsConnector
 *
 * Revision 1.8  2008/01/03 15:51:56  <NAME> <<EMAIL>>
 * rework port connected listener interfaces
 *
 * Revision 1.7  2007/11/23 14:22:04  <NAME> <<EMAIL>>
 * Remove code that confirms processing of message to JMS Session, because from the PushingJmsListener this is now always done by a container.
 *
 * Revision 1.6  2007/11/22 13:29:52  <NAME> <<EMAIL>>
 * some more logging
 *
 * Revision 1.5  2007/11/22 09:08:56  <NAME> <<EMAIL>>
 * update from ejb-branch
 *
 * Revision 1.1.2.6  2007/11/15 10:35:24  <NAME> <<EMAIL>>
 * Add methods new in implemented interface
 *
 * Revision 1.1.2.5  2007/11/06 13:15:10  <NAME> <<EMAIL>>
 * Move code putting properties into threadContext from 'getIdFromRawMessage' to 'populateThreadContext'
 *
 * Revision 1.1.2.4  2007/11/06 12:43:56  <NAME> <<EMAIL>>
 * Improve some JavaDoc
 *
 * Revision 1.1.2.3  2007/11/06 12:41:17  <NAME> <<EMAIL>>
 * Add original raw message as parameter to method 'createThreadContext' of 'pushingJmsListener' in preparation of adding it to interface
 *
 * Revision 1.1.2.2  2007/11/06 12:29:54  <NAME> <<EMAIL>>
 * Rename parameter 'context' to 'threadContext', in keeping with other code
 *
 * Revision 1.1.2.1  2007/11/06 09:39:14  <NAME> <<EMAIL>>
 * Merge refactoring/renaming from HEAD
 *
 * Revision 1.4  2007/11/05 13:06:55  <NAME> <<EMAIL>>
 * Rename and redefine methods in interface IListenerConnector to remove 'jms' from names
 *
 * Revision 1.3  2007/11/05 12:26:51  <NAME> <<EMAIL>>
 * * Implement new interface 'IPortConnectedListener'
 * * Rename property 'jmsConfigurator' to 'jmsConnector'
 *
 * Revision 1.2  2007/11/05 10:33:15  <NAME> <<EMAIL>>
 * Move interface 'IListenerConnector' from package 'configuration' to package 'core' in preparation of renaming it
 *
 * Revision 1.1  2007/10/16 09:52:35  <NAME> <<EMAIL>>
 * Change over JmsListener to a 'switch-class' to facilitate smoother switchover from older version to spring version
 *
 * Revision 1.25.4.7  2007/10/12 09:09:06  <NAME> <<EMAIL>>
 * Fix compilation-problems after code-merge
 *
 * Revision 1.25.4.6  2007/10/04 12:01:21  <NAME> <<EMAIL>>
 * Work on EJB version of IBIS
 *
 * Revision 1.25.4.5  2007/10/01 09:16:18  <NAME> <<EMAIL>>
 * Lazy creation of Session when not provided by caller
 *
 * Revision 1.25.4.4  2007/09/28 14:20:26  <NAME> <<EMAIL>>
 * Add destroying of thread-context; allow session to be 'null' when populating thread-context
 *
 * Revision 1.25.4.3  2007/09/26 06:05:18  <NAME> <<EMAIL>>
 * Add exception-propagation to new JMS Listener; increase robustness of JMS configuration
 *
 * Revision 1.25.4.2  2007/09/21 09:20:33  <NAME> <<EMAIL>>
 * * Remove UserTransaction from Adapter
 * * Remove InProcessStorage; refactor a lot of code in Receiver
 *
 */
package nl.nn.adapterframework.jms;

import java.util.Date;
import java.util.Map;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.commons.lang.StringUtils;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.IListenerConnector;
import nl.nn.adapterframework.core.IMessageHandler;
import nl.nn.adapterframework.core.IPortConnectedListener;
import nl.nn.adapterframework.core.IReceiver;
import nl.nn.adapterframework.core.ISender;
import nl.nn.adapterframework.core.IbisExceptionListener;
import nl.nn.adapterframework.core.ListenerException;
import nl.nn.adapterframework.core.PipeLineResult;

/**
 * JMSListener re-implemented as a pushing listener rather than a pulling listener.
 * The JMS messages have to come in from an external source: an MDB or a Spring
 * message container.
 * 
 * Configuration is same as JmsListener / PullingJmsListener.
 * 
 * @author  <NAME>
 * @since   4.8
 * @version Id
 */
public class PushingJmsListener extends JMSFacade implements IPortConnectedListener {
    public static final String version="$RCSfile: PushingJmsListener.java,v $ $Revision: 1.9 $ $Date: 2008-01-11 09:45:08 $";

	private final static String THREAD_CONTEXT_SESSION_KEY="session";

    private long timeOut = 3000;
    private boolean useReplyTo=true;
    private String replyMessageType=null;
    private long replyMessageTimeToLive=0;
    private int replyPriority=-1;
    private String replyDeliveryMode=MODE_NON_PERSISTENT;
    private ISender sender;
    
    private boolean forceMessageIdAsCorrelationId=false;
 
    private String commitOnState="success";

	private String listenerPort;
	private String cacheMode; 
    
    private IListenerConnector jmsConnector;
    private IMessageHandler handler;
    private IReceiver receiver;
    private IbisExceptionListener exceptionListener;
    
    

    public void configure() throws ConfigurationException {
        super.configure();
        ISender sender = getSender();
        if (sender != null) {
            sender.configure();
        }
        if (jmsConnector==null) {
        	throw new ConfigurationException(getLogPrefix()+" has no jmsConnector. It should be configured via springContext.xml");
        }
		if (StringUtils.isNotEmpty(getCacheMode())) {
			if (!getCacheMode().equals("CACHE_NONE") && 
				!getCacheMode().equals("CACHE_CONNECTION") && 
				!getCacheMode().equals("CACHE_SESSION") && 
				!getCacheMode().equals("CACHE_CONSUMER")) {
					throw new ConfigurationException(getLogPrefix()+"cacheMode ["+getCacheMode()+"] must be one of CACHE_NONE, CACHE_CONNECTION, CACHE_SESSION or CACHE_CONSUMER");
				}
		}
		Destination destination=null;
        try {
			destination=getDestination();
		} catch (Exception e) {
			throw new ConfigurationException(getLogPrefix()+"could not get Destination",e);
		}
        try {
			jmsConnector.configureEndpointConnection(this, getConnection().getConnectionFactory(), destination, getExceptionListener(), getCacheMode(), isJmsTransacted(), getMessageSelector());
		} catch (JmsException e) {
			throw new ConfigurationException(e);
		}
    }

    public void open() throws ListenerException {
        // DO NOT open JMSFacade!
        jmsConnector.start();
    }

    public void close() throws ListenerException {
        try {
            // DO close JMSFacade - it might have been opened via other calls
            jmsConnector.stop();
            closeFacade();
			if (sender != null) {
				sender.close();
			}
        } catch (Exception ex) {
            throw new ListenerException(ex);
        }
    }
{'fraction_non_alphanumeric': 0.10792435135979994, 'fraction_numerical': 0.060643951234760865, 'mean_word_length': 3.773218948153674, 'pattern_counts': {'":': 0, '<': 122, '<?xml version=': 0, '>': 122, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 24, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5710940', 'n_tokens_mistral': 4506, 'n_tokens_neox': 3994, 'n_words': 1152}