Example usage for javax.jms TextMessage getJMSType

List of usage examples for javax.jms TextMessage getJMSType

Introduction

In this page you can find the example usage for javax.jms TextMessage 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:org.fatal1t.forexapp.spring.api.adapters.SyncListener.java

@JmsListener(destination = "forex.sync.listener.connector.request", containerFactory = "myJmsContainerFactory")
public void receiveMessage(TextMessage message) throws JMSException {
    log.info("Source Queue: " + message.getJMSDestination().toString());
    log.info("Target Queue: " + message.getJMSReplyTo().toString());
    log.info("Received:" + message.getJMSCorrelationID() + " " + message.getJMSType() + " <"
            + message.getText().substring(0, 50) + ">");
    initiateAdapter();//w w  w  .  j a  v  a  2 s.  c o  m
    if (!initiateAdapter()) {
        log.info("pruser s adapterem");
        sendMessage("Error in adapter setting, cant login", message.getJMSCorrelationID(),
                message.getJMSReplyTo());
    }
    XStream xs = new XStream();
    Object o = xs.fromXML(message.getText());
    System.out.println(message.getText());
    switch (message.getJMSType()) {
    case "GetUserData": {
        GetUserDataResp APIResponse = this.APIAdapter.GetUserData();
        sendMessage(xs.toXML(APIResponse), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetAllSymbols": {
        GetAllSymbolsResp APIResp = this.APIAdapter.GetAllSymbols();
        sendMessage(xs.toXML(APIResp), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetTradingHours": {
        GetTradingHoursResp APIResp = this.APIAdapter.GetTradingHours((GetTradingHoursReq) o);
        sendMessage(xs.toXML(APIResp), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    case "GetCandlesHistory": {
        GetCandlesHistoryReq request = (GetCandlesHistoryReq) o;
        GetCandlesHistoryResp response = new GetCandlesHistoryResp();
        request.getRequestList().forEach((CandlesRange range) -> {
            GetCandlesRangeResp APIResp = this.APIAdapter.getCandlesRange(request.getSymbol(), range);
            response.getRecords().put(range.getId(), APIResp.getRecords());
        });
        sendMessage(xs.toXML(response), message.getJMSCorrelationID(), message.getJMSReplyTo());
        break;
    }
    }
}

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

private Object tryToGetPayload(TextMessage msg, Class<?> payloadClass) throws JMSException {
    String text = msg.getText();/* ww w . ja  va 2  s  . co m*/
    if (StringUtils.isBlank(text)) {
        return null;
    }
    String trimmedText = text.trim();
    Object payload = null;
    if (payloadClass != null && trimmedText.startsWith("{") && trimmedText.endsWith("}")) {
        try {
            payload = objectMapper.readValue(trimmedText, payloadClass);

        } catch (Throwable t0) { // NOSONAR
            log.info("Reading JSON from message with JMSType [" + msg.getJMSType() + "] failed."); // NOSONAR
        }
    }

    if (payload == null) {
        try {
            payload = marshaller.unmarshal(new StreamSource(new StringReader(text)));

        } catch (Throwable t0) { // NOSONAR
            log.info("Reading XML from message with JMSType [" + msg.getJMSType() + "] failed.");
        }
    }

    if (payload == null) {
        MessageConversionException e = new MessageConversionException("Converting TextMessage failed.");
        log.error("Could not convert text:\n" + text + "\n", e);
        throw e;
    }

    return payload;
}

From source file:org.codehaus.stomp.StompTest.java

public void testSendMessageWithStandardHeaders() throws Exception {

    MessageConsumer consumer = session.createConsumer(queue);

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);/*from  ww w  . ja  v  a  2 s.co  m*/

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame = "SEND\n" + "correlation-id:c123\n" + "priority:3\n" + "type:t345\n" + "JMSXGroupID:abc\n"
            + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World"
            + Stomp.NULL;

    sendFrame(frame);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));

    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    ActiveMQTextMessage amqMessage = (ActiveMQTextMessage) message;
    Assert.assertEquals("GroupID", "abc", amqMessage.getGroupID());
}

From source file:org.mule.transport.jms.JmsMuleMessageFactoryTestCase.java

@Override
protected Object getValidTransportMessage() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    when(textMessage.getText()).thenReturn(MESSAGE_TEXT);
    when(textMessage.getJMSCorrelationID()).thenReturn(null);
    when(textMessage.getJMSDeliveryMode()).thenReturn(Integer.valueOf(1));
    when(textMessage.getJMSDestination()).thenReturn(null);
    when(textMessage.getJMSExpiration()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSMessageID()).thenReturn("1234567890");
    when(textMessage.getJMSPriority()).thenReturn(Integer.valueOf(4));
    when(textMessage.getJMSRedelivered()).thenReturn(Boolean.FALSE);
    when(textMessage.getJMSReplyTo()).thenReturn(null);
    when(textMessage.getJMSTimestamp()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSType()).thenReturn(null);
    when(textMessage.getPropertyNames())
            .thenReturn(IteratorUtils.asEnumeration(IteratorUtils.arrayIterator(new Object[] { "foo" })));
    when(textMessage.getObjectProperty("foo")).thenReturn("bar");
    return textMessage;
}

