Java Code Examples for javax.jms.Message.getStringProperty()

The following are Jave code examples for showing how to use getStringProperty() of the javax.jms.Message class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: oneops   File: JMSConsumer.java   Source Code and License Vote up 7 votes
private void addData(Message message, String text) throws JMSException {
    MessageData data = new MessageData();
    data.setPayload(text);
    Map<String, String> headers = new HashMap<>();
    Enumeration<String> names = message.getPropertyNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = message.getStringProperty(name);
        headers.put(name, value);
    }
    data.setHeaders(headers);
    messages.add(data);
}
 
Example 2
Project: OperatieBRP   File: AspectForMDC.java   Source Code and License Vote up 6 votes
/**
 * Het advies uit te voeren op de pointcut.
 * @param message parameter van de methode
 * @throws JMSException als iets in de pointcut fout gaat
 */
@Before("nl.bzk.algemeenbrp.util.common.logging.AspectForMDC.jmsBerichtLezer() && args(message)")
public void voegMDCInformatieToe(Message message) throws JMSException {
    if (message.getStringProperty(MDC.JMS_VERWERKING_CODE) != null) {
        org.slf4j.MDC.put(VERWERKING_CODE, message.getStringProperty(MDC.JMS_VERWERKING_CODE));
    } else {
        org.slf4j.MDC.put(VERWERKING_CODE, UUID.randomUUID().toString());
    }
    org.slf4j.MDC.put(JMS_MESSAGE_ID, message.getJMSMessageID());
    if (message.getStringProperty(BERICHT_REFERENTIE) != null) {
        org.slf4j.MDC.put(SYNC_BERICHT_REFERENTIE, message.getStringProperty(BERICHT_REFERENTIE));
    } else {
        org.slf4j.MDC.remove(SYNC_BERICHT_REFERENTIE);
    }
    if (message.getStringProperty(CORRELATIE_REFERENTIE) != null) {
        org.slf4j.MDC.put(SYNC_CORRELATIE_REFERENTIE, message.getStringProperty(CORRELATIE_REFERENTIE));
    } else {
        org.slf4j.MDC.remove(SYNC_CORRELATIE_REFERENTIE);
    }
}
 
Example 3
Project: oneops   File: JMSConsumer.java   Source Code and License Vote up 5 votes
private void addData(Message message, String text) throws JMSException {
	MessageData data = new MessageData();
	data.setPayload(text);
	Map<String, String> headers = new HashMap<String, String>();
	Enumeration<String> names = message.getPropertyNames();
	while (names.hasMoreElements()) {
		String name = names.nextElement();
		String value = message.getStringProperty(name);
		headers.put(name, value);
	}
	data.setHeaders(headers);
	messages.add(data);
}
 
Example 4
Project: OperatieBRP   File: VrijBerichtMessageListener.java   Source Code and License Vote up 5 votes
private String leesBerichtReferentie(final Message message) {
    try {
        return message.getStringProperty(BERICHT_REFERENTIE);
    } catch (final JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
    }
}
 
Example 5
Project: OperatieBRP   File: AfnemerIndicatieMessageListener.java   Source Code and License Vote up 5 votes
private String leesBerichtReferentie(final Message message) {
    try {
        return message.getStringProperty(BERICHT_REFERENTIE);
    } catch (final JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
    }
}
 
Example 6
Project: OperatieBRP   File: GbaBijhoudingsMessageListener.java   Source Code and License Vote up 5 votes
private static String leesBerichtReferentie(final Message message) {
    try {
        return message.getStringProperty(BERICHT_REFERENTIE);
    } catch (final JMSException e) {
        throw new VerzendOntvangstException("Kan berichtreferentie niet lezen", e);
    }
}
 
Example 7
Project: kalinka   File: MqttSparkClusterJmsMessagePublisher.java   Source Code and License Vote up 5 votes
@Override
public void publish(final Message message, final KafkaTemplate<String, byte[]> kafkaTemplate) {

	try {
		final byte[] effectivePayload = JmsUtil.getPayload((BytesMessage) message);
		final String sourceTopic = message.getStringProperty("JMSDestination");
		final String destTopic = this.getDestTopic(sourceTopic);
		kafkaTemplate.send(destTopic, effectivePayload);
	} catch (final Throwable t) {
		LOG.error("Exception occured", t);
	}
}
 
