Example usage for javax.jms Message setBooleanProperty

List of usage examples for javax.jms Message setBooleanProperty

Introduction

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

Prototype


void setBooleanProperty(String name, boolean value) throws JMSException;

Source Link

Document

Sets a boolean 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: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   ww  w  .  j  a va2 s  .  co m
            message.setObjectProperty(name, v);
        }
    }
    return message;
}

From source file:hermes.impl.DefaultXMLHelper.java

public Message createMessage(MessageFactory hermes, XMLMessage message)
        throws JMSException, IOException, ClassNotFoundException, DecoderException {
    try {/*from w ww .  j a  v a 2s . co m*/
        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.knaw.huygens.timbuctoo.messages.Action.java

public Message createMessage(Session session) throws JMSException {
    Message message = session.createMessage();

    message.setStringProperty(PROP_ACTION, actionType.getStringRepresentation());

    message.setStringProperty(PROP_ENTITY_TYPE, TypeNames.getInternalName(type));
    message.setBooleanProperty(PROP_FOR_MULTI_ENTITIES, forMultiEntities);
    if (!forMultiEntities) {
        message.setStringProperty(PROP_ENTITY_ID, id);
    }//from w w  w  .  ja  v a2  s . c  om

    return message;
}

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

/**
 * sets the JMS message properties as descriped in the msgProperties arraylist
 * @param msg//from   w  ww  .  ja  v a 2s.  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. java 2 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.james.queue.jms.JMSMailQueue.java

@Override
public long flush() throws MailQueueException {
    boolean first = true;
    long count = 0;
    try (Session session = connection.createSession(true, Session.SESSION_TRANSACTED)) {
        Queue queue = session.createQueue(queueName);
        try (MessageConsumer consumer = session.createConsumer(queue)) {
            try (MessageProducer producer = session.createProducer(queue)) {

                Message message = null;//from ww  w  .java2  s. co  m
                while (first || message != null) {
                    if (first) {
                        // give the consumer 2000 ms to receive messages
                        message = consumer.receive(2000);
                    } else {
                        message = consumer.receiveNoWait();
                    }
                    first = false;

                    if (message != null) {
                        Message m = copy(session, message);
                        m.setBooleanProperty(FORCE_DELIVERY, true);
                        producer.send(m, message.getJMSDeliveryMode(), message.getJMSPriority(),
                                message.getJMSExpiration());
                        count++;
                    }
                }
                session.commit();
                return count;
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unable to flush mail", e);
        throw new MailQueueException("Unable to get size of queue " + queueName, e);
    }
}

From source file:org.apache.qpid.disttest.client.MessageProvider.java

protected void setCustomProperty(Message message, String propertyName, Object propertyValue)
        throws JMSException {
    if (propertyValue instanceof Integer) {
        message.setIntProperty(propertyName, ((Integer) propertyValue).intValue());
    } else if (propertyValue instanceof Long) {
        message.setLongProperty(propertyName, ((Long) propertyValue).longValue());
    } else if (propertyValue instanceof Boolean) {
        message.setBooleanProperty(propertyName, ((Boolean) propertyValue).booleanValue());
    } else if (propertyValue instanceof Byte) {
        message.setByteProperty(propertyName, ((Byte) propertyValue).byteValue());
    } else if (propertyValue instanceof Double) {
        message.setDoubleProperty(propertyName, ((Double) propertyValue).doubleValue());
    } else if (propertyValue instanceof Float) {
        message.setFloatProperty(propertyName, ((Float) propertyValue).floatValue());
    } else if (propertyValue instanceof Short) {
        message.setShortProperty(propertyName, ((Short) propertyValue).shortValue());
    } else if (propertyValue instanceof String) {
        message.setStringProperty(propertyName, (String) propertyValue);
    } else {//from  w  ww  .j  a  va2s  .  c  om
        message.setObjectProperty(propertyName, propertyValue);
    }
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

private void setJmsMessageProperties(Message message, MessageContext synCtx) {
    Set<String> properties = synCtx.getPropertyKeySet();
    for (String prop : properties) {
        if (prop.startsWith(JMS_MSG_P)) {
            Object value = synCtx.getProperty(prop);
            String key = prop.substring(JMS_MSG_P.length());
            try {
                if (value instanceof String) {
                    message.setStringProperty(key, (String) value);
                } else if (value instanceof Long) {
                    message.setLongProperty(key, (Long) value);
                } else if (value instanceof Integer) {
                    message.setIntProperty(key, (Integer) value);
                } else if (value instanceof Boolean) {
                    message.setBooleanProperty(key, (Boolean) value);
                } else if (value instanceof Double) {
                    message.setDoubleProperty(key, (Double) value);
                } else if (value instanceof Float) {
                    message.setFloatProperty(key, (Float) value);
                } else if (value instanceof Short) {
                    message.setShortProperty(key, (Short) value);
                }//from ww  w .  j ava  2  s  . c  o m
            } catch (JMSException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not save Message property: " + e.getLocalizedMessage());
                }
            }
        }
    }
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

private void setTransportHeaders(Message message, MessageContext synCtx) {
    //Set transport headers to the message
    Map<?, ?> headerMap = (Map<?, ?>) ((Axis2MessageContext) synCtx).getAxis2MessageContext()
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    if (headerMap != null) {
        for (Object headerName : headerMap.keySet()) {
            String name = (String) headerName;
            Object value = headerMap.get(name);
            try {
                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);
                }/*  ww w. jav  a2s. co  m*/
            } catch (JMSException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not save Message property: " + ex.getLocalizedMessage());
                }
            }
        }
    }
}