/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
if (sessionContext.supportsLargeMessage() && (getBodyInputStream(msg) != null || msg.isLargeMessage() || msg.getBodyBuffer().writerIndex() > minLargeMessageSize)) { isLarge = true; } else { session.setAddress(msg, sendingAddress); } else { msg.setAddress(sendingAddress); msg.putStringProperty(Message.HDR_GROUP_ID, groupID); final boolean sendBlockingConfig = msg.isDurable() ? blockOnDurableSend : blockOnNonDurableSend;
/** * Returns the result of an operation invocation or an attribute value. * <br> * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will return {@code false}. * and the result will be a String corresponding to the server exception. */ public static Object[] getResults(final ICoreMessage message) throws Exception { SimpleString sstring = message.getReadOnlyBodyBuffer().readNullableSimpleString(); String jsonString = (sstring == null) ? null : sstring.toString(); if (jsonString != null) { JsonArray jsonArray = JsonUtil.readJsonArray(jsonString); return JsonUtil.fromJsonArray(jsonArray); } else { return null; } }
/** * Stores an operation invocation in a message to invoke the corresponding operation the value from the server resource. * * @param message message * @param resourceName the name of the server resource * @param operationName the name of the operation to invoke on the server resource * @param parameters the parameters to use to invoke the server resource * @see ResourceNames */ public static void putOperationInvocation(final ICoreMessage message, final String resourceName, final String operationName, final Object... parameters) throws Exception { // store the name of the operation in the headers message.putStringProperty(ManagementHelper.HDR_RESOURCE_NAME, new SimpleString(resourceName)); message.putStringProperty(ManagementHelper.HDR_OPERATION_NAME, new SimpleString(operationName)); // and the params go in the body, since might be too large for header String paramString; if (parameters != null) { JsonArray jsonArray = JsonUtil.toJSONArray(parameters); paramString = jsonArray.toString(); } else { paramString = null; } message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(paramString)); }
public void printMessageAttributes(ICoreMessage message) throws XMLStreamException { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_ID, Long.toString(message.getMessageID())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_PRIORITY, Byte.toString(message.getPriority())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_EXPIRATION, Long.toString(message.getExpiration())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TIMESTAMP, Long.toString(message.getTimestamp())); String prettyType = XmlDataExporterUtil.getMessagePrettyType(message.getType()); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TYPE, prettyType); if (message.getUserID() != null) { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_USER_ID, message.getUserID().toString()); } } }
Assert.assertEquals(type, message.getType()); Assert.assertEquals(durable, message.isDurable()); Assert.assertEquals(expiration, message.getExpiration()); Assert.assertEquals(timestamp, message.getTimestamp()); Assert.assertEquals(priority, message.getPriority()); final byte priority2 = RandomUtil.randomByte(); message.setAddress(destination); Assert.assertEquals(destination, message.getAddressSimpleString()); message.setDurable(durable2); Assert.assertEquals(durable2, message.isDurable()); message.setExpiration(expiration2); Assert.assertEquals(expiration2, message.getExpiration()); message.setTimestamp(timestamp2); Assert.assertEquals(timestamp2, message.getTimestamp()); message.setPriority(priority2); Assert.assertEquals(priority2, message.getPriority());
AMQConsumer consumer) throws IOException { final ActiveMQMessage amqMsg; final byte coreType = coreMessage.getType(); final Boolean compressProp = (Boolean) coreMessage.getObjectProperty(AMQ_MSG_COMPRESSED); final boolean isCompressed = compressProp == null ? false : compressProp.booleanValue(); final byte[] bytes; final ActiveMQBuffer buffer = coreMessage.getDataBuffer(); buffer.resetReaderIndex(); break; default: throw new IllegalStateException("Unknown message type: " + coreMessage.getType()); final String type = coreMessage.getStringProperty(JMS_TYPE_PROPERTY); if (type != null) { amqMsg.setJMSType(type); amqMsg.setPersistent(coreMessage.isDurable()); amqMsg.setExpiration(coreMessage.getExpiration()); amqMsg.setPriority(coreMessage.getPriority()); amqMsg.setTimestamp(coreMessage.getTimestamp()); Long brokerInTime = (Long) coreMessage.getObjectProperty(AMQ_MSG_BROKER_IN_TIME); if (brokerInTime == null) { brokerInTime = 0L; Long arrival = (Long) coreMessage.getObjectProperty(AMQ_MSG_ARRIVAL); if (arrival == null) {
private void sendServerMessage(int messageId, ICoreMessage message, int deliveryCount, int qos) { String address = MQTTUtil.convertCoreAddressFilterToMQTT(message.getAddress() == null ? "" : message.getAddress().toString(), session.getWildcardConfiguration()); boolean isRetain = message.getBooleanProperty(MQTT_MESSAGE_RETAIN_KEY); ByteBuf payload; switch (message.getType()) { case Message.TEXT_TYPE: try { SimpleString text = message.getDataBuffer().readNullableSimpleString(); byte[] stringPayload = text.toString().getBytes("UTF-8"); payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length); payload.writeBytes(stringPayload); break; } catch (UnsupportedEncodingException e) { log.warn("Unable to send message: " + message.getMessageID() + " Cause: " + e.getMessage(), e); } default: ActiveMQBuffer bodyBuffer = message.getDataBuffer(); payload = ByteBufAllocator.DEFAULT.buffer(bodyBuffer.writerIndex()); payload.writeBytes(bodyBuffer.byteBuf()); break; } session.getProtocolHandler().send(messageId, address, qos, isRetain, payload, deliveryCount); }
protected void sendServerMessage(ICoreMessage message, String txID) throws ActiveMQStompException { StompSession stompSession = getSession(txID); if (stompSession.isNoLocal()) { message.putStringProperty(CONNECTION_ID_PROP, getID().toString()); } if (isEnableMessageID()) { message.putStringProperty("amqMessageId", "STOMP" + message.getMessageID()); } try { if (minLargeMessageSize == -1 || (message.getBodyBuffer().writerIndex() < minLargeMessageSize)) { stompSession.sendInternal(message, false); } else { stompSession.sendInternalLarge((CoreMessage)message, false); } } catch (Exception e) { throw BUNDLE.errorSendMessage(message, e).setHandler(frameHandler); } }
@Override public void copyHeadersAndProperties(final Message msg) { messageID = msg.getMessageID(); address = msg.getAddressSimpleString(); userID = (UUID) msg.getUserID(); type = msg.toCore().getType(); durable = msg.isDurable(); expiration = msg.getExpiration(); timestamp = msg.getTimestamp(); priority = msg.getPriority(); if (msg instanceof CoreMessage) { properties = ((CoreMessage) msg).getTypedProperties(); } }
msgI.putBooleanProperty(Message.HDR_LARGE_COMPRESSED, true); deflaterReader = new DeflaterReader(inputStreamParameter, messageSize); input = deflaterReader; msgI.getBodyBuffer().resetReaderIndex(); msgI.getBodyBuffer().resetWriterIndex(); msgI.putLongProperty(Message.HDR_LARGE_BODY_SIZE, deflaterReader.getTotalSize()); msgI.getBodyBuffer().writeBytes(buff, 0, pos); sendRegularMessage(msgI.getAddressSimpleString(), msgI, sendBlocking, credits, handler); return; } else {
public void printMessageBody(Message message, boolean encodeTextMessageUTF8) throws Exception { xmlWriter.writeStartElement(XmlDataConstants.MESSAGE_BODY); if (message.isLargeMessage()) { printLargeMessageBody((LargeServerMessage) message); } else { if (encodeTextMessageUTF8 && message.toCore().getType() == Message.TEXT_TYPE) { xmlWriter.writeCData(TextMessageUtil.readBodyText(message.toCore().getReadOnlyBodyBuffer()).toString()); } else { xmlWriter.writeCData(XmlDataExporterUtil.encodeMessageBodyBase64(message)); } } xmlWriter.writeEndElement(); // end MESSAGE_BODY }
public void decode() throws Exception { if (!message.isLargeMessage()) { message.getBodyBuffer().resetReaderIndex(); } }
/** * @param sendBlocking * @param msgI * @param handler * @throws ActiveMQException */ private void largeMessageSendBuffered(final boolean sendBlocking, final ICoreMessage msgI, final ClientProducerCredits credits, SendAcknowledgementHandler handler) throws ActiveMQException { msgI.getBodyBuffer().readerIndex(0); largeMessageSendStreamed(sendBlocking, msgI, new ActiveMQBufferInputStream(msgI.getBodyBuffer()), credits, handler); }
/** * Stores a resource attribute in a message to retrieve the value from the server resource. * * @param message message * @param resourceName the name of the resource * @param attribute the name of the attribute * @see ResourceNames */ public static void putAttribute(final ICoreMessage message, final String resourceName, final String attribute) { message.putStringProperty(ManagementHelper.HDR_RESOURCE_NAME, new SimpleString(resourceName)); message.putStringProperty(ManagementHelper.HDR_ATTRIBUTE, new SimpleString(attribute)); }
protected ICoreMessage createMessage(final long messageId, final SimpleString destination, final ByteBuffer buffer) { ICoreMessage msg = new CoreMessage(messageId, 200); msg.setAddress(destination); msg.getBodyBuffer().writeBytes(buffer); return msg; }
@Override public void setOriginalHeaders(ServerMessage otherServerMessage, MessageReference originalReference, boolean expiry) { ICoreMessage other = otherServerMessage.getICoreMessage(); SimpleString originalQueue = other.getSimpleStringProperty(Message.HDR_ORIGINAL_QUEUE); if (originalQueue != null) { message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalQueue); } else if (originalReference != null) { message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalReference.getQueue().getName()); } if (other.containsProperty(Message.HDR_ORIG_MESSAGE_ID)) { message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, other.getSimpleStringProperty(Message.HDR_ORIGINAL_ADDRESS)); message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getLongProperty(Message.HDR_ORIG_MESSAGE_ID)); } else { message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, new SimpleString(other.getAddress())); message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getMessageID()); } // reset expiry message.setExpiration(0); if (expiry) { long actualExpiryTime = System.currentTimeMillis(); message.putLongProperty(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime); } // TODO ASk clebert //message.bufferValid = false; }
@Override public Map<String, Object> getFields(MessageReference ref) throws OpenDataException { Map<String, Object> rc = super.getFields(ref); ICoreMessage m = ref.getMessage().toCore(); if (!m.isLargeMessage()) { SimpleString text = m.getReadOnlyBodyBuffer().readNullableSimpleString(); rc.put(CompositeDataConstants.TEXT_BODY, text != null ? text.toString() : ""); } else { rc.put(CompositeDataConstants.TEXT_BODY, ""); } return rc; } }
@Override public StompFrame createMessageFrame(ICoreMessage serverMessage, ActiveMQBuffer bodyBuffer, StompSubscription subscription, int deliveryCount) throws Exception { StompFrame frame = super.createMessageFrame(serverMessage, bodyBuffer, subscription, deliveryCount); if (!subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { frame.addHeader(Stomp.Headers.Message.ACK, String.valueOf(serverMessage.getMessageID())); } return frame; }
protected Message generateMessage(final long id) { ICoreMessage message = new CoreMessage(id, 1000); message.setMessageID(id); message.getBodyBuffer().writeString(UUID.randomUUID().toString()); message.setAddress(new SimpleString("foo")); return message; }