Search in sources :

Example 1 with StompFrameMessage

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

the class StompSenderSession method sendStompMessage.

public void sendStompMessage(StompFrameMessage message) throws Exception {
    checkSession();
    MessageTransformer<Message, Message> mt = stompconn.getProtocolHandler().getMessageTransformer();
    StompMessageImpl msg = new StompMessageImpl(mt);
    stompconn.getProtocolHandler().fromStompFrameMessage(message, msg);
    Message jmsmsg = msg.jmsmsg;
    Destination jmsdest = msg.jmsdest;
    if (mt != null) {
        mt.init(session, Bridge.STOMP_TYPE);
        jmsmsg = mt.transform(jmsmsg, false, "UTF-8", MessageTransformer.STOMP, MessageTransformer.SUN_MQ, msg.propsForTransformer);
        if (jmsmsg == null) {
            throw new JMSException("null returned from " + mt.getClass().getName() + " transform() method");
        }
    }
    producer.send(jmsdest, jmsmsg, jmsmsg.getJMSDeliveryMode(), jmsmsg.getJMSPriority(), jmsmsg.getJMSExpiration());
    logger.log(Level.FINE, "Sent message " + jmsmsg.getJMSMessageID());
}
Also used : StompDestination(com.sun.messaging.bridge.api.StompDestination) StompMessage(com.sun.messaging.bridge.api.StompMessage) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage)

Example 2 with StompFrameMessage

use of com.sun.messaging.bridge.api.StompFrameMessage 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)

Example 3 with StompFrameMessage

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

the class JSONWebSocket method processData.

@Override
protected void processData(String text) throws Exception {
    if (DEBUG) {
        logger.log(logger.INFO, toString() + ".processData(text=" + text + ")");
    }
    try {
        JsonReader jsonReader = Json.createReader(new StringReader(text));
        JsonObject jo = jsonReader.readObject();
        String command = jo.getString(JsonMessage.Key.COMMAND);
        JsonObject headers = jo.getJsonObject(JsonMessage.Key.HEADERS);
        JsonObject body = jo.getJsonObject(JsonMessage.Key.BODY);
        StompFrameMessage frame = StompFrameMessageImpl.getFactory().newStompFrameMessage(StompFrameMessage.Command.valueOf(command), logger);
        Iterator<String> itr = headers.keySet().iterator();
        String key;
        String val;
        while (itr.hasNext()) {
            key = itr.next();
            val = headers.getString(key);
            if (val != null) {
                frame.addHeader(key, val);
            }
        }
        if (body != null) {
            JsonString btype = body.getJsonString(JsonMessage.BodySubKey.TYPE);
            if (btype == null || btype.getString().equals(JsonMessage.BODY_TYPE_TEXT)) {
                JsonString msg = body.getJsonString(JsonMessage.BodySubKey.TEXT);
                if (msg != null) {
                    frame.setBody(msg.getString().getBytes("UTF-8"));
                }
            } else if (btype.getString().equals(JsonMessage.BODY_TYPE_BYTES)) {
                JsonString enc = body.getJsonString("encoder");
                if (enc == null || enc.getString().equals(JsonMessage.ENCODER_BASE64)) {
                    JsonString msg = body.getJsonString(JsonMessage.BodySubKey.TEXT);
                    if (msg != null) {
                        byte[] bytes = null;
                        if (base64Class == null) {
                            BASE64Decoder decoder = new BASE64Decoder();
                            bytes = decoder.decodeBuffer(msg.getString());
                        } else {
                            Method gm = base64Class.getMethod("getDecoder", (new Class[] {}));
                            Object o = gm.invoke(null);
                            Method dm = o.getClass().getMethod("decode", (new Class[] { String.class }));
                            bytes = (byte[]) dm.invoke(o, msg.getString());
                        }
                        frame.setBody(bytes);
                        frame.addHeader(StompFrameMessage.CommonHeader.CONTENTLENGTH, String.valueOf(bytes.length));
                    }
                } else {
                    throw new IOException("encoder " + enc + " not supported");
                }
            } else {
                throw new IOException("body type:" + btype + " not supported");
            }
        }
        dispatchMessage((StompFrameMessageImpl) frame);
    } catch (Exception e) {
        logger.logStack(logger.ERROR, e.getMessage(), e);
        sendFatalError(e);
    }
}
Also used : StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) StringReader(java.io.StringReader) JsonReader(jakarta.json.JsonReader) JsonObject(jakarta.json.JsonObject) JsonObject(jakarta.json.JsonObject) JsonString(jakarta.json.JsonString) JsonString(jakarta.json.JsonString) Method(java.lang.reflect.Method) IOException(java.io.IOException) BASE64Decoder(com.sun.messaging.jmq.util.BASE64Decoder) IOException(java.io.IOException)

