javax.jms.MessageFormatException Java Examples
The following examples show how to use
javax.jms.MessageFormatException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsSession.java From qpid-jms with Apache License 2.0 | 6 votes |
protected void send(JmsMessageProducer producer, Destination dest, Message msg, int deliveryMode, int priority, long timeToLive, boolean disableMsgId, boolean disableTimestamp, long deliveryDelay, CompletionListener listener) throws JMSException { if (dest == null) { throw new InvalidDestinationException("Destination must not be null"); } if (msg == null) { throw new MessageFormatException("Message must not be null"); } JmsDestination destination = JmsMessageTransformation.transformDestination(connection, dest); if (destination.isTemporary() && ((JmsTemporaryDestination) destination).isDeleted()) { throw new IllegalStateException("Temporary destination has been deleted"); } send(producer, destination, msg, deliveryMode, priority, timeToLive, disableMsgId, disableTimestamp, deliveryDelay, listener); }
Example #2
Source File: MockJMSMapMessage.java From pooled-jms with Apache License 2.0 | 6 votes |
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()); } }
Example #3
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public long getLong(final String name) throws JMSException { Object value; value = content.get(name); if (value == null) { return Long.parseLong(null); } if (value instanceof Byte) { return ((Byte) value).longValue(); } else if (value instanceof Short) { return ((Short) value).longValue(); } else if (value instanceof Integer) { return ((Integer) value).longValue(); } else if (value instanceof Long) { return ((Long) value).longValue(); } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new MessageFormatException("Invalid conversion"); } }
Example #4
Source File: JmsStreamMessage.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public byte readByte() throws JMSException { checkWriteOnlyBody(); checkBytesInFlight(); Byte result = null; Object value = facade.peek(); if (value instanceof Byte) { result = (Byte) value; } else if (value instanceof String || value == null) { result = Byte.valueOf((String) value); } else { throw new MessageFormatException( "stream value: " + value.getClass().getSimpleName() + " cannot be converted to a boolean."); } facade.pop(); return result; }
Example #5
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public int getInt(final String name) throws JMSException { Object value; value = content.get(name); if (value == null) { return Integer.parseInt(null); } if (value instanceof Byte) { return ((Byte) value).intValue(); } else if (value instanceof Short) { return ((Short) value).intValue(); } else if (value instanceof Integer) { return ((Integer) value).intValue(); } else if (value instanceof String) { return Integer.parseInt((String) value); } else { throw new MessageFormatException("Invalid conversion"); } }
Example #6
Source File: JmsStreamMessage.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public double readDouble() throws JMSException { checkWriteOnlyBody(); checkBytesInFlight(); Double result = null; Object value = facade.peek(); if (value instanceof Double) { result = (Double) value; } else if (value instanceof Float) { result = ((Float) value).doubleValue(); } else if (value instanceof String || value == null) { result = Double.valueOf((String) value); } else { throw new MessageFormatException( "stream value: " + value.getClass().getSimpleName() + " cannot be converted to a boolean."); } facade.pop(); return result; }
Example #7
Source File: MockJMSMapMessage.java From pooled-jms with Apache License 2.0 | 6 votes |
@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()); } }
Example #8
Source File: MockJMSMapMessage.java From pooled-jms with Apache License 2.0 | 6 votes |
@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()); } }
Example #9
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public char getChar(final String name) throws JMSException { Object value; value = content.get(name); if (value == null) { throw new NullPointerException("Invalid conversion"); } if (value instanceof Character) { return ((Character) value).charValue(); } else { throw new MessageFormatException("Invalid conversion"); } }
Example #10
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public byte getByte(final String name) throws JMSException { Object value; value = content.get(name); if (value == null) { return Byte.parseByte(null); } if (value instanceof Byte) { return ((Byte) value).byteValue(); } else if (value instanceof String) { return Byte.parseByte((String) value); } else { throw new MessageFormatException("Invalid conversion"); } }
Example #11
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public boolean getBoolean(final String name) throws JMSException { Object value; value = content.get(name); if (value == null) { return Boolean.valueOf(null).booleanValue(); } if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } else if (value instanceof String) { return Boolean.valueOf((String) value).booleanValue(); } else { throw new MessageFormatException("Invalid conversion"); } }
Example #12
Source File: ProcessMessageConverter.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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()); } } }
Example #13
Source File: JmsMapMessage.java From qpid-jms with Apache License 2.0 | 6 votes |
@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()); } }
Example #14
Source File: JMSMessagePropertySupport.java From pooled-jms with Apache License 2.0 | 6 votes |
@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; }
Example #15
Source File: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void setObject(final String name, final Object value) throws JMSException { try { // primitives and String Object val = value; if (value instanceof UnsignedInteger) { val = ((UnsignedInteger) value).intValue(); } else if (value instanceof UnsignedShort) { val = ((UnsignedShort) value).shortValue(); } else if (value instanceof UnsignedByte) { val = ((UnsignedByte) value).byteValue(); } else if (value instanceof UnsignedLong) { val = ((UnsignedLong) value).longValue(); } TypedProperties.setObjectProperty(new SimpleString(name), val, map); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #16
Source File: JmsStreamMessage.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public short readShort() throws JMSException { checkWriteOnlyBody(); checkBytesInFlight(); Short result = null; Object value = facade.peek(); if (value instanceof Short) { result = (Short) value; } else if (value instanceof Byte) { result = ((Byte) value).shortValue(); } else if (value instanceof String || value == null) { result = Short.valueOf((String) value); } else { throw new MessageFormatException( "stream value: " + value.getClass().getSimpleName() + " cannot be converted to a boolean."); } facade.pop(); return result; }
Example #17
Source File: SimpleJMSStreamMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public float readFloat() throws JMSException { if (bodyWriteOnly) { throw new MessageNotReadableException("The message body is writeonly"); } try { Object value = content.get(position); offset = 0; if (value == null) { throw new NullPointerException("Value is null"); } else if (value instanceof Float) { position++; return ((Float) value).floatValue(); } else if (value instanceof String) { float result = Float.parseFloat((String) value); position++; return result; } else { throw new MessageFormatException("Invalid conversion"); } } catch (IndexOutOfBoundsException e) { throw new MessageEOFException(""); } }
Example #18
Source File: JmsStreamMessage.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public int readInt() throws JMSException { checkWriteOnlyBody(); checkBytesInFlight(); Integer result = null; Object value = facade.peek(); if (value instanceof Integer) { result = (Integer) value; } else if (value instanceof Short) { result = ((Short) value).intValue(); } else if (value instanceof Byte) { result = ((Byte) value).intValue(); } else if (value instanceof String || value == null) { result = Integer.valueOf((String) value); } else { throw new MessageFormatException( "stream value: " + value.getClass().getSimpleName() + " cannot be converted to a boolean."); } facade.pop(); return result; }
Example #19
Source File: ActiveMQMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public String getStringProperty(final String name) throws JMSException { if (MessageUtil.JMSXDELIVERYCOUNT.equals(name)) { return String.valueOf(message.getDeliveryCount()); } try { return MessageUtil.getStringProperty(message, name); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #20
Source File: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public long getLong(final String name) throws JMSException { try { return map.getLongProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #21
Source File: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public byte getByte(final String name) throws JMSException { try { return map.getByteProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #22
Source File: ActiveMQMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public <T> T getBody(Class<T> c) throws JMSException { if (isBodyAssignableTo(c)) { return getBodyInternal(c); } else if (hasNoBody()) { return null; } // XXX HORNETQ-1209 Do we need translations here? throw new MessageFormatException("Body not assignable to " + c); }
Example #23
Source File: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public boolean getBoolean(final String name) throws JMSException { try { return map.getBooleanProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #24
Source File: ActiveMQMapMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetByteFromInvalidType() throws Exception { ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setFloat(itemName, RandomUtil.randomFloat()); try { message.getByte(itemName); Assert.fail("MessageFormatException"); } catch (MessageFormatException e) { } }
Example #25
Source File: JmsMapMessage.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public byte getByte(String name) throws JMSException { Object value = getObject(name); if (value instanceof Byte) { return ((Byte) value).byteValue(); } else if (value instanceof String || value == null) { return Byte.valueOf((String) value).byteValue(); } else { throw new MessageFormatException("Cannot read a byte from " + value.getClass().getSimpleName()); } }
Example #26
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setObject(final String name, final Object value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } if (value instanceof Boolean) { content.put(name, value); } else if (value instanceof Byte) { content.put(name, value); } else if (value instanceof Short) { content.put(name, value); } else if (value instanceof Character) { content.put(name, value); } else if (value instanceof Integer) { content.put(name, value); } else if (value instanceof Long) { content.put(name, value); } else if (value instanceof Float) { content.put(name, value); } else if (value instanceof Double) { content.put(name, value); } else if (value instanceof String) { content.put(name, value); } else if (value instanceof byte[]) { content.put(name, ((byte[]) value).clone()); } else { throw new MessageFormatException("Invalid object type."); } }
Example #27
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Object value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { if (value == null) { throw new NullPointerException("Attempt to write a new value"); } if (value instanceof String) { p.writeUTF((String) value); } else if (value instanceof Boolean) { p.writeBoolean(((Boolean) value).booleanValue()); } else if (value instanceof Byte) { p.writeByte(((Byte) value).byteValue()); } else if (value instanceof Short) { p.writeShort(((Short) value).shortValue()); } else if (value instanceof Integer) { p.writeInt(((Integer) value).intValue()); } else if (value instanceof Long) { p.writeLong(((Long) value).longValue()); } else if (value instanceof Float) { p.writeFloat(((Float) value).floatValue()); } else if (value instanceof Double) { p.writeDouble(((Double) value).doubleValue()); } else if (value instanceof byte[]) { p.write((byte[]) value, 0, ((byte[]) value).length); } else { throw new MessageFormatException("Invalid object for properties"); } } catch (IOException e) { throw new JMSException("IOException"); } }
Example #28
Source File: SimpleJMSStreamMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public double readDouble() throws JMSException { if (bodyWriteOnly) { throw new MessageNotReadableException("The message body is writeonly"); } try { Object value = content.get(position); offset = 0; if (value == null) { throw new NullPointerException("Value is null"); } else if (value instanceof Float) { position++; return ((Float) value).doubleValue(); } else if (value instanceof Double) { position++; return ((Double) value).doubleValue(); } else if (value instanceof String) { double result = Double.parseDouble((String) value); position++; return result; } else { throw new MessageFormatException("Invalid conversion"); } } catch (IndexOutOfBoundsException e) { throw new MessageEOFException(""); } }
Example #29
Source File: SimpleJMSStreamMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public long readLong() throws JMSException { if (bodyWriteOnly) { throw new MessageNotReadableException("The message body is writeonly"); } try { Object value = content.get(position); offset = 0; if (value == null) { throw new NullPointerException("Value is null"); } else if (value instanceof Byte) { position++; return ((Byte) value).longValue(); } else if (value instanceof Short) { position++; return ((Short) value).longValue(); } else if (value instanceof Integer) { position++; return ((Integer) value).longValue(); } else if (value instanceof Long) { position++; return ((Long) value).longValue(); } else if (value instanceof String) { long result = Long.parseLong((String) value); position++; return result; } else { throw new MessageFormatException("Invalid conversion"); } } catch (IndexOutOfBoundsException e) { throw new MessageEOFException(""); } }
Example #30
Source File: SimpleJMSStreamMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public int readInt() throws JMSException { if (bodyWriteOnly) { throw new MessageNotReadableException("The message body is writeonly"); } try { Object value = content.get(position); offset = 0; if (value == null) { throw new NullPointerException("Value is null"); } else if (value instanceof Byte) { position++; return ((Byte) value).intValue(); } else if (value instanceof Short) { position++; return ((Short) value).intValue(); } else if (value instanceof Integer) { position++; return ((Integer) value).intValue(); } else if (value instanceof String) { int result = Integer.parseInt((String) value); position++; return result; } else { throw new MessageFormatException("Invalid conversion"); } } catch (IndexOutOfBoundsException e) { throw new MessageEOFException(""); } }