本文整理汇总了Java中org.springframework.jms.support.converter.MessageConversionException类的典型用法代码示例。如果您正苦于以下问题:Java MessageConversionException类的具体用法?Java MessageConversionException怎么用?Java MessageConversionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageConversionException类属于org.springframework.jms.support.converter包,在下文中一共展示了MessageConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
Message message;
try {
switch (this.targetType) {
case TEXT:
message = mapToTextMessage(object, session, this.objectMapper);
break;
case BYTES:
message = mapToBytesMessage(object, session, this.objectMapper);
break;
default:
message = mapToMessage(object, session, this.objectMapper, this.targetType);
}
} catch (IOException ex) {
throw new MessageConversionException("Could not map JSON object [" + object + "]", ex);
}
setTypeIdOnMessage(object, message);
return message;
}
示例2: getJavaTypeForMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
protected JavaType getJavaTypeForMessage(Message message) throws JMSException {
if (null == this.typeIdPropertyName || !message.propertyExists(this.typeIdPropertyName)) {
return null;
}
String typeId = message.getStringProperty(this.typeIdPropertyName);
if (typeId == null) {
LOGGER.debug("Could not find type id property [{}]", typeIdPropertyName);
return null;
}
try {
Class<?> typeClass = ClassUtils.forName(typeId, this.beanClassLoader);
return this.objectMapper.getTypeFactory().constructType(typeClass);
} catch (Throwable ex) {
throw new MessageConversionException("Failed to resolve type id [" + typeId + "]", ex);
}
}
示例3: buildMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
/**
* 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 = (result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
if (content instanceof org.springframework.messaging.Message) {
return this.messagingMessageConverter.toMessage(content, session);
}
MessageConverter converter = getMessageConverter();
if (converter != null) {
return converter.toMessage(content, session);
}
if (!(content instanceof Message)) {
throw new MessageConversionException(
"No MessageConverter specified - cannot handle message [" + content + "]");
}
return (Message) content;
}
示例4: testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
final Session session = mock(Session.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
adapter.setMessageConverter(null);
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with MessageConversionException");
} catch(ReplyFailureException ex) {
assertEquals(MessageConversionException.class, ex.getCause().getClass());
}
}
示例5: testMapConversionWhereMapHasNonStringTypesForKeys
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Integer, String> content = new HashMap<Integer, String>(1);
content.put(1, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例6: fromMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
/**
* Converts an incoming tag update into a {@link DataTagValueUpdate} object.
*
* @param message the incoming tag update
*
* @throws JMSException if an error occurs converting the message
*/
@Override
public Object fromMessage(final Message message) throws JMSException {
if (message == null) {
throw new MessageConversionException("Message must not be null!");
}
if (!(message instanceof TextMessage)) {
throw new MessageConversionException("Message must be an instance of TextMessage!");
}
try {
String json = ((TextMessage) message).getText();
log.trace("Update received from DAQ:\n" + json);
return mapper.readValue(json, DataTagValueUpdate.class);
} catch (IOException | RuntimeException e) {
log.error("Exception caught while parsing incoming update", e);
throw new MessageConversionException("Exception caught while parsing incoming update: " + ((TextMessage) message).getText(), e);
}
}
示例7: fromXML
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
/**
* Converts the top level DOM element of an XML document to
* a ConfigurationRequest object.
* @param domElement the top-level XML element ("ConfigurationRequest")
* @return the request object
*/
private static ConfigurationRequest fromXML(final Element domElement) {
ConfigurationRequest result = null;
if (domElement.getNodeName().equals(CONFIGURATION_XML_ROOT)) {
String idStr = domElement.getAttribute(CONFIGURATION_ID_ATTRIBUTE);
if (idStr == null || idStr.length() == 0) {
throw new RuntimeException("Unable to read configuration request id: " + idStr);
} else {
result = new ConfigurationRequest(new Integer(idStr));
}
return result;
} else {
throw new MessageConversionException("Called the fromXML message on the wrong XML doc Element! - check your code as this should be checked first");
}
}
示例8: onMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Override
public void onMessage(final Message message, final Session session) throws JMSException {
try {
DataTagValueUpdate update = (DataTagValueUpdate) converter.fromMessage(message);
// We do the process PIK checking in order to accept or not the update
if(this.checkProcessPIK(update)) {
processUpdates(update);
}
else {
log.warn("Received update(s) for Process #" + update.getProcessId()
+ " with wrong PIK: Ignoring " + update.getValues().size() + " updates");
}
} catch (MessageConversionException ex) {
String errorMessage = "Error processing incoming update from DAQ: message is being discarded!";
log.error(errorMessage, ex);
if (System.currentTimeMillis() - lastEmailLog > EMAIL_FREQUENCY_MILLIS) {
EMAILLOGGER.error(errorMessage, ex);
lastEmailLog = System.currentTimeMillis();
}
}
}
示例9: onMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Override
public void onMessage(Message message) {
requireNonNull(message, "Message must not be null!");
log.debug("On message: {}", message);
AvMessage avMessage;
try {
avMessage = (AvMessage) messageConverter.fromMessage(message);
messageInfoService.save(avMessage, InfoSource.JMS_ADAPTER_IN, serviceId);
} catch (JMSException | MessageConversionException e) {
log.warn("Conversion error!", e);
return;
}
notifyListeners(getListeners(), avMessage);
}
示例10: fromMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
if (message instanceof TextMessage) {
String text = ((TextMessage) message).getText();
JmsMsg jmsMsg = null;
try {
jmsMsg = JSON.parseObject(text, JmsMsg.class);
}catch (Exception e){
return text;
}
Long msgId = jmsMsg.getMsgId();
// 不符合标准的jms 可能是旧系统的直接返回
if (msgId == null) return text;
//判断一下如果 msg id 存在就返回null
if (j2cache.get1(JMS_CACHE_KEY , msgId) == null) {
j2cache.set1n(JMS_CACHE_KEY , msgId, "", 60*60);
return jmsMsg.getData();
} else throw new MessageConversionException("MSG id exist" + msgId + " filter");
}
return message;
}
示例11: sendMessageResults
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
/** Returns the actual message results to the waiting client via DeferredResult.setResult() */
private void sendMessageResults(List<Message> msgs, DeferredResult<ModelAndView> result) throws MessageConversionException, JMSException {
if (msgs == null) msgs = Collections.emptyList();
List<Object> data = new ArrayList<Object>();
for (Message msg : msgs) {
// TODO: Probably should implement a custom MessageConverter for this instead
Object obj = converter.fromMessage(msg);
if (obj instanceof IFrameEvent) {
Map<String, Object> newobj = new HashMap<String, Object>();
for (Enumeration<?> e = msg.getPropertyNames(); e.hasMoreElements();) {
String key = (String) e.nextElement();
newobj.put(key, msg.getObjectProperty(key));
}
newobj.put("event", obj);
obj = newobj;
}
data.add(obj);
}
Map<String, Object> ret = new HashMap<String, Object>();
ret.put("size", msgs.size());
ret.put("data", data);
result.setResult(ModelAndViewFactory.contentNegotiatingModelAndView(ret));
}
示例12: testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
final Session session = mock(Session.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
adapter.setMessageConverter(null);
try {
adapter.onMessage(sentTextMessage, session);
fail("expected MessageConversionException");
} catch(MessageConversionException ex) { /* expected */ }
}
示例13: testMapConversionWhereMapHasNonStringTypesForKeys
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map content = new HashMap();
content.put(new Integer(1), "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例14: testMapConversionWhereMapHasNNullForKey
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map content = new HashMap();
content.put(null, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例15: fromMessage
import org.springframework.jms.support.converter.MessageConversionException; //导入依赖的package包/类
@Override
public Object fromMessage(Message message) throws JMSException,
MessageConversionException {
if(message instanceof MapMessage){
return EventConverter.convertToEvent((MapMessage) message );
}
throw new EdsException("eds message to event conversion exception : " + message);
}