Example usage for javax.jms Message setIntProperty

List of usage examples for javax.jms Message setIntProperty

Introduction

In this page you can find the example usage for javax.jms Message setIntProperty.

Prototype


void setIntProperty(String name, int value) throws JMSException;

Source Link

Document

Sets an int property value with the specified name into the message.

Usage

From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java

public static void addProperties(Message jmsMsg) throws JMSException {
    jmsMsg.setStringProperty(STRING_METADATA, STRING_VALUE);
    jmsMsg.setBooleanProperty(BOOLEAN_METADATA, Boolean.valueOf(BOOLEAN_VALUE).booleanValue());
    jmsMsg.setIntProperty(INTEGER_METADATA, Integer.valueOf(INTEGER_VALUE).intValue());
}

From source file:org.test.app.web.framework.backend.messaging.services.integration.impl.live.SampleRepositoryImpl.java

@Override
public void fillHeader(final Message message, final AbstractIntegrationBean header) throws JMSException {
    message.setIntProperty("businessId", ((HeaderDTO) header).getSequenceId());
    message.setLongProperty("businessDate", ((HeaderDTO) header).getDate().getTime());
}

From source file:org.nebulaframework.grid.cluster.manager.services.jobs.splitaggregate.SplitterServiceImpl.java

/**
 * Enqueues a given Task with in the {@code TaskQueue}.
 * //  w ww  . j a va 2s  .c  o  m
 * @param jobId String JobId
 * @param taskId int TaskId (Sequence Number of Task)
 * @param task {@code GridTask} task
 */
private void enqueueTask(final GridJobProfile profile, final int taskId, GridTask<?> task) {

    final String jobId = profile.getJobId();

    // Send GridTask as a JMS Object Message to TaskQueue
    jmsTemplate.convertAndSend(JMSNamingSupport.getTaskQueueName(jobId), task, new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            // Post Process to include Meta Data
            message.setJMSCorrelationID(jobId); // Set Correlation ID to Job Id
            message.setIntProperty("taskId", taskId); // Put taskId as a property
            log.debug("Enqueued Task : " + taskId);
            return message;
        }
    });

    profile.getTaskTracker().taskEnqueued(taskId);
}

From source file:cherry.foundation.async.PropertyMessagePostProcessor.java

@Override
public Message postProcessMessage(Message message) throws JMSException {
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        String name = entry.getKey();
        Object v = entry.getValue();
        if (v instanceof String) {
            message.setStringProperty(name, (String) v);
        } else if (v instanceof Integer) {
            message.setIntProperty(name, ((Integer) v).intValue());
        } else if (v instanceof Long) {
            message.setLongProperty(name, ((Long) v).longValue());
        } else if (v instanceof Short) {
            message.setShortProperty(name, ((Short) v).shortValue());
        } else if (v instanceof Byte) {
            message.setByteProperty(name, ((Byte) v).byteValue());
        } else if (v instanceof Boolean) {
            message.setBooleanProperty(name, ((Boolean) v).booleanValue());
        } else if (v instanceof Double) {
            message.setDoubleProperty(name, ((Double) v).doubleValue());
        } else if (v instanceof Float) {
            message.setFloatProperty(name, ((Float) v).floatValue());
        } else {//from  w w w.  j a v a2  s  .co m
            message.setObjectProperty(name, v);
        }
    }
    return message;
}

From source file:org.nebulaframework.grid.cluster.manager.services.jobs.unbounded.UnboundedJobProcessor.java

/**
 * Enqueues a given Task with in the {@code TaskQueue}.
 * //w  w w  .  j a v  a  2s  .c om
 * @param jobId
 *            String JobId
 * @param taskId
 *            int TaskId (Sequence Number of Task)
 * @param task
 *            {@code GridTask} task
 */
private void enqueueTask(final String jobId, final int taskId, GridTask<?> task) {

    String queueName = JMSNamingSupport.getTaskQueueName(jobId);

    // Post Process to include Meta Data
    MessagePostProcessor postProcessor = new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            // Set Correlation ID to Job Id
            message.setJMSCorrelationID(jobId);

            // Put taskId as a property
            message.setIntProperty("taskId", taskId);

            log.debug("Enqueued Task : " + taskId);

            return message;
        }
    };

    // Send GridTask as a JMS Object Message to TaskQueue
    jmsTemplate.convertAndSend(queueName, task, postProcessor);

    // Update Task Tracker
    profile.getTaskTracker().taskEnqueued(taskId);

}

From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java

