Example usage for javax.jms TextMessage getText

List of usage examples for javax.jms TextMessage getText

Introduction

In this page you can find the example usage for javax.jms TextMessage getText.

Prototype


String getText() throws JMSException;

Source Link

Document

Gets the string containing this message's data.

Usage

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param topicName Topic name/* ww  w .  j a v a2s.  co m*/
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param maxSize   Max messages to receive
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Interconnect Object
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static List<InterconnectObject> receiveBulkFromTopic(final String topicName, final String selector,
        final int maxSize, final long timeout, final boolean secure)
        throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(topicName, "Topic name");
    final List<TextMessage> responses = MessageConnector.receiveBulkFromTopic(topicName, selector, maxSize,
            timeout, secure);
    final List<InterconnectObject> icos = new ArrayList<>(responses.size());
    try {
        for (final TextMessage response : responses) {
            icos.add(InterconnectMapper.fromJson(response.getText()));
        }
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
    return icos;
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param queueName Queue name/*www  . j  av a2  s .co  m*/
 * @param maxSize   Max messages to receive
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Response
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static List<Response> receiveBulkFromQueueEnhanced(final String queueName, final String selector,
        final int maxSize, final long timeout, final boolean secure)
        throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(queueName, "Queue name");
    final List<TextMessage> responses = MessageConnector.receiveBulkFromQueue(queueName, selector, maxSize,
            timeout, secure);
    final List<Response> enhanceds = new ArrayList<>(responses.size());
    try {
        for (final TextMessage response : responses) {
            enhanceds.add(new Response(InterconnectMapper.fromJson(response.getText()), response));
        }
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
    return enhanceds;
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param topicName Topic name/*from   w w  w.  j a v  a 2s.  c  o  m*/
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param maxSize   Max messages to receive
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Response
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static List<Response> receiveBulkFromTopicEnhanced(final String topicName, final String selector,
        final int maxSize, final long timeout, final boolean secure)
        throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(topicName, "Topic name");
    final List<TextMessage> responses = MessageConnector.receiveBulkFromTopic(topicName, selector, maxSize,
            timeout, secure);
    final List<Response> enhanceds = new ArrayList<>(responses.size());
    try {
        for (final TextMessage response : responses) {
            enhanceds.add(new Response(InterconnectMapper.fromJson(response.getText()), response));
        }
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
    return enhanceds;
}

From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java

public static String getMessageBody(Message message) {
    try {/*from ww w  .  j  av a  2 s.  co  m*/
        if (message instanceof MapMessage) {
            MapMessage mm = (MapMessage) message;
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode root = mapper.createObjectNode();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mm.getMapNames();
            while (e.hasMoreElements()) {
                String field = e.nextElement();
                root.set(field, mapper.convertValue(mm.getObject(field), JsonNode.class));
            }
            return mapper.writer().writeValueAsString(root);
        } else if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            return tm.getText();
        } else if (message instanceof BytesMessage) {
            BytesMessage bm = (BytesMessage) message;
            byte[] bytes = new byte[(int) bm.getBodyLength()];
            if (bm.readBytes(bytes) == bm.getBodyLength()) {
                return new String(bytes);
            }
        } else {
            log.log(Level.SEVERE, "Unsupported message type:\n" + formatMessage(message));
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unhandled exception retrieving message body:\n" + formatMessage(message), e);
    }

    return "";
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param uuid          Universally unique identifier of the request
 * @param queueName     Queue name//from   ww w . j  a v  a  2 s .co m
 * @param requestICO    Request Interconnect Object
 * @param customHeaders Headers
 * @return Response Interconnect Object
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static InterconnectObject request(final UUID uuid, final String queueName,
        final InterconnectObject requestICO, final Map<String, Object> customHeaders)
        throws InfrastructureException, IOException {
    Preconditions.checkNotNull(uuid, "Universally unique identifier of the request");
    Preconditions.checkNotNull(queueName, "Queue name");
    Preconditions.checkNotNull(requestICO, "Request Interconnect Object");
    final String body = InterconnectMapper.toJson(requestICO);
    final Map<String, Object> headers;
    if (customHeaders == null) {
        headers = new HashMap<>(2);
    } else {
        headers = new HashMap<>(customHeaders);
    }
    headers.put(InterconnectConnector.HEADER_REQUEST_UUID, uuid.toString());
    headers.put(InterconnectConnector.HEADER_ICO_CLASS, requestICO.getClass().getName());
    final TextMessage response = MessageConnector.request(queueName, body, headers);
    try {
        return InterconnectMapper.fromJson(response.getText());
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param queueName Queue name/* w  w w .ja va2 s.  c  o  m*/
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Interconnect Object
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static InterconnectObject receiveFromQueue(final String queueName, final String selector,
        final long timeout, final boolean secure) throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(queueName, "Queue name");
    final TextMessage response = MessageConnector.receiveFromQueue(queueName, selector, timeout, secure);
    try {
        return InterconnectMapper.fromJson(response.getText());
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param topicName Topic name//from  w ww  .  java2  s  . co m
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Interconnect Object
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static InterconnectObject receiveFromTopic(final String topicName, final String selector,
        final long timeout, final boolean secure) throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(topicName, "Topic name");
    final TextMessage response = MessageConnector.receiveFromTopic(topicName, selector, timeout, secure);
    try {
        return InterconnectMapper.fromJson(response.getText());
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param queueName Queue name//from   ww w  . ja  va2  s  .  co m
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Response
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static Response receiveFromQueueEnhanced(final String queueName, final String selector,
        final long timeout, final boolean secure) throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(queueName, "Queue name");
    final TextMessage response = MessageConnector.receiveFromQueue(queueName, selector, timeout, secure);
    try {
        return new Response(InterconnectMapper.fromJson(response.getText()), response);
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param topicName Topic name/*from  w  ww  .j  av a2  s. c  om*/
 * @param selector  JMS selector (or null or empty string := no selector)
 * @param timeout   Timeout in milliseconds to wait for an Interconnect Object
 * @param secure    Enable secure transport?
 * @return Response
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static Response receiveFromTopicEnhanced(final String topicName, final String selector,
        final long timeout, final boolean secure) throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(topicName, "Topic name");
    final TextMessage response = MessageConnector.receiveFromTopic(topicName, selector, timeout, secure);
    try {
        return new Response(InterconnectMapper.fromJson(response.getText()), response);
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}

From source file:de.taimos.dvalin.interconnect.core.InterconnectConnector.java

/**
 * @param uuid           Universally unique identifier of the request
 * @param queueName      Queue name//  w w w  . java 2 s.  com
 * @param requestICO     Request Interconnect Object
 * @param customHeaders  Headers
 * @param secure         Enable secure transport?
 * @param receiveTimeout Request timeout (in milliseconds)
 * @param sendTimeout    Send timeout (in milliseconds)
 * @param priority       JMS priority
 * @return Response Interconnect Object
 * @throws InfrastructureException If an infrastructure error occurs
 * @throws CryptoException         If the message could not be encrypted
 * @throws JsonGenerationException if the JSON data could not be generated
 * @throws JsonMappingException    if the object could not be mapped to a JSON string
 * @throws IOException             if an I/O related problem occurred
 */
public static InterconnectObject request(final UUID uuid, final String queueName,
        final InterconnectObject requestICO, final Map<String, Object> customHeaders, final boolean secure,
        final long receiveTimeout, final long sendTimeout, final int priority)
        throws InfrastructureException, CryptoException, IOException {
    Preconditions.checkNotNull(uuid, "Universally unique identifier of the request");
    Preconditions.checkNotNull(queueName, "Queue name");
    Preconditions.checkNotNull(requestICO, "Request Interconnect Object");
    final String body = InterconnectMapper.toJson(requestICO);
    final Map<String, Object> headers;
    if (customHeaders == null) {
        headers = new HashMap<>(2);
    } else {
        headers = new HashMap<>(customHeaders);
    }
    headers.put(InterconnectConnector.HEADER_REQUEST_UUID, uuid.toString());
    headers.put(InterconnectConnector.HEADER_ICO_CLASS, requestICO.getClass().getName());
    final TextMessage response = MessageConnector.request(queueName, body, headers, secure, receiveTimeout,
            sendTimeout, priority);
    try {
        return InterconnectMapper.fromJson(response.getText());
    } catch (final JMSException e) {
        throw new InfrastructureException("Failed to read message");
    }
}