Search in sources :

Example 6 with JMSPacket

use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.

the class JMSServiceImpl method sendMessage.

/**
 * Send a message to the broker.
 *
 * @param connectionId The Id of the connection
 * @param message The Message to be sent
 *
 * @throws JMSServiceException if the Status returned for the sendMessage method is not
 * {@link JMSServiceReply.Status#OK}
 */
@Override
public JMSServiceReply sendMessage(long connectionId, JMSPacket message) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    cxn = checkConnectionId(connectionId, "sendMessage");
    /*
         * TBD: The packets used here are not compatible. Should sendMessage() have individual params (eg msg body) to pass to
         * processMessage() instead of Packet ?
         *
         * Trying Packet.fill()...
         */
    try {
        Packet p = new Packet();
        p.fill(message.getPacket());
        protocol.processMessage(cxn, p);
    } catch (Exception e) {
        String errStr = "sendMessage: Sending message failed. Connection ID: " + connectionId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", JMSServiceReply.Status.ERROR);
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : JMSPacket(com.sun.messaging.jmq.io.JMSPacket) Packet(com.sun.messaging.jmq.io.Packet) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException)

Example 7 with JMSPacket

use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.

the class StompSenderSession method sendStompMessage.

public void sendStompMessage(StompFrameMessage message) throws Exception {
    checkSession();
    Packet pkt = new Packet();
    pkt.setPersistent(jmsservice.DEFAULT_MessageDeliveryMode == MessageDeliveryMode.PERSISTENT);
    pkt.setPriority(jmsservice.DEFAULT_MessagePriority.priority());
    pkt.setExpiration(jmsservice.DEFAULT_TIME_TO_LIVE);
    pkt.setDeliveryTime(jmsservice.DEFAULT_DELIVERY_DELAY);
    stompconn.fillRemoteIPAndPort(pkt);
    StompDestinationImpl d = fromStompFrameMessage(message, pkt);
    String stompdest = d.getStompDestinationString();
    try {
        jmsservice.createDestination(connectionId, d.getDestination());
    } catch (JMSServiceException jmsse) {
        JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
        if (status == JMSServiceReply.Status.CONFLICT) {
            if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
                logger.log(logger.INFO, "Destination " + stompdest + " already exist");
            }
        } else {
            throw jmsse;
        }
    }
    synchronized (this) {
        Long prodid = producers.get(stompdest);
        if (prodid == null) {
            JMSServiceReply reply = jmsservice.addProducer(connectionId, sessionId, d.getDestination());
            prodid = Long.valueOf(reply.getJMQProducerID());
            producers.put(stompdest, prodid);
        }
        pkt.setProducerID(prodid.longValue());
    }
    pkt.prepareToSend();
    synchronized (this) {
        if (isTransacted()) {
            pkt.setTransactionID(getTransactionId());
        } else {
            pkt.setTransactionID(0L);
        }
        final Packet p = pkt;
        jmsservice.sendMessage(connectionId, new JMSPacket() {

            @Override
            public Packet getPacket() {
                return p;
            }
        });
    }
    if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
        logger.log(logger.INFO, "Sent message " + pkt.getSysMessageID());
    }
}
Also used : JMSPacket(com.sun.messaging.jmq.io.JMSPacket) Packet(com.sun.messaging.jmq.io.Packet) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSPacket(com.sun.messaging.jmq.io.JMSPacket)

Aggregations

JMSPacket (com.sun.messaging.jmq.io.JMSPacket)7 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)3 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)3 AccessControlException (java.security.AccessControlException)3 Packet (com.sun.messaging.jmq.io.Packet)2 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 ConsumerClosedNoDeliveryException (com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)2 IllegalStateException (com.sun.messaging.jms.IllegalStateException)2 InvalidDestinationException (jakarta.jms.InvalidDestinationException)2 InvalidSelectorException (jakarta.jms.InvalidSelectorException)2 JMSException (jakarta.jms.JMSException)2 JMSSecurityException (jakarta.jms.JMSSecurityException)2 Message (jakarta.jms.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)2 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)1 Session (com.sun.messaging.jmq.jmsserver.core.Session)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)1