Example 8
Project: kalinka   File: JmsMessageListener.java   Source Code and License Vote up 5 votes
@Override
public void onMessage(final Message msg) {

	try {
		final String destination = msg.getStringProperty("JMSDestination");
		final IMessagePublisher<Message, K, V> publisher = this.messagePublisherProvider.getPublisher(msg.getStringProperty("JMSDestination"));
		if (publisher == null) {
			LOG.warn("No publisher found for destination={}", destination);
			return;
		}
		publisher.publish(msg, this.kafkaTemplate);
	} catch (final Throwable t) {
		throw new RuntimeException(t);
	}
}
 
Example 9
Project: jaffa-framework   File: JmsBrowser.java   Source Code and License Vote up 5 votes
/** Returns true if the input Message was created by the currently authenticated user.
 * @param message the JMS Message.
 * @return true if the input Message was created by the currently authenticated user.
 */
private static boolean isMessageOwner(Message message) throws JMSException {
    String currentUserId = SecurityManager.getPrincipal() != null ? SecurityManager.getPrincipal().getName() : null;
    String createdBy = message.getStringProperty(HEADER_USER_ID);
    boolean result = currentUserId != null && currentUserId.equals(createdBy);
    if (!result && log.isDebugEnabled())
        log.debug(currentUserId + " is not owner of the message " + message.getJMSMessageID() + ", which was created by " + createdBy);
    return result;
}
 
Example 10
Project: jaffa-framework   File: MessageViewerTx.java   Source Code and License Vote up 5 votes
/** Returns the messageId to be used for retrieving the BusinessEventLogs for a Message.
 * @param input The criteria based on which an object will be retrieved.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The messageId.
 */
public String getMessageIdForBusinessEventLog(MessageViewerInDto input) throws FrameworkException, ApplicationExceptions{
    try{
        Message message = findMessage(input);
        return message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID) != null ? message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID) : message.getJMSMessageID();
    } catch(JMSException e) {
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, null, e);
    }
}
 
Example 11
Project: message-broker   File: DeadLetterChannelTest.java   Source Code and License Vote up 4 votes
@Parameters({ "broker-hostname", "broker-port", "admin-username", "admin-password" })
@Test
public void testDlcWithBasicRecover(String brokerHostname,
                                         String port,
                                         String adminUsername,
                                         String adminPassword) throws Exception {
    String queueName = "testDlcWithBasicRecover";
    String dlcQueueName = "amq.dlq";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .withQueue(dlcQueueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish message
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

    producer.send(producerSession.createTextMessage("Message for DLC test"));
    producerSession.close();

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    for (int iteration = 0; iteration < 6; iteration++) {
        Message message = consumer.receive(5000);
        Assert.assertNotNull(message, "Message was not received");
        subscriberSession.recover();
    }

    Connection dlcConsumerConnection = connectionFactory.createConnection();
    dlcConsumerConnection.start();
    Session dlcConsumerSession = dlcConsumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer dlcConsumer = dlcConsumerSession.createConsumer((Destination) initialContextForQueue.lookup(
            dlcQueueName));

    Message dlcMessage = dlcConsumer.receive(5000);
    Assert.assertNotNull(dlcMessage, "Dead lettered message was not received" + dlcMessage);
    String originQueue = dlcMessage.getStringProperty("x-origin-queue");
    Assert.assertEquals(originQueue, queueName, "Origin queue name did not match" + dlcMessage);
    String originExchange = dlcMessage.getStringProperty("x-origin-exchange");
    Assert.assertEquals(originExchange, "amq.direct", "Origin exchange name did not match" + dlcMessage);
    String originRoutingKey = dlcMessage.getStringProperty("x-origin-routing-key");
    Assert.assertEquals(originRoutingKey, queueName, "Origin routing key did not match" + dlcMessage);

    dlcConsumerConnection.close();
    connection.close();
}