Search in sources :

Example 1 with MessageConversionException

use of org.springframework.jms.support.converter.MessageConversionException in project opennms by OpenNMS.

the class CollectionJobListener method onMessage.

@Override
public void onMessage(Message message) {
    try {
        // FIXME abstraction between technology and job handling is missing
        CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message);
        collectionJob = protocolCollectorRegistry.getProtocolCollector(collectionJob.getService()).collect(collectionJob);
        Date finishedTimestamp = new Date();
        collectionJob.setFinishedTimestamp(finishedTimestamp);
        Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination();
        int val = counter.incrementAndGet();
        if (val % 1000 == 0) {
            logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        } else {
            logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        }
        for (String destinationString : measurementSets.keySet()) {
            jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString));
            logger.info("** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString);
        }
        LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet(collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp());
        for (String metricId : collectionJob.getAllMetrics()) {
            if (collectionJob.getMetricValue(metricId) == null) {
                errorMeasurementSet.addMeasurement(metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId));
            }
            logger.trace("collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId));
        }
        if (errorMeasurementSet.getMeasurements().size() > 0) {
            logger.warn("result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size());
            jmsTemplate.convertAndSend("error", errorMeasurementSet);
            logger.trace("** sending to 'error'");
        }
    } catch (JMSException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    } catch (MessageConversionException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    }
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) JMSException(javax.jms.JMSException) Date(java.util.Date) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet)

Example 2 with MessageConversionException

use of org.springframework.jms.support.converter.MessageConversionException in project spring-integration by spring-projects.

the class ChannelPublishingJmsMessageListenerTests method testBadConversion.

@Test
public void testBadConversion() throws Exception {
    final QueueChannel requestChannel = new QueueChannel();
    ChannelPublishingJmsMessageListener listener = new ChannelPublishingJmsMessageListener();
    Log logger = spy(TestUtils.getPropertyValue(listener, "logger", Log.class));
    doNothing().when(logger).error(anyString(), any(Throwable.class));
    new DirectFieldAccessor(listener).setPropertyValue("logger", logger);
    listener.setRequestChannel(requestChannel);
    QueueChannel errorChannel = new QueueChannel();
    listener.setErrorChannel(errorChannel);
    listener.setBeanFactory(mock(BeanFactory.class));
    listener.setMessageConverter(new TestMessageConverter() {

        @Override
        public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException {
            return null;
        }
    });
    listener.afterPropertiesSet();
    javax.jms.Message jmsMessage = session.createTextMessage("test");
    listener.onMessage(jmsMessage, mock(Session.class));
    ErrorMessage received = (ErrorMessage) errorChannel.receive(0);
    assertNotNull(received);
    assertThat(received.getPayload().getMessage(), startsWith("Inbound conversion failed"));
    listener.stop();
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) QueueChannel(org.springframework.integration.channel.QueueChannel) Log(org.apache.commons.logging.Log) JMSException(javax.jms.JMSException) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BeanFactory(org.springframework.beans.factory.BeanFactory) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with MessageConversionException

use of org.springframework.jms.support.converter.MessageConversionException in project spring-framework by spring-projects.

the class AbstractAdaptableMessageListener method buildMessage.

/**
	 * Build a JMS message to be sent as response based on the given result object.
	 * @param session the JMS Session to operate on
	 * @param result the content of the message, as returned from the listener method
	 * @return the JMS {@code Message} (never {@code null})
	 * @throws JMSException if thrown by JMS API methods
	 * @see #setMessageConverter
	 */
protected Message buildMessage(Session session, Object result) throws JMSException {
    Object content = preProcessResponse(result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
    MessageConverter converter = getMessageConverter();
    if (converter != null) {
        if (content instanceof org.springframework.messaging.Message) {
            return this.messagingMessageConverter.toMessage(content, session);
        } else {
            return converter.toMessage(content, session);
        }
    }
    if (!(content instanceof Message)) {
        throw new MessageConversionException("No MessageConverter specified - cannot handle message [" + content + "]");
    }
    return (Message) content;
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) SmartMessageConverter(org.springframework.jms.support.converter.SmartMessageConverter) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) MessagingMessageConverter(org.springframework.jms.support.converter.MessagingMessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter)

Example 4 with MessageConversionException

use of org.springframework.jms.support.converter.MessageConversionException in project opennms by OpenNMS.

the class NrtBrokerJms method receiveMeasurementSets.

@Override
public List<MeasurementSet> receiveMeasurementSets(String nrtCollectionTaskId) {
    List<MeasurementSet> result = new ArrayList<MeasurementSet>();
    m_jmsTemplate.setReceiveTimeout(125);
    Message message = m_jmsTemplate.receive(nrtCollectionTaskId);
    while (message != null) {
        MeasurementSet measurementSet;
        try {
            measurementSet = (MeasurementSet) simpleMessageConverter.fromMessage(message);
            result.add(measurementSet);
        } catch (JMSException ex) {
            logger.error("Error receiving messages", ex);
            return result;
        } catch (MessageConversionException ex) {
            logger.error("Error converting messages", ex);
            return result;
        }
        message = m_jmsTemplate.receive(nrtCollectionTaskId);
    }
    return result;
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) Message(javax.jms.Message) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet)

Example 5 with MessageConversionException

use of org.springframework.jms.support.converter.MessageConversionException in project av-service by dvoraka.

the class JmsComponent method onMessage.

@Override
public void onMessage(Message message) {
    requireNonNull(message, "Message must not be null!");
    AvMessage avMessage;
    try {
        avMessage = (AvMessage) messageConverter.fromMessage(message);
        messageInfoService.save(avMessage, AvMessageSource.JMS_COMPONENT_IN, serviceId);
    } catch (JMSException | MessageConversionException e) {
        log.warn("Conversion error!", e);
        return;
    }
    notifyListeners(listeners, avMessage);
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) JMSException(javax.jms.JMSException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Aggregations

MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)8 JMSException (javax.jms.JMSException)7 Message (javax.jms.Message)4 Session (javax.jms.Session)3 Test (org.junit.Test)3 MessageConverter (org.springframework.jms.support.converter.MessageConverter)3 AvMessage (dvoraka.avservice.common.data.AvMessage)2 Connection (javax.jms.Connection)2 ConnectionFactory (javax.jms.ConnectionFactory)2 TextMessage (javax.jms.TextMessage)2 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)2 CamelContext (org.apache.camel.CamelContext)2 PollingConsumer (org.apache.camel.PollingConsumer)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 MeasurementSet (org.opennms.nrtg.api.model.MeasurementSet)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BytesMessage (javax.jms.BytesMessage)1 NamingException (javax.naming.NamingException)1