From source file:org.wso2.carbon.appfactory.eventing.jms.AFMessageListener.java

@Override
public void onMessage(Message message) {
    if (log.isDebugEnabled()) {
        if (message instanceof MapMessage) {
            try {
                String messageBody = ((MapMessage) message).getString(TopicPublisher.MESSAGE_BODY);
                log.debug("Received a message:" + messageBody);
            } catch (JMSException e) {
                log.error("Error while getting message content.", e);
            }/*from  w  w w . jav  a  2 s. c  o  m*/
        }
    }
    MapMessage mapMessage;
    if (message instanceof MapMessage) {
        mapMessage = (MapMessage) message;
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    } else if (message instanceof TextMessage) {
        //Todo:remove this. we only support mapMessages initially and below code is only for testing purpose.
        final TextMessage textMessage = (TextMessage) message;
        mapMessage = new MapMessage() {
            @Override
            public boolean getBoolean(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByte(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShort(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public char getChar(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getInt(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLong(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloat(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDouble(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getString(String s) throws JMSException {
                return textMessage.getText();
            }

            @Override
            public byte[] getBytes(String s) throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObject(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getMapNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBoolean(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByte(String s, byte b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setShort(String s, short i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setChar(String s, char c) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setInt(String s, int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setLong(String s, long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setFloat(String s, float v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setDouble(String s, double v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setString(String s, String s2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes, int i, int i2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setObject(String s, Object o) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean itemExists(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSMessageID() throws JMSException {
                return textMessage.getJMSMessageID();
            }

            @Override
            public void setJMSMessageID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSTimestamp() throws JMSException {
                return textMessage.getJMSTimestamp();
            }

            @Override
            public void setJMSTimestamp(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSCorrelationID() throws JMSException {
                return textMessage.getJMSCorrelationID();
            }

            @Override
            public Destination getJMSReplyTo() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSReplyTo(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Destination getJMSDestination() throws JMSException {
                return textMessage.getJMSDestination();
            }

            @Override
            public void setJMSDestination(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSDeliveryMode() throws JMSException {
                return textMessage.getJMSDeliveryMode();
            }

            @Override
            public void setJMSDeliveryMode(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean getJMSRedelivered() throws JMSException {
                return textMessage.getJMSRedelivered();
            }

            @Override
            public void setJMSRedelivered(boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSType() throws JMSException {
                return textMessage.getJMSType();
            }

            @Override
            public void setJMSType(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSExpiration() throws JMSException {
                return textMessage.getJMSExpiration();
            }

            @Override
            public void setJMSExpiration(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSPriority() throws JMSException {
                return textMessage.getJMSPriority();
            }

            @Override
            public void setJMSPriority(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void clearProperties() throws JMSException {
                textMessage.clearProperties();
            }

            @Override
            public boolean propertyExists(String s) throws JMSException {
                return textMessage.propertyExists(s);
            }

            @Override
            public boolean getBooleanProperty(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByteProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShortProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getIntProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLongProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloatProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDoubleProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getStringProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObjectProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getPropertyNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBooleanProperty(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByteProperty(String s, byte b) throws JMSException {
                textMessage.setByteProperty(s, b);
            }

            @Override
            public void setShortProperty(String s, short i) throws JMSException {
                textMessage.setShortProperty(s, i);
            }

            @Override
            public void setIntProperty(String s, int i) throws JMSException {
                textMessage.setIntProperty(s, i);
            }

            @Override
            public void setLongProperty(String s, long l) throws JMSException {
                textMessage.setLongProperty(s, l);
            }

            @Override
            public void setFloatProperty(String s, float v) throws JMSException {
                textMessage.setFloatProperty(s, v);
            }

            @Override
            public void setDoubleProperty(String s, double v) throws JMSException {
                textMessage.setDoubleProperty(s, v);
            }

            @Override
            public void setStringProperty(String s, String s2) throws JMSException {
                textMessage.setStringProperty(s, s2);
            }

            @Override
            public void setObjectProperty(String s, Object o) throws JMSException {
                textMessage.setObjectProperty(s, o);
            }

            @Override
            public void acknowledge() throws JMSException {
                textMessage.acknowledge();
            }

            @Override
            public void clearBody() throws JMSException {
                textMessage.clearBody();
            }
        };
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    }

}