Example 4 with StompFrameMessage

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

the class STOMPWebSocket method sendFatalError.

protected void sendFatalError(Exception e) {
    logger.log(logger.ERROR, e.getMessage());
    try {
        StompFrameMessage err = stompProtocolHandler.toStompErrorMessage(getClass().getSimpleName(), e);
        err.setFatalERROR();
        sendToClient(err, stompProtocolHandler, null);
    } catch (Exception ee) {
        logger.log(logger.ERROR, "br.E_UNABLE_SEND_ERROR_MSG: " + e.toString() + ": " + ee.toString(), ee);
        this.close();
    }
}
Also used : StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) IOException(java.io.IOException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) StompFrameParseException(com.sun.messaging.bridge.api.StompFrameParseException)

Example 5 with StompFrameMessage

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

the class StompSubscriberSession method deliver.

@Override
public JMSAck deliver(JMSPacket msgpkt) throws ConsumerClosedNoDeliveryException {
    if (closing || closed || stompconn.isClosed()) {
        throw new ConsumerClosedNoDeliveryException("Subscriber " + this + " is closed");
    }
    try {
        final boolean needAck = (ackMode != SessionAckMode.AUTO_ACKNOWLEDGE);
        StompFrameMessage msg = toStompFrameMessage(subid, stompdest, msgpkt.getPacket(), needAck);
        if (stompconn.getProtocolHandler().getDEBUG()) {
            logger.log(logger.INFO, " SEND message " + msg + " for " + toString());
        }
        if (ackMode != SessionAckMode.CLIENT_ACKNOWLEDGE) {
            out.sendToClient(msg, stompconn.getProtocolHandler(), null);
            return new Ack(msgpkt.getPacket(), MessageAckType.ACKNOWLEDGE);
        } else {
            unackedMessages.add(msgpkt.getPacket().getSysMessageID());
            out.sendToClient(msg, stompconn.getProtocolHandler(), null);
        }
    } catch (Exception e) {
        logger.logStack(logger.WARNING, e.getMessage(), e);
    }
    return null;
}
Also used : ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) JMSAck(com.sun.messaging.jmq.jmsservice.JMSAck) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException)

Aggregations

StompFrameMessage (com.sun.messaging.bridge.api.StompFrameMessage)6 IOException (java.io.IOException)3 StompDestination (com.sun.messaging.bridge.api.StompDestination)2 StompMessage (com.sun.messaging.bridge.api.StompMessage)2 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)2 StompFrameParseException (com.sun.messaging.bridge.api.StompFrameParseException)1 StompOutputHandler (com.sun.messaging.bridge.api.StompOutputHandler)1 StompUnrecoverableAckException (com.sun.messaging.bridge.api.StompUnrecoverableAckException)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 ConsumerClosedNoDeliveryException (com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)1 JMSAck (com.sun.messaging.jmq.jmsservice.JMSAck)1 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)1 BASE64Decoder (com.sun.messaging.jmq.util.BASE64Decoder)1 JsonObject (jakarta.json.JsonObject)1 JsonReader (jakarta.json.JsonReader)1 JsonString (jakarta.json.JsonString)1 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 Enumeration (java.util.Enumeration)1