下面列出了javax.jms.Message#getClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Convert from a JMS Message to a Java object.
*
* @param message the message to convert for discovering who sends it
* @return the converted Java object
* @throws javax.jms.JMSException if thrown by JMS API methods
*/
@Override
public Object fromMessage(final Message message) throws JMSException {
if (!(message instanceof TextMessage)) {
throw new MessageFormatException("Expected TextMessage as response but received " + message.getClass());
} else {
try {
// LOGGER.debug("fromMessage() - Message received: " + ((TextMessage) message).getText());
LOGGER.debug("fromMessage() - Message properly received");
return this.xmlConverter.fromXml(((TextMessage) message).getText());
} catch (Exception ex) {
LOGGER.error("fromMessage() - Error caught in conversion of JMS message to Process Object");
LOGGER.error("Message was: " + ((TextMessage) message).getText());
throw new JMSException(ex.getMessage());
}
}
}
private void setForeignMessageDeliveryTime(Message foreignMessage, long deliveryTime) throws JMSException {
// Verify if the setJMSDeliveryTime method exists, i.e the foreign provider isn't only JMS 1.1.
Method deliveryTimeMethod = null;
try {
Class<?> clazz = foreignMessage.getClass();
Method method = clazz.getMethod("setJMSDeliveryTime", new Class[] { long.class });
if (!Modifier.isAbstract(method.getModifiers())) {
deliveryTimeMethod = method;
}
} catch (NoSuchMethodException e) {
// Assume its a JMS 1.1 Message, we will no-op.
}
if (deliveryTimeMethod != null) {
// Method exists, isn't abstract, so use it.
foreignMessage.setJMSDeliveryTime(deliveryTime);
}
}
private static long getForeignMessageDeliveryTime(Message foreignMessage) throws JMSException {
// Verify if the getJMSDeliveryTime method exists, i.e the foreign provider isn't only JMS 1.1.
Method deliveryTimeMethod = null;
try {
Class<?> clazz = foreignMessage.getClass();
Method method = clazz.getMethod("getJMSDeliveryTime", (Class[]) null);
if (!Modifier.isAbstract(method.getModifiers())) {
deliveryTimeMethod = method;
}
} catch (NoSuchMethodException e) {
// Assume its a JMS 1.1 Message, we will return 0.
}
if (deliveryTimeMethod != null) {
// Method exists, isn't abstract, so use it.
return foreignMessage.getJMSDeliveryTime();
}
return 0;
}
/**
* Template method that allows for custom message unmarshalling.
* Invoked when {@link #fromMessage(Message)} is invoked with a message
* that is not a {@link TextMessage} or {@link BytesMessage}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the message
* @param unmarshaller the unmarshaller to use
* @return the unmarshalled object
* @throws JMSException if thrown by JMS methods
* @throws IOException in case of I/O errors
* @throws XmlMappingException in case of OXM mapping errors
*/
protected Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller)
throws JMSException, IOException, XmlMappingException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
}
/**
* Template method that allows for custom message mapping.
* Invoked when {@link #setTargetType} is not {@link MessageType#TEXT} or
* {@link MessageType#BYTES}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the input message
* @param targetJavaType the target type
* @return the message converted to an object
* @throws JMSException if thrown by JMS
* @throws IOException in case of I/O errors
*/
protected Object convertFromMessage(Message message, JavaType targetJavaType)
throws JMSException, IOException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MappingJacksonMessageConverter by default only supports TextMessages and BytesMessages.");
}
/**
* Template method that allows for custom message unmarshalling.
* Invoked when {@link #fromMessage(Message)} is invoked with a message
* that is not a {@link TextMessage} or {@link BytesMessage}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the message
* @param unmarshaller the unmarshaller to use
* @return the unmarshalled object
* @throws JMSException if thrown by JMS methods
* @throws IOException in case of I/O errors
* @throws XmlMappingException in case of OXM mapping errors
*/
protected Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller)
throws JMSException, IOException, XmlMappingException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
}
/**
* Template method that allows for custom message mapping.
* Invoked when {@link #setTargetType} is not {@link MessageType#TEXT} or
* {@link MessageType#BYTES}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the input message
* @param targetJavaType the target type
* @return the message converted to an object
* @throws JMSException if thrown by JMS
* @throws IOException in case of I/O errors
*/
protected Object convertFromMessage(Message message, JavaType targetJavaType)
throws JMSException, IOException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MappingJacksonMessageConverter by default only supports TextMessages and BytesMessages.");
}
/**
* Template method that allows for custom message unmarshalling.
* Invoked when {@link #fromMessage(Message)} is invoked with a message
* that is not a {@link TextMessage} or {@link BytesMessage}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the message
* @param unmarshaller the unmarshaller to use
* @return the unmarshalled object
* @throws JMSException if thrown by JMS methods
* @throws IOException in case of I/O errors
* @throws XmlMappingException in case of OXM mapping errors
*/
protected Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller)
throws JMSException, IOException, XmlMappingException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
}
/**
* Template method that allows for custom message mapping.
* Invoked when {@link #setTargetType} is not {@link MessageType#TEXT} or
* {@link MessageType#BYTES}.
* <p>The default implementation throws an {@link IllegalArgumentException}.
* @param message the input message
* @param targetJavaType the target type
* @return the message converted to an object
* @throws JMSException if thrown by JMS
* @throws IOException in case of I/O errors
*/
protected Object convertFromMessage(Message message, JavaType targetJavaType)
throws JMSException, IOException {
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MappingJacksonMessageConverter by default only supports TextMessages and BytesMessages.");
}