public void run() {

    try {/*from www  .  j av a  2  s  .  c  om*/
        Connection conn = getConnection();
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        if (isExpectReply()) {
            Destination replyTo = getDestinationProvider().getDestination(session, getReplyDestination());
            MessageConsumer consumer = session.createConsumer(replyTo);
            consumer.setMessageListener(this);
        }

        Destination dest = getDestinationProvider().getDestination(session, getDestinationName());
        MessageProducer producer = session.createProducer(dest);
        producer.setDeliveryMode(getDeliveryMode().getCode());
        getConnection().start();

        LOG.info(">>Starting Message send loop");
        while (!done.get()) {
            try {
                locallySent++;
                Destination replyDest = null;
                Message msg = getMessageFactory().createMessage(session);
                if (getMsgGroup() != null) {
                    LOG.debug("Setting message group to : " + getMsgGroup());
                    msg.setStringProperty("JMSXGroupID", getMsgGroup());
                    if (getMessagesToSend() > 0) {
                        if (locallySent == getMessagesToSend()) {
                            LOG.debug("Closing message group: " + getMsgGroup());
                            msg.setIntProperty("JMSXGroupSeq", 0);
                        }
                    }
                }
                msg.setLongProperty("MsgNr", locallySent);
                if (isExpectReply()) {
                    corrId = getReplyDestination() + "Seq-" + locallySent;
                    msg.setStringProperty("JMSCorrelationID", corrId);
                    replyDest = getDestinationProvider().getDestination(session, getReplyDestination());
                    msg.setJMSReplyTo(replyDest);
                    receivedResponse = false;
                }
                long sendTime = System.currentTimeMillis();
                producer.send(msg, deliveryMode.getCode(), 4, ttl);
                if (sent != null) {
                    sent.incrementAndGet();
                }
                done.set((getMessagesToSend() > 0) && ((locallySent) == getMessagesToSend()));
                if (isExpectReply()) {
                    try {
                        LOG.debug("Waiting for response ...");
                        synchronized (corrId) {
                            try {
                                if (getReplyTimeOut() > 0) {
                                    corrId.wait(getReplyTimeOut());
                                } else {
                                    corrId.wait();
                                }
                            } catch (InterruptedException ie) {
                            }
                            if (receivedResponse) {
                                long duration = System.currentTimeMillis() - sendTime;
                                LOG.debug("Got response from peer in " + duration + " ms");
                            } else {
                                LOG.error("Response not received within time frame...");
                                if (timeOuts != null) {
                                    timeOuts.incrementAndGet();
                                }
                            }
                        }
                    } catch (Exception e) {
                        if (exceptions != null) {
                            exceptions.incrementAndGet();
                        }
                    }
                }
                if (sleep > 0L) {
                    try {
                        Thread.sleep(sleep);
                    } catch (InterruptedException ie) {
                    }
                }
            } catch (JMSException e) {
                if (exceptions != null) {
                    exceptions.incrementAndGet();
                }
            }
        }
    } catch (Exception e) {
    } finally {
        try {
            closeConnection();
        } catch (Throwable e) {
        }
    }
    LOG.info(">>MessageSender done...(" + sent + ")");
}

From source file:hermes.impl.DefaultXMLHelper.java

