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
}
}
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();
}
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;
}
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;
}
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);
}
Aggregations