use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class SimpleJMSStreamMessage method readDouble.
@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("");
}
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class SimpleJMSStreamMessage method readBoolean.
// Public --------------------------------------------------------
// StreamMessage implementation ----------------------------------
@Override
public boolean readBoolean() 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 Boolean) {
position++;
return ((Boolean) value).booleanValue();
} else if (value instanceof String) {
boolean result = Boolean.valueOf((String) value).booleanValue();
position++;
return result;
} else {
throw new MessageFormatException("Invalid conversion");
}
} catch (IndexOutOfBoundsException e) {
throw new MessageEOFException("");
}
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class SimpleJMSStreamMessage method readInt.
@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("");
}
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class SimpleJMSStreamMessage method readString.
@Override
public String readString() throws JMSException {
if (bodyWriteOnly) {
throw new MessageNotReadableException("The message body is writeonly");
}
try {
Object value = content.get(position);
offset = 0;
if (value == null) {
position++;
return null;
} else if (value instanceof Boolean) {
position++;
return ((Boolean) value).toString();
} else if (value instanceof Byte) {
position++;
return ((Byte) value).toString();
} else if (value instanceof Short) {
position++;
return ((Short) value).toString();
} else if (value instanceof Character) {
position++;
return ((Character) value).toString();
} else if (value instanceof Integer) {
position++;
return ((Integer) value).toString();
} else if (value instanceof Long) {
position++;
return ((Long) value).toString();
} else if (value instanceof Float) {
position++;
return ((Float) value).toString();
} else if (value instanceof Double) {
position++;
return ((Double) value).toString();
} else if (value instanceof String) {
position++;
return (String) value;
} else {
throw new MessageFormatException("Invalid conversion");
}
} catch (IndexOutOfBoundsException e) {
throw new MessageEOFException("");
}
}
use of javax.jms.MessageEOFException in project qpid-broker-j by apache.
the class AmqpManagementFacade method performOperationUsingAmqpManagement.
public Object performOperationUsingAmqpManagement(final String name, final String operation, final Session session, final String type, Map<String, Object> arguments) throws JMSException {
Destination replyToDestination;
Destination replyConsumerDestination;
if (_protocol == Protocol.AMQP_1_0) {
replyToDestination = session.createTemporaryQueue();
replyConsumerDestination = replyToDestination;
} else {
replyToDestination = session.createQueue(AMQP_0_X_REPLY_TO_DESTINATION);
replyConsumerDestination = session.createQueue(AMQP_0_X_CONSUMER_REPLY_DESTINATION);
}
MessageConsumer consumer = session.createConsumer(replyConsumerDestination);
MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));
MapMessage opMessage = session.createMapMessage();
opMessage.setStringProperty("type", type);
opMessage.setStringProperty("operation", operation);
opMessage.setStringProperty("index", "object-path");
opMessage.setJMSReplyTo(replyToDestination);
opMessage.setStringProperty("key", name);
for (Map.Entry<String, Object> argument : arguments.entrySet()) {
Object value = argument.getValue();
if (value.getClass().isPrimitive() || value instanceof String) {
opMessage.setObjectProperty(argument.getKey(), value);
} else {
ObjectMapper objectMapper = new ObjectMapper();
String jsonifiedValue;
try {
jsonifiedValue = objectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(String.format("Cannot convert the argument '%s' to JSON to meet JMS type restrictions", argument.getKey()));
}
opMessage.setObjectProperty(argument.getKey(), jsonifiedValue);
}
}
producer.send(opMessage);
if (session.getTransacted()) {
session.commit();
}
Message response = consumer.receive(5000);
try {
int statusCode = response.getIntProperty("statusCode");
if (statusCode < 200 || statusCode > 299) {
throw new OperationUnsuccessfulException(response.getStringProperty("statusDescription"), statusCode);
}
if (response instanceof StreamMessage) {
StreamMessage bodyStream = (StreamMessage) response;
List<Object> result = new ArrayList<>();
boolean done = false;
do {
try {
result.add(bodyStream.readObject());
} catch (MessageEOFException mfe) {
// Expected - end of stream
done = true;
}
} while (!done);
return result;
} else if (response instanceof MapMessage) {
MapMessage bodyMap = (MapMessage) response;
Map<String, Object> result = new TreeMap<>();
Enumeration mapNames = bodyMap.getMapNames();
while (mapNames.hasMoreElements()) {
String key = (String) mapNames.nextElement();
result.put(key, bodyMap.getObject(key));
}
return result;
} else if (response instanceof ObjectMessage) {
return ((ObjectMessage) response).getObject();
} else if (response instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) response;
if (bytesMessage.getBodyLength() == 0) {
return null;
} else {
byte[] buf = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(buf);
return buf;
}
}
throw new IllegalArgumentException("Cannot parse the results from a management operation. JMS response message : " + response);
} finally {
if (session.getTransacted()) {
session.commit();
}
consumer.close();
if (_protocol == Protocol.AMQP_1_0) {
((TemporaryQueue) replyToDestination).delete();
}
}
}
Aggregations