public Message createMessage(MessageFactory hermes, XMLMessage message)
        throws JMSException, IOException, ClassNotFoundException, DecoderException {
    try {//from   ww  w .j  a va  2s.c om
        Message rval = hermes.createMessage();

        if (message instanceof XMLTextMessage) {
            rval = hermes.createTextMessage();

            XMLTextMessage textMessage = (XMLTextMessage) message;
            TextMessage textRval = (TextMessage) rval;

            if (BASE64_CODEC.equals(textMessage.getCodec())) {
                byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes());
                textRval.setText(new String(bytes, "ASCII"));
            } else {
                textRval.setText(textMessage.getText());
            }
        } else if (message instanceof XMLMapMessage) {
            rval = hermes.createMapMessage();

            XMLMapMessage mapMessage = (XMLMapMessage) message;
            MapMessage mapRval = (MapMessage) rval;

            for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) {
                final Property property = (Property) iter.next();

                if (property.getValue() == null) {
                    mapRval.setObject(property.getName(), null);
                } else if (property.getType().equals(String.class.getName())) {
                    mapRval.setString(property.getName(), property.getValue());
                } else if (property.getType().equals(Long.class.getName())) {
                    mapRval.setLong(property.getName(), Long.parseLong(property.getValue()));
                } else if (property.getType().equals(Double.class.getName())) {
                    mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue()));
                } else if (property.getType().equals(Boolean.class.getName())) {
                    mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue()));
                } else if (property.getType().equals(Character.class.getName())) {
                    mapRval.setChar(property.getName(), property.getValue().charAt(0));
                } else if (property.getType().equals(Short.class.getName())) {
                    mapRval.setShort(property.getName(), Short.parseShort(property.getValue()));
                } else if (property.getType().equals(Integer.class.getName())) {
                    mapRval.setInt(property.getName(), Integer.parseInt(property.getValue()));
                }
            }
        } else if (message instanceof XMLBytesMessage) {
            rval = hermes.createBytesMessage();

            XMLBytesMessage bytesMessage = (XMLBytesMessage) message;
            BytesMessage bytesRval = (BytesMessage) rval;

            bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes()));
        } else if (message instanceof XMLObjectMessage) {
            rval = hermes.createObjectMessage();

            XMLObjectMessage objectMessage = (XMLObjectMessage) message;
            ObjectMessage objectRval = (ObjectMessage) rval;
            ByteArrayInputStream bistream = new ByteArrayInputStream(
                    base64EncoderTL.get().decode(objectMessage.getObject().getBytes()));

            ObjectInputStream oistream = new ObjectInputStream(bistream);

            objectRval.setObject((Serializable) oistream.readObject());
        }

        //
        // JMS Header properties

        try {
            rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
        } catch (JMSException ex) {
            log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": "
                    + ex.getMessage());
        }

        try {
            rval.setJMSMessageID(message.getJMSMessageID());
        } catch (JMSException ex) {
            log.error("unable to set JMSMessageID: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSExpiration() != null) {
                rval.setJMSExpiration(message.getJMSExpiration());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSExpiration: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSPriority() != null) {
                rval.setJMSPriority(message.getJMSPriority());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSPriority: " + ex.getMessage(), ex);
        }

        try {
            if (message.getJMSTimestamp() != null) {
                rval.setJMSTimestamp(message.getJMSTimestamp());
            }
        } catch (JMSException ex) {
            log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex);
        }

        if (message.getJMSCorrelationID() != null) {
            rval.setJMSCorrelationID(message.getJMSCorrelationID());
        }

        if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) {
            rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(),
                    Domain.getDomain(message.getJMSReplyToDomain())));
        }

        if (message.getJMSType() != null) {
            rval.setJMSType(message.getJMSType());
        }

        if (message.getJMSDestination() != null) {
            if (message.isFromQueue()) {
                rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE));
            } else {
                rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC));
            }
        }

        for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) {
            Property property = (Property) iter.next();

            if (property.getValue() == null) {
                rval.setObjectProperty(property.getName(), null);
            } else if (property.getType().equals(String.class.getName())) {
                rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue()));
            } else if (property.getType().equals(Long.class.getName())) {
                rval.setLongProperty(property.getName(), Long.parseLong(property.getValue()));
            } else if (property.getType().equals(Double.class.getName())) {
                rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue()));
            } else if (property.getType().equals(Boolean.class.getName())) {
                rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue()));
            } else if (property.getType().equals(Short.class.getName())) {
                rval.setShortProperty(property.getName(), Short.parseShort(property.getValue()));
            } else if (property.getType().equals(Integer.class.getName())) {
                rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue()));
            }
        }

        return rval;
    } catch (NamingException e) {
        throw new HermesException(e);
    }

}

From source file:nl.nn.adapterframework.jms.JmsSender.java

/**
 * sets the JMS message properties as descriped in the msgProperties arraylist
 * @param msg//from w  w w  . j a v  a2 s. c  o  m
 * @param msgProperties
 * @throws JMSException
 */
private void setProperties(Message msg, ParameterValueList msgProperties) throws JMSException {
    for (int i = 0; i < msgProperties.size(); i++) {
        ParameterValue property = msgProperties.getParameterValue(i);
        String type = property.getDefinition().getType();
        String name = property.getDefinition().getName();

        if (!isSoap() || !name.equals(getSoapHeaderParam())) {

            if (log.isDebugEnabled()) {
                log.debug(getLogPrefix() + "setting [" + type + "] property from param [" + name
                        + "] to value [" + property.getValue() + "]");
            }

            if ("boolean".equalsIgnoreCase(type))
                msg.setBooleanProperty(name, property.asBooleanValue(false));
            else if ("byte".equalsIgnoreCase(type))
                msg.setByteProperty(name, property.asByteValue((byte) 0));
            else if ("double".equalsIgnoreCase(type))
                msg.setDoubleProperty(name, property.asDoubleValue(0));
            else if ("float".equalsIgnoreCase(type))
                msg.setFloatProperty(name, property.asFloatValue(0));
            else if ("int".equalsIgnoreCase(type))
                msg.setIntProperty(name, property.asIntegerValue(0));
            else if ("long".equalsIgnoreCase(type))
                msg.setLongProperty(name, property.asLongValue(0L));
            else if ("short".equalsIgnoreCase(type))
                msg.setShortProperty(name, property.asShortValue((short) 0));
            else if ("string".equalsIgnoreCase(type))
                msg.setStringProperty(name, property.asStringValue(""));
            else // if ("object".equalsIgnoreCase(type))
                msg.setObjectProperty(name, property.getValue());
        }
    }
}

