Example usage for javax.jms Message getStringProperty

List of usage examples for javax.jms Message getStringProperty

Introduction

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

Prototype


String getStringProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the String property with the specified name.

Usage

From source file:fr.ortolang.diffusion.OrtolangEvent.java

@SuppressWarnings("unchecked")
public void fromJMSMessage(Message message) throws OrtolangException {
    try {//from   w ww. j a  v a  2s.  c  o m
        setFormattedDate(message.getStringProperty(OrtolangEvent.DATE));
        setThrowedBy(message.getStringProperty(OrtolangEvent.THROWED_BY));
        setFromObject(message.getStringProperty(OrtolangEvent.FROM_OBJECT));
        setObjectType(message.getStringProperty(OrtolangEvent.OBJECT_TYPE));
        setType(message.getStringProperty(OrtolangEvent.TYPE));
        String serializedArgs = message.getStringProperty(OrtolangEvent.ARGUMENTS);
        if (serializedArgs != null) {
            ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(serializedArgs));
            try {
                ObjectInputStream ois = new ObjectInputStream(bais);
                Map<String, String> args = (Map<String, String>) ois.readObject();
                setArguments(args);
            } catch (IOException | ClassNotFoundException e) {
                LOGGER.log(Level.SEVERE, "Unable to deserialize arguments", e);
            }
        }
    } catch (JMSException e) {
        throw new OrtolangException("unable to build event from jms message", e);
    }
}

From source file:org.apache.servicemix.jms.JmsProviderEndpointTest.java

public void testSendWithoutProperties() throws Exception {
    container.activateComponent(createEndpoint(false), "servicemix-jms");

    InOnly me = client.createInOnlyExchange();
    NormalizedMessage inMessage = me.getInMessage();
    inMessage.setProperty(MSG_PROPERTY, "Test-Value");
    inMessage.setProperty(MSG_PROPERTY_BLACKLISTED, "Unwanted value");
    inMessage.setContent(new StringSource("<hello>world</hello>"));
    me.setService(new QName("jms"));
    client.sendSync(me);//w  w w  .ja v a  2  s  .co  m
    assertEquals(ExchangeStatus.DONE, me.getStatus());

    Message msg = jmsTemplate.receive("destination");
    assertNull("Found not expected property", msg.getStringProperty(MSG_PROPERTY));
    assertNull("Found blacklisted property", msg.getStringProperty(MSG_PROPERTY_BLACKLISTED));
    assertNotNull(msg);
}

From source file:org.apache.servicemix.jms.JmsProviderEndpointTest.java

public void testSendSimple() throws Exception {
    container.activateComponent(createEndpoint(), "servicemix-jms");

    InOnly me = client.createInOnlyExchange();
    NormalizedMessage inMessage = me.getInMessage();
    inMessage.setProperty(MSG_PROPERTY, "Test-Value");
    inMessage.setProperty(MSG_PROPERTY_BLACKLISTED, "Unwanted value");
    inMessage.setContent(new StringSource("<hello>world</hello>"));
    me.setService(new QName("jms"));
    client.sendSync(me);//from   w w w  .j ava 2 s.  com
    assertEquals(ExchangeStatus.DONE, me.getStatus());

    Message msg = jmsTemplate.receive("destination");
    assertNotNull("Expected property not found", msg.getStringProperty(MSG_PROPERTY));
    assertNull("Found blacklisted property", msg.getStringProperty(MSG_PROPERTY_BLACKLISTED));
    assertNotNull(msg);
}

From source file:de.taimos.dvalin.interconnect.core.spring.DaemonEvents.java

@Override
public void onMessage(final Message message) {
    final String icoClass;
    try {//from   w  ww.j  a  va  2 s .c  o  m
        icoClass = message.getStringProperty(InterconnectConnector.HEADER_ICO_CLASS); // can be null
    } catch (final Exception e) {
        this.logger.error("Exception", e);
        return;
    }
    try {
        if (message instanceof TextMessage) {
            final TextMessage textMessage = (TextMessage) message;
            this.logger.debug("TextMessage received: {}", textMessage.getText());
            if (MessageConnector.isMessageSecure(textMessage)) {
                MessageConnector.decryptMessage(textMessage);
            }
            final InterconnectObject ico;
            try {
                ico = InterconnectMapper.fromJson(textMessage.getText());
            } catch (final Exception e) {
                this.logEventError(icoClass, "Event not supported", e);
                return;
            }
            if (ico instanceof IVO) {
                this.emit((IVO) ico);
            } else {
                this.logEventError(icoClass, "Event not an IVO", null);
            }
        } else {
            this.logEventError(icoClass, "Event not a TextMessage", null);
        }
    } catch (final Exception e) {
        // we are in non transactional wonderland so we catch the exception which leads to a lost event.
        this.logEventError(icoClass, "Exception", e);
    }
}

