<commit_before>/*
 * Copyright 2006-2009 ConSol* Software GmbH.
 * 
 * This file is part of Citrus.
 * 
 *  Citrus is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Citrus is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Citrus.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.consol.citrus.jms;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.core.Message;
import org.springframework.integration.jms.AbstractJmsTemplateBasedAdapter;
import org.springframework.integration.jms.HeaderMappingMessageConverter;
import org.springframework.integration.jms.JmsHeaderMapper;
import org.springframework.integration.message.GenericMessage;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConverter;

import com.consol.citrus.exceptions.ActionTimeoutException;
import com.consol.citrus.message.MessageReceiver;

public class JmsMessageReceiver extends AbstractJmsTemplateBasedAdapter implements MessageReceiver {
    
    private long receiveTimeout = 5000L;
    
    /**
     * Logger
     */
    private static final Logger log = LoggerFactory.getLogger(JmsMessageReceiver.class);
    
    public Message<?> receive(long timeout) {
        log.info("Receiving message from: " + getDestinationName());
        
        getJmsTemplate().setReceiveTimeout(timeout);
        Object receivedObject = getJmsTemplate().receiveAndConvert();
        
        if(receivedObject == null) {
            throw new ActionTimeoutException("Action timed out while receiving message on " + getDestinationName());
        }
        
        Message<?> receivedMessage;
        if (receivedObject instanceof Message<?>) {
            receivedMessage = (Message<?>)receivedObject;
        } else {
            receivedMessage = new GenericMessage<Object>(receivedObject);
        }
        
        if(log.isDebugEnabled()) {
            log.debug("Message received:");
            log.debug(receivedMessage.toString());
        }
        
        return receivedMessage;
    }

    public Message<?> receiveSelected(String selector, long timeout) {
        log.info("Receiving message from: " + getDestinationName() + "(" + selector + ")");
        
        Object receivedObject = getJmsTemplate().receiveSelectedAndConvert(selector);
        
        if(receivedObject == null) {
            throw new ActionTimeoutException("Action timed out while receiving message on " + getDestinationName());
        }
        
        Message<?> receivedMessage;
        if (receivedObject instanceof Message<?>) {
            receivedMessage = (Message<?>)receivedObject;
        } else {
            receivedMessage = new GenericMessage<Object>(receivedObject);<commit_msg>Fixed timeout setting in receive selected<commit_after>/*
 * Copyright 2006-2009 ConSol* Software GmbH.
 * 
 * This file is part of Citrus.
 * 
 *  Citrus is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Citrus is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Citrus.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.consol.citrus.jms;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.core.Message;
import org.springframework.integration.jms.AbstractJmsTemplateBasedAdapter;
import org.springframework.integration.jms.HeaderMappingMessageConverter;
import org.springframework.integration.jms.JmsHeaderMapper;
import org.springframework.integration.message.GenericMessage;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConverter;

import com.consol.citrus.exceptions.ActionTimeoutException;
import com.consol.citrus.message.MessageReceiver;

public class JmsMessageReceiver extends AbstractJmsTemplateBasedAdapter implements MessageReceiver {
    
    private long receiveTimeout = 5000L;
    
    /**
     * Logger
     */
    private static final Logger log = LoggerFactory.getLogger(JmsMessageReceiver.class);
    
    public Message<?> receive(long timeout) {
        log.info("Receiving message from: " + getDestinationName());
        
        getJmsTemplate().setReceiveTimeout(timeout);
        Object receivedObject = getJmsTemplate().receiveAndConvert();
        
        if(receivedObject == null) {
            throw new ActionTimeoutException("Action timed out while receiving message on " + getDestinationName());
        }
        
        Message<?> receivedMessage;
        if (receivedObject instanceof Message<?>) {
            receivedMessage = (Message<?>)receivedObject;
        } else {
            receivedMessage = new GenericMessage<Object>(receivedObject);
        }
        
        if(log.isDebugEnabled()) {
            log.debug("Message received:");
            log.debug(receivedMessage.toString());
        }
        
        return receivedMessage;
    }

    public Message<?> receiveSelected(String selector, long timeout) {
        log.info("Receiving message from: " + getDestinationName() + "(" + selector + ")");
        
        getJmsTemplate().setReceiveTimeout(timeout);
        Object receivedObject = getJmsTemplate().receiveSelectedAndConvert(selector);
        
        if(receivedObject == null) {
            throw new ActionTimeoutException("Action timed out while receiving message on " + getDestinationName());
        }
        
        Message<?> receivedMessage;
        if (receivedObject instanceof Message<?>) {
            receivedMessage = (Message<?>)receivedObject;
        } else {
            receivedMessage = new GenericMessage<Object>(receivedObject);
{'fraction_non_alphanumeric': 0.08872292755787901, 'fraction_numerical': 0.004480955937266617, 'mean_word_length': 3.2433460076045626, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '5328568', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1662, 'n_words': 477}