Search in sources :

Example 1 with StompMessage

use of com.sun.messaging.bridge.api.StompMessage in project openmq by eclipse-ee4j.

the class StompSubscriberSession method toStompFrameMessage.

protected static StompFrameMessage toStompFrameMessage(Message jmsmsg, final String subid, Session ss, final StompProtocolHandlerImpl sph) throws Exception {
    MessageTransformer<Message, Message> mt = sph.getMessageTransformer();
    if (mt != null) {
        mt.init(ss, Bridge.STOMP_TYPE);
        Message oldmsg = jmsmsg;
        jmsmsg = mt.transform(jmsmsg, true, null, MessageTransformer.SUN_MQ, MessageTransformer.STOMP, null);
        if (jmsmsg == null) {
            throw new JMSException("null returned from " + mt.getClass().getName() + " transform() method for JMS message " + oldmsg + " in subscription " + subid);
        }
    }
    final Message msg = jmsmsg;
    final boolean needAck = (ss.getAcknowledgeMode() != Session.AUTO_ACKNOWLEDGE);
    return sph.toStompFrameMessage(new StompMessage() {

        @Override
        public String getSubscriptionID() throws Exception {
            return subid;
        }

        @Override
        public String getDestination() throws Exception {
            Destination jmsdest = msg.getJMSDestination();
            return sph.toStompFrameDestination(new StompDestinationImpl(jmsdest), false);
        }

        @Override
        public String getReplyTo() throws Exception {
            Destination jmsdest = msg.getJMSReplyTo();
            if (jmsdest == null) {
                return null;
            }
            return sph.toStompFrameDestination(new StompDestinationImpl(jmsdest), true);
        }

        @Override
        public String getJMSMessageID() throws Exception {
            return msg.getJMSMessageID();
        }

        @Override
        public String getJMSCorrelationID() throws Exception {
            return msg.getJMSCorrelationID();
        }

        @Override
        public String getJMSExpiration() throws Exception {
            return String.valueOf(msg.getJMSExpiration());
        }

        @Override
        public String getJMSRedelivered() throws Exception {
            return String.valueOf(msg.getJMSRedelivered());
        }

        @Override
        public String getJMSPriority() throws Exception {
            return String.valueOf(msg.getJMSPriority());
        }

        @Override
        public String getJMSTimestamp() throws Exception {
            return String.valueOf(msg.getJMSTimestamp());
        }

        @Override
        public String getJMSType() throws Exception {
            return msg.getJMSType();
        }

        @Override
        public Enumeration getPropertyNames() throws Exception {
            return msg.getPropertyNames();
        }

        @Override
        public String getProperty(String name) throws Exception {
            return (msg.getObjectProperty(name)).toString();
        }

        @Override
        public boolean isTextMessage() throws Exception {
            return (msg instanceof TextMessage);
        }

        @Override
        public boolean isBytesMessage() throws Exception {
            return (msg instanceof BytesMessage);
        }

        @Override
        public String getText() throws Exception {
            return ((TextMessage) msg).getText();
        }

        @Override
        public byte[] getBytes() throws Exception {
            BytesMessage m = (BytesMessage) msg;
            byte[] data = new byte[(int) m.getBodyLength()];
            m.readBytes(data);
            return data;
        }

        @Override
        public void setText(StompFrameMessage message) throws Exception {
            throw new RuntimeException("Unexpected call: setText()");
        }

        @Override
        public void setBytes(StompFrameMessage message) throws Exception {
            throw new RuntimeException("Unexpected call: setBytes()");
        }

        @Override
        public void setDestination(String stompdest) throws Exception {
            throw new RuntimeException("Unexpected call: setDestination()");
        }

        @Override
        public void setPersistent(String stompdest) throws Exception {
            throw new RuntimeException("Unexpected call: setPersistent()");
        }

        @Override
        public void setReplyTo(String replyto) throws Exception {
            throw new RuntimeException("Unexpected call: setReplyTo()");
        }

        @Override
        public void setJMSCorrelationID(String value) throws Exception {
            throw new RuntimeException("Unexpected call: setJMSCorrelationID()");
        }

        @Override
        public void setJMSExpiration(String value) throws Exception {
            throw new RuntimeException("Unexpected call: setJMSExpiration()");
        }

        @Override
        public void setJMSPriority(String value) throws Exception {
            throw new RuntimeException("Unexpected call: setJMSPriority()");
        }

        @Override
        public void setJMSType(String value) throws Exception {
            throw new RuntimeException("Unexpected call: setJMSType()");
        }

        @Override
        public void setProperty(String name, String value) throws Exception {
            throw new RuntimeException("Unexpected call: setProperty()");
        }
    }, needAck);
}
Also used : StompDestination(com.sun.messaging.bridge.api.StompDestination) Enumeration(java.util.Enumeration) StompMessage(com.sun.messaging.bridge.api.StompMessage) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) StompMessage(com.sun.messaging.bridge.api.StompMessage) StompUnrecoverableAckException(com.sun.messaging.bridge.api.StompUnrecoverableAckException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Aggregations

StompDestination (com.sun.messaging.bridge.api.StompDestination)1 StompFrameMessage (com.sun.messaging.bridge.api.StompFrameMessage)1 StompMessage (com.sun.messaging.bridge.api.StompMessage)1 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)1 StompUnrecoverableAckException (com.sun.messaging.bridge.api.StompUnrecoverableAckException)1 Enumeration (java.util.Enumeration)1