From source file:org.apache.axis2.transport.jms.JMSUtils.java

/**
 * Set transport headers from the axis message context, into the JMS message
 *
 * @param msgContext the axis message context
 * @param message the JMS Message/*from   ww  w .j  a va2 s .  co  m*/
 * @throws JMSException on exception
 */
public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException {

    Map<?, ?> headerMap = (Map<?, ?>) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);

    if (headerMap == null) {
        return;
    }

    for (Object headerName : headerMap.keySet()) {

        String name = (String) headerName;

        if (name.startsWith(JMSConstants.JMSX_PREFIX)
                && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) {
            continue;
        }

        if (JMSConstants.JMS_COORELATION_ID.equals(name)) {
            message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID));
        } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) {
            Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE);
            if (o instanceof Integer) {
                message.setJMSDeliveryMode((Integer) o);
            } else if (o instanceof String) {
                try {
                    message.setJMSDeliveryMode(Integer.parseInt((String) o));
                } catch (NumberFormatException nfe) {
                    log.warn("Invalid delivery mode ignored : " + o, nfe);
                }
            } else {
                log.warn("Invalid delivery mode ignored : " + o);
            }

        } else if (JMSConstants.JMS_EXPIRATION.equals(name)) {
            message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION)));
        } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) {
            message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID));
        } else if (JMSConstants.JMS_PRIORITY.equals(name)) {
            message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY)));
        } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) {
            message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP)));
        } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) {
            message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE));

        } else {
            Object value = headerMap.get(name);
            if (value instanceof String) {
                message.setStringProperty(name, (String) value);
            } else if (value instanceof Boolean) {
                message.setBooleanProperty(name, (Boolean) value);
            } else if (value instanceof Integer) {
                message.setIntProperty(name, (Integer) value);
            } else if (value instanceof Long) {
                message.setLongProperty(name, (Long) value);
            } else if (value instanceof Double) {
                message.setDoubleProperty(name, (Double) value);
            } else if (value instanceof Float) {
                message.setFloatProperty(name, (Float) value);
            }
        }
    }
}

From source file:org.apache.camel.component.jms.JmsBinding.java

public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message in,
        String headerName, Object headerValue) throws JMSException {
    if (isStandardJMSHeader(headerName)) {
        if (headerName.equals("JMSCorrelationID")) {
            jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
        } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
            if (headerValue instanceof String) {
                // if the value is a String we must normalize it first
                headerValue = normalizeDestinationName((String) headerValue);
            }//from   www .ja va  2s  .c  o m
            jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue));
        } else if (headerName.equals("JMSType")) {
            jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
        } else if (headerName.equals("JMSPriority")) {
            jmsMessage.setJMSPriority(ExchangeHelper.convertToType(exchange, Integer.class, headerValue));
        } else if (headerName.equals("JMSDeliveryMode")) {
            Integer deliveryMode = ExchangeHelper.convertToType(exchange, Integer.class, headerValue);
            jmsMessage.setJMSDeliveryMode(deliveryMode);
            jmsMessage.setIntProperty(JmsConstants.JMS_DELIVERY_MODE, deliveryMode);
        } else if (headerName.equals("JMSExpiration")) {
            jmsMessage.setJMSExpiration(ExchangeHelper.convertToType(exchange, Long.class, headerValue));
        } else if (LOG.isTraceEnabled()) {
            // The following properties are set by the MessageProducer:
            // JMSDestination
            // The following are set on the underlying JMS provider:
            // JMSMessageID, JMSTimestamp, JMSRedelivered
            // log at trace level to not spam log
            LOG.trace("Ignoring JMS header: " + headerName + " with value: " + headerValue);
        }
    } else if (shouldOutputHeader(in, headerName, headerValue, exchange)) {
        // only primitive headers and strings is allowed as properties
        // see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html
        Object value = getValidJMSHeaderValue(headerName, headerValue);
        if (value != null) {
            // must encode to safe JMS header name before setting property on jmsMessage
            String key = jmsKeyFormatStrategy.encodeKey(headerName);
            // set the property
            JmsMessageHelper.setProperty(jmsMessage, key, value);
        } else if (LOG.isDebugEnabled()) {
            // okay the value is not a primitive or string so we cannot sent it over the wire
            LOG.debug("Ignoring non primitive header: " + headerName + " of class: "
                    + headerValue.getClass().getName() + " with value: " + headerValue);
        }
    }
}