From source file:com.npower.dm.multiplexor.Multiplexor.java

public void onMessage(Message jmsMsg) {
    try {/*from   w  w w  .ja  v  a 2  s.c  om*/
        String from = jmsMsg.getStringProperty(JmsSmsReceiverImpl.PROPERTY_DEVICE_MSISDN_NAME);
        String to = jmsMsg.getStringProperty(JmsSmsReceiverImpl.PROPERTY_DEVICE_SERVICE_CODE);
        String msgText = jmsMsg.getStringProperty(JmsSmsReceiverImpl.PROPERTY_TEXT_MESSAGE);
        byte[] msgBytes = HelperUtil
                .hexStringToBytes(jmsMsg.getStringProperty(JmsSmsReceiverImpl.PROPERTY_RAW_MESSAGE));
        if (log.isDebugEnabled()) {
            log.debug("Incoming msg, [from: " + from + ", to: " + to + ", text=" + msgText + "]");
        }
        this.dispatch(from, to, msgBytes, msgText);
    } catch (JMSException e) {
        log.error("Failure to dispatch a incoming message.", e);
    } catch (TargetQueueNotFoundException e) {
        log.error(e.getMessage());
        log.info("Could not found target queue, message has been discarded!");
    } catch (Exception e) {
        log.error("Failure to dispatch a incoming message.", e);
    }
}

From source file:org.kuali.student.enrollment.courseoffering.service.DequeuerCallbackListener.java

@Override
@Transactional// www . jav  a2  s  .  c  o m
public void onMessage(Message message) {
    try {
        String methodName = message.getStringProperty(EnqueuerCallbackListener.EVENT_QUEUE_MESSAGE_METHOD_NAME);
        String offeringId = message.getStringProperty(EnqueuerCallbackListener.EVENT_QUEUE_MESSAGE_OFFERING_ID);

        if ("updateActivityOffering".equals(methodName)) {
            Selector target = new Selector(SubscriptionActionEnum.UPDATE, null);
            target.offeringId = offeringId;
            this.fireSelectedCallbacks(target, offeringId);
        } else {
            log.warn(methodName + " not supported");
        }
    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.atlantbh.jmeter.plugins.jmstools.BinaryMessageConverter.java

@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {

    Enumeration<String> names = message.getPropertyNames();
    messageProperties = new HashMap<String, String>();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        messageProperties.put(name, message.getStringProperty(name));
    }//from   ww  w .j a  va  2  s.c o m

    BytesMessage bm = (BytesMessage) message;
    byte[] transfer = new byte[(int) bm.getBodyLength()];
    bm.readBytes(transfer);
    return new String(transfer);
}

From source file:org.hawkular.apm.server.jms.RetryCapableMDB.java

@Override
public void onMessage(Message message) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Message received=" + message);
    }/*w w  w  .  ja  v  a  2  s. c  o  m*/

    try {
        String tenantId = message.getStringProperty("tenant");

        int retryCount;

        if (message.propertyExists("retryCount")) {
            retryCount = message.getIntProperty("retryCount");
        } else {
            retryCount = maxRetryCount;
        }

        String data = ((TextMessage) message).getText();

        List<S> items = mapper.readValue(data, getTypeReference());

        process(tenantId, items, retryCount);

    } catch (Exception e) {
        if (processor.isReportRetryExpirationAsWarning()) {
            serverMsgLogger.warnMaxRetryReached(e);
        } else if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST, "Maximum retry reached. Last exception to occur ....", e);
        }
    }
}

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

public void testMoveMetadata_AdaptrisMessageToJmsMessage_RemoveAll() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    trans.setMetadataFilter(new RemoveAllMetadataFilter());
    try {//www .j  av a 2 s .  c o  m
        broker.start();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();

        addMetadata(msg);
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);

        Message jmsMsg = trans.translate(msg);
        assertNull(jmsMsg.getStringProperty(STRING_METADATA));
        assertNull(jmsMsg.getStringProperty(BOOLEAN_METADATA));
        assertNull(jmsMsg.getStringProperty(INTEGER_METADATA));
    } finally {
        stop(trans);
        broker.destroy();

    }
}

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

public void testMoveMetadata_AdaptrisMessageToJmsMessage_WithFilter() throws Exception {

    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    RegexMetadataFilter regexp = new RegexMetadataFilter();
    regexp.addExcludePattern("IntegerMetadataKey");
    trans.setMetadataFilter(regexp);//  w ww.  ja  v  a  2s.c om
    try {
        broker.start();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);
        Message jmsMsg = trans.translate(msg);
        assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
        assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
        assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(),
                jmsMsg.getBooleanProperty(BOOLEAN_METADATA));
        assertNull(jmsMsg.getStringProperty(INTEGER_METADATA));
    } finally {
        stop(trans);
        broker.destroy();
    }
}