protected void processMessageHeaders()

in shims/qpid-jms/src/main/java/org/apache/qpid/interop_test/jms_hdrs_props_test/Receiver.java [365:414]


    protected void processMessageHeaders(Message message, JsonObject flagMap) throws Exception, JMSException {
        addMessageHeaderString("JMS_TYPE_HEADER", message.getJMSType());
        if (flagMap.containsKey("JMS_CORRELATIONID_AS_BYTES") && flagMap.getBoolean("JMS_CORRELATIONID_AS_BYTES")) {
            addMessageHeaderByteArray("JMS_CORRELATIONID_HEADER", message.getJMSCorrelationIDAsBytes());
        } else {
            addMessageHeaderString("JMS_CORRELATIONID_HEADER", message.getJMSCorrelationID());
        }
        if (flagMap.containsKey("JMS_REPLYTO_AS_TOPIC") && flagMap.getBoolean("JMS_REPLYTO_AS_TOPIC")) {
            addMessageHeaderDestination("JMS_REPLYTO_HEADER", JMS_DESTINATION_TYPE.JMS_TOPIC, message.getJMSReplyTo());
        } else {
            addMessageHeaderDestination("JMS_REPLYTO_HEADER", JMS_DESTINATION_TYPE.JMS_QUEUE, message.getJMSReplyTo());
        }
        if (flagMap.containsKey("JMS_CLIENT_CHECKS") && flagMap.getBoolean("JMS_CLIENT_CHECKS")) {
            // Get and check message headers which are set by a JMS-compient sender
            // See: https://docs.oracle.com/cd/E19798-01/821-1841/bnces/index.html
            // 1. Destination
            Destination destination = message.getJMSDestination();
            if (destination.toString().compareTo(_queue.toString()) != 0) {
                throw new Exception("JMS_DESTINATION header invalid: found \"" + destination.toString() +
                                    "\"; expected \"" + _queue.toString() + "\"");
            }
            // 2. Delivery Mode (persistence)
            int deliveryMode = message.getJMSDeliveryMode();
            if (deliveryMode != DeliveryMode.NON_PERSISTENT && deliveryMode != DeliveryMode.PERSISTENT) {
                throw new Exception("JMS_DELIVERY_MODE header invalid: " + deliveryMode);
            }
            // 3. Expiration
            long expiration = message.getJMSExpiration();
            if (expiration != 0) {
                throw new Exception("JMS_EXPIRATION header is non-zero");
            }
            // 4. Message ID
            String message_id = message.getJMSMessageID();
            // TODO: Find a check for this
            // 5. Message priority
            int message_priority = message.getJMSPriority();
            if (message_priority != 4) { // Default JMS message priority
                throw new Exception("JMS_PRIORITY header is not default (4): found " + message_priority);
            }
            // 6. Message timestamp
            long timeStamp = message.getJMSTimestamp();
            long currentTime = System.currentTimeMillis();
            if (currentTime - timeStamp > 60 * 1000) { // More than 1 minute old
                SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.S z");
                throw new Exception("JMS_TIMESTAMP header contains suspicious value: found " + timeStamp +
                                    " (" + df.format(timeStamp) + ") is not within 1 minute of " + currentTime +
                                    " (" + df.format(currentTime) + ")");
            }
        }
    }