本文整理汇总了Java中javax.jms.MessageFormatException类的典型用法代码示例。如果您正苦于以下问题:Java MessageFormatException类的具体用法?Java MessageFormatException怎么用?Java MessageFormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageFormatException类属于javax.jms包,在下文中一共展示了MessageFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertPropertyTo
import javax.jms.MessageFormatException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T convertPropertyTo(String name, Object value, Class<T> target) throws JMSException {
if (value == null) {
if (Boolean.class.equals(target)) {
return (T) Boolean.FALSE;
} else if (Float.class.equals(target) || Double.class.equals(target)) {
throw new NullPointerException("property " + name + " was null");
} else if (Number.class.isAssignableFrom(target)) {
throw new NumberFormatException("property " + name + " was null");
} else {
return null;
}
}
T rc = (T) TypeConversionSupport.convert(value, target);
if (rc == null) {
throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a " + target.getName());
}
return rc;
}
示例2: checkValidObject
import javax.jms.MessageFormatException; //导入依赖的package包/类
public static void checkValidObject(Object value) throws MessageFormatException {
boolean valid = value instanceof Boolean ||
value instanceof Byte ||
value instanceof Short ||
value instanceof Integer ||
value instanceof Long ||
value instanceof Float ||
value instanceof Double ||
value instanceof Character ||
value instanceof String ||
value == null;
if (!valid) {
throw new MessageFormatException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass());
}
}
示例3: getInt
import javax.jms.MessageFormatException; //导入依赖的package包/类
@Override
public int getInt(String name) throws JMSException {
Object value = getObject(name);
if (value instanceof Integer) {
return ((Integer) value).intValue();
} else if (value instanceof Short) {
return ((Short) value).intValue();
} else if (value instanceof Byte) {
return ((Byte) value).intValue();
} else if (value instanceof String || value == null) {
return Integer.valueOf((String) value).intValue();
} else {
throw new MessageFormatException("Cannot read an int from " + value.getClass().getSimpleName());
}
}
示例4: getLong
import javax.jms.MessageFormatException; //导入依赖的package包/类
@Override
public long getLong(String name) throws JMSException {
Object value = getObject(name);
if (value instanceof Long) {
return ((Long) value).longValue();
} else if (value instanceof Integer) {
return ((Integer) value).longValue();
} else if (value instanceof Short) {
return ((Short) value).longValue();
} else if (value instanceof Byte) {
return ((Byte) value).longValue();
} else if (value instanceof String || value == null) {
return Long.valueOf((String) value).longValue();
} else {
throw new MessageFormatException("Cannot read a long from " + value.getClass().getSimpleName());
}
}
示例5: checkValidObject
import javax.jms.MessageFormatException; //导入依赖的package包/类
private void checkValidObject(Object value) throws MessageFormatException {
boolean valid = value instanceof Boolean ||
value instanceof Byte ||
value instanceof Short ||
value instanceof Integer ||
value instanceof Long ||
value instanceof Float ||
value instanceof Double ||
value instanceof Character ||
value instanceof String ||
value instanceof byte[] ||
value == null;
if (!valid) {
throw new MessageFormatException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass());
}
}
示例6: doSend
import javax.jms.MessageFormatException; //导入依赖的package包/类
private void doSend(Destination destination, Message message) throws JMSException {
if (message == null) {
throw new MessageFormatException("Message must not be null");
}
for (Map.Entry<String, Object> entry : messageProperties.entrySet()) {
message.setObjectProperty(entry.getKey(), entry.getValue());
}
if (correlationId != null) {
message.setJMSCorrelationID(correlationId);
}
if (correlationIdBytes != null) {
message.setJMSCorrelationIDAsBytes(correlationIdBytes);
}
if (type != null) {
message.setJMSType(type);
}
if (replyTo != null) {
message.setJMSReplyTo(replyTo);
}
session.send(producer, destination, message, deliveryMode, priority, timeToLive, disableMessageId, disableTimestamp, deliveryDelay, completionListener);
}
示例7: getPrimitiveProperty
import javax.jms.MessageFormatException; //导入依赖的package包/类
/**
* Get the value for a property that represents a java primitive(e.g. int or
* long).
*
* @param property The name of the property to get.
* @param type The type of the property.
* @return the converted value for the property.
* @throws JMSException On internal error.
* @throws MessageFormatException If the property cannot be converted to the specified type.
* @throws NullPointerException and NumberFormatException when property name or value is
* null. Method throws same exception as primitives
* corresponding valueOf(String) method.
*/
<T> T getPrimitiveProperty(final String property, final Class<T> type) throws JMSException {
if (property == null) {
throw new NullPointerException("Property name is null");
}
final Object value = getObjectProperty(property);
if (value == null) {
return handleNullPropertyValue(property, type);
}
final T convertedValue = TypeConversionSupport.convert(value, type);
if (convertedValue == null) {
throw new MessageFormatException("Property " + property + " was " + value.getClass().getName() +
" and cannot be read as " + type.getName());
}
return convertedValue;
}
示例8: convertPropertyTo
import javax.jms.MessageFormatException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T convertPropertyTo(String name, Object value, Class<T> target) throws JMSException {
if (value == null) {
if (Boolean.class.equals(target)) {
return (T) Boolean.FALSE;
} else if (Float.class.equals(target) || Double.class.equals(target)) {
throw new NullPointerException("property " + name + " was null");
} else if (Number.class.isAssignableFrom(target)) {
throw new NumberFormatException("property " + name + " was null");
} else {
return null;
}
}
if (target.isInstance(value)) {
return target.cast(value);
} else {
try {
return target.getConstructor(String.class).newInstance(value.toString());
} catch (Exception e) {
throw new MessageFormatException("Property " + name + " was a "
+ value.getClass().getName() + " and cannot be read as a " + target.getName());
}
}
}
示例9: fromMessage
import javax.jms.MessageFormatException; //导入依赖的package包/类
/**
* 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());
}
}
}
示例10: Receive
import javax.jms.MessageFormatException; //导入依赖的package包/类
public Object Receive(String filter, long timeoutReceive) throws JMSException {
System.out.println("CLIENT: Creating cosumer: " + filter + "'");
MessageConsumer consumer = queuesession.createConsumer(queue, filter);
Message mrcv;
if ((mrcv = consumer.receive(timeoutReceive)) != null) {
Object rm1;
try {
rm1 = ((ObjectMessage) mrcv).getObject();
//System.out.println("RCV1: " + mrcv.getJMSCorrelationID() + " req=" + rm1.name);
return rm1;
} catch (MessageFormatException e) {
System.out.println("MessageFormatException: " + e.getMessage());
mrcv.acknowledge();
}
}
return null;
}
示例11: checkValidObject
import javax.jms.MessageFormatException; //导入依赖的package包/类
protected void checkValidObject(Object value) throws MessageFormatException {
boolean valid = value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long;
valid = valid || value instanceof Float || value instanceof Double || value instanceof Character || value instanceof String || value == null;
if (!valid) {
ActiveMQConnection conn = getConnection();
// conn is null if we are in the broker rather than a JMS client
if (conn == null || conn.isNestedMapAndListEnabled()) {
if (!(value instanceof Map || value instanceof List)) {
throw new MessageFormatException("Only objectified primitive objects, String, Map and List types are allowed but was: " + value + " type: " + value.getClass());
}
} else {
throw new MessageFormatException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass());
}
}
}
示例12: getStringProperty
import javax.jms.MessageFormatException; //导入依赖的package包/类
@Override
public String getStringProperty(String name) throws JMSException {
Object value = null;
if (name.equals("JMSXUserID")) {
value = getUserID();
if (value == null) {
value = getObjectProperty(name);
}
} else {
value = getObjectProperty(name);
}
if (value == null) {
return null;
}
String rc = (String) TypeConversionSupport.convert(value, String.class);
if (rc == null) {
throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a String");
}
return rc;
}
示例13: getBoolean
import javax.jms.MessageFormatException; //导入依赖的package包/类
/**
* Returns the <CODE>boolean</CODE> value with the specified name.
*
* @param name the name of the <CODE>boolean</CODE>
* @return the <CODE>boolean</CODE> value with the specified name
* @throws JMSException if the JMS provider fails to read the message due to
* some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public boolean getBoolean(String name) throws JMSException {
initializeReading();
Object value = map.get(name);
if (value == null) {
return false;
}
if (value instanceof Boolean) {
return ((Boolean)value).booleanValue();
}
if (value instanceof UTF8Buffer) {
return Boolean.valueOf(value.toString()).booleanValue();
}
if (value instanceof String) {
return Boolean.valueOf(value.toString()).booleanValue();
} else {
throw new MessageFormatException(" cannot read a boolean from " + value.getClass().getName());
}
}
示例14: getByte
import javax.jms.MessageFormatException; //导入依赖的package包/类
/**
* Returns the <CODE>byte</CODE> value with the specified name.
*
* @param name the name of the <CODE>byte</CODE>
* @return the <CODE>byte</CODE> value with the specified name
* @throws JMSException if the JMS provider fails to read the message due to
* some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public byte getByte(String name) throws JMSException {
initializeReading();
Object value = map.get(name);
if (value == null) {
return 0;
}
if (value instanceof Byte) {
return ((Byte)value).byteValue();
}
if (value instanceof UTF8Buffer) {
return Byte.valueOf(value.toString()).byteValue();
}
if (value instanceof String) {
return Byte.valueOf(value.toString()).byteValue();
} else {
throw new MessageFormatException(" cannot read a byte from " + value.getClass().getName());
}
}
示例15: getShort
import javax.jms.MessageFormatException; //导入依赖的package包/类
/**
* Returns the <CODE>short</CODE> value with the specified name.
*
* @param name the name of the <CODE>short</CODE>
* @return the <CODE>short</CODE> value with the specified name
* @throws JMSException if the JMS provider fails to read the message due to
* some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public short getShort(String name) throws JMSException {
initializeReading();
Object value = map.get(name);
if (value == null) {
return 0;
}
if (value instanceof Short) {
return ((Short)value).shortValue();
}
if (value instanceof Byte) {
return ((Byte)value).shortValue();
}
if (value instanceof UTF8Buffer) {
return Short.valueOf(value.toString()).shortValue();
}
if (value instanceof String) {
return Short.valueOf(value.toString()).shortValue();
} else {
throw new MessageFormatException(" cannot read a short from " + value.getClass().getName());
}
}