Example usage for javax.jms Message getJMSType

List of usage examples for javax.jms Message getJMSType

Introduction

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

Prototype


String getJMSType() throws JMSException;

Source Link

Document

Gets the message type identifier supplied by the client when the message was sent.

Usage

From source file:com.egt.core.aplicacion.Bitacora.java

public static void traceMessage(Class clase, String metodo, Message message) throws JMSException {
    logTrace(Utils.getTraceMessageFormat(getCallingMethodStackTraceElementTrack(clase, metodo, 4),
            new Object[] { message.getJMSType(), message.getJMSMessageID(), message.getJMSCorrelationID(),
                    message.getJMSRedelivered() }));
}

From source file:org.osgp.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    try {//from w w  w. j  a v a2  s  .c o  m
        LOGGER.info("Received message of type: {}", message.getJMSType());

        final ObjectMessage objectMessage = (ObjectMessage) message;

        final MessageProcessor processor = this.dlmsRequestMessageProcessorMap
                .getMessageProcessor(objectMessage);

        processor.processMessage(objectMessage);

    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.SigningServerResponsesMessageListener.java

@Override
public void onMessage(final Message message) {
    try {/*  w w  w . j  a va  2  s  .  co  m*/
        LOGGER.info("Received message of type: {}", message.getJMSType());

        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final String correlationId = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final ResponseMessageResultType result = responseMessage == null ? null : responseMessage.getResult();

        // Check the result.
        if (result.equals(ResponseMessageResultType.NOT_OK)) {
            LOGGER.error("OslpEnvelope was not signed by signing-server. Unable to send request to device: {}",
                    deviceIdentification);
            this.oslpSigningService.handleError(deviceIdentification, responseMessage);
            return;
        }

        LOGGER.info("messageType: {}, deviceIdentification: {}, result: {}, correlationId: {}", messageType,
                deviceIdentification, result, correlationId);

        // Get the DTO object containing signed OslpEnvelope.
        final SignedOslpEnvelopeDto signedOslpEnvelopeDto = (SignedOslpEnvelopeDto) responseMessage
                .getDataObject();

        this.oslpSigningService.handleSignedOslpEnvelope(signedOslpEnvelopeDto, deviceIdentification);
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;/*from  ww  w  .j a v a 2  s .c  o  m*/

    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        final MessageProcessor processor = this.oslpRequestMessageProcessorMap
                .getMessageProcessor(objectMessage);
        processor.processMessage(objectMessage);
    } catch (final JMSException ex) {
        LOGGER.error("Unexpected JMSException during onMessage(Message)", ex);
        this.sendException(objectMessage, ex, "JMSException while processing message");
    } catch (final IllegalArgumentException e) {
        LOGGER.error("Unexpected IllegalArgumentException during onMessage(Message)", e);
        this.sendException(objectMessage, new NotSupportedException(ComponentType.PROTOCOL_OSLP, messageType),
                "Unsupported device function: " + messageType);
    }
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.DeviceRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;/*  w ww.  j a  v a  2s .  com*/

    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        final MessageProcessor processor = this.iec61850RequestMessageProcessorMap
                .getMessageProcessor(objectMessage);
        processor.processMessage(objectMessage);
    } catch (final JMSException ex) {
        LOGGER.error("Unexpected JMSException during onMessage(Message)", ex);
        this.sendException(objectMessage, ex, "JMSException while processing message");
    } catch (final IllegalArgumentException e) {
        LOGGER.error("Unexpected IllegalArgumentException during onMessage(Message)", e);
        this.sendException(objectMessage,
                new NotSupportedException(ComponentType.PROTOCOL_IEC61850, messageType),
                "Unsupported device function: " + messageType);
    }
}

From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java

public void testBug895() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    JmsConnection conn = null;//from  w  ww  .  j ava2 s  . c om
    try {
        activeMqBroker.start();
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);

        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();

        msg.addMetadata(JmsConstants.JMS_PRIORITY, "9");
        msg.addMetadata(JmsConstants.JMS_TYPE, "idaho");
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.setMoveJmsHeaders(true);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        start(trans);

        Message jmsMsg = trans.translate(msg);

        assertNotSame("JMS Priorities should be different", jmsMsg.getJMSPriority(), 9);
        assertEquals("JMSType should be equal", "idaho", jmsMsg.getJMSType());
    } finally {
        stop(trans);
        stop(conn);
        activeMqBroker.destroy();
    }

}

From source file:org.carewebframework.jms.GlobalEventDispatcher.java

/**
 * Process a dequeued message by forwarding it to the local event manager for local delivery. If
 * the message is a ping request, send the response.
 * //from  w  w  w. ja v a2 s. c o m
 * @param message Message to process.
 */
protected void processMessage(final Message message) {
    try {
        final String eventName = message.getJMSType();
        Object eventData;

        if (message instanceof ObjectMessage) {
            eventData = ((ObjectMessage) message).getObject();
        } else if (message instanceof TextMessage) {
            eventData = ((TextMessage) message).getText();
        } else {
            log.warn(String.format("Ignoring unsupported message: type [%s], message [%s]", message.getClass(),
                    message));
            return;
        }
        localEventDelivery(eventName, eventData);
    } catch (final Exception e) {
        log.error("Error during local dispatch of global event.", e);
    }
}

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

public void testMoveJmsHeadersAdaptrisMessageToJmsMessage() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    try {/*from   w  ww  . j a  v a2 s.  com*/
        broker.start();
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);

        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        addRedundantJmsHeaders(msg);

        trans.setMoveJmsHeaders(true);
        start(trans, session);

        Message jmsMsg = trans.translate(msg);
        assertEquals(msg.getMetadataValue(JMS_TYPE), jmsMsg.getJMSType());
        assertNotSame(msg.getMetadataValue(JMS_CORRELATION_ID), jmsMsg.getJMSCorrelationID());
        assertNotSame(msg.getMetadataValue(JMS_TIMESTAMP), jmsMsg.getJMSTimestamp());
        assertNotSame(msg.getMetadataValue(JMS_REDELIVERED), jmsMsg.getJMSPriority());
        assertNotSame(msg.getMetadataValue(JMS_MESSAGE_ID), jmsMsg.getJMSMessageID());
        assertNotSame(msg.getMetadataValue(JMS_EXPIRATION), jmsMsg.getJMSExpiration());
        assertNotSame(msg.getMetadataValue(JMS_DELIVERY_MODE), jmsMsg.getJMSDeliveryMode());
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
        broker.destroy();
    }

}

From source file:org.bremersee.common.jms.DefaultJmsConverter.java

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

    if (message == null) {
        return null;
    }/*from   w  ww  . j  a va  2 s  .  c  o m*/

    Class<?> payloadClass;
    try {
        payloadClass = Class.forName(message.getJMSType());
    } catch (Throwable t) { // NOSONAR
        payloadClass = null;
    }

    Object payload;

    if (message instanceof TextMessage) {

        TextMessage msg = (TextMessage) message;
        payload = tryToGetPayload(msg, payloadClass);

    } else if (message instanceof BytesMessage) {

        BytesMessage msg = (BytesMessage) message;
        payload = tryToGetPayload(msg, payloadClass);

    } else {

        MessageConversionException e = new MessageConversionException(
                "Unsupported message type [" + message.getClass().getName() + "].");
        log.error("Could not convert message:", e);
        throw e;
    }

    return payload;
}

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

public void testBug895() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    try {//from  w ww .j  a  v a2  s.  c o  m
        broker.start();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();

        msg.addMetadata(JmsConstants.JMS_PRIORITY, "9");
        msg.addMetadata(JmsConstants.JMS_TYPE, "idaho");
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.setMoveJmsHeaders(true);
        start(trans, session);

        Message jmsMsg = trans.translate(msg);

        assertNotSame("JMS Priorities should be different", jmsMsg.getJMSPriority(), 9);
        assertEquals("JMSType should be equal", "idaho", jmsMsg.getJMSType());
    } finally {
        stop(trans);
        broker.destroy();

    }
}