Package javax.jms

Examples of javax.jms.Message


        if (!responseExpected
            && (jmsAddressPolicy.getJndiReplyDestinationName() == null)) {
            replyTo = null;
        }

        Message message = marshal(request, pooledSession.session(), replyTo,
                                  clientBehaviourPolicy.getMessageType().value());
      //  message.get

        JMSMessageHeadersType headers =
            (JMSMessageHeadersType)context.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);


        int deliveryMode = getJMSDeliveryMode(headers);
        int priority = getJMSPriority(headers);
        String correlationID = getCorrelationId(headers);
        long ttl = getTimeToLive(headers);
        if (ttl <= 0) {
            ttl = DEFAULT_RECEIVE_TIMEOUT;
        }
       
        setMessageProperties(headers, message);
        if (responseExpected) {
            String id = pooledSession.getCorrelationID();

            if (id != null) {
                if (correlationID != null) {
                    String error = "User cannot set JMSCorrelationID when "
                        + "making a request/reply invocation using "
                        + "a static replyTo Queue.";
                    throw new JMSException(error);
                }
                correlationID = id;
            }
        }

        if (correlationID != null) {
            message.setJMSCorrelationID(correlationID);
        } else {
            //No message correlation id is set. Whatever comeback will be accepted as responses.
            // We assume that it will only happen in case of the temp. reply queue.
        }
View Full Code Here


        if (receiveTimeout != null) {
            timeout = receiveTimeout.longValue();
        }
       
        Message message = pooledSession.consumer().receive(timeout);
        LOG.log(Level.FINE, "client received reply: " , message);

        if (message != null) {
           
            populateIncomingContext(message, context, JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
View Full Code Here

     * @param replyTo the ReplyTo destination if any
     * @return a JMS of the appropriate type populated with the given payload
     */
    protected Message marshal(Object payload, Session session, Destination replyTo,
                              String messageType) throws JMSException {
        Message message = null;

        if (JMSConstants.TEXT_MESSAGE_TYPE.equals(messageType)) {
            message = session.createTextMessage((String)payload);
        } else {
            message = session.createObjectMessage();
            ((ObjectMessage)message).setObject((byte[])payload);
        }

        if (replyTo != null) {
            message.setJMSReplyTo(replyTo);
        }

        return message;
    }
View Full Code Here

    public void testMarshall() throws Exception {
        Requestor requestor = createRequestor(getDestinationName());

        LingoInvocation invocation = new LingoInvocation("foo", new Class[0], new Object[0], new MethodMetadata(false));
        Message message = marshaller.createRequestMessage(requestor, invocation);

        assertTrue("Should have created a text message: " + message, message instanceof TextMessage);

        TextMessage textMessage = (TextMessage) message;
        String text = textMessage.getText();
View Full Code Here

    }

    public void postDispatch(MessageContext bindingContext, OutputStreamMessageContext context)
        throws IOException {

        Message message = (Message)bindingContext.get(JMS_SERVER_TRANSPORT_MESSAGE);
        PooledSession replySession = null;
         // ensure non-oneways in point-to-point domain
        counters.getRequestTotal().increase();
       
        if (!context.isOneWay()) {
            if (queueDestinationStyle) {
                try {
//                  send reply
                    Queue replyTo = getReplyToDestination(context, message);
                    replySession = sessionFactory.get(false);

                    Message reply = marshalResponse(message, context, replySession);
                    setReplyCorrelationID(message, reply);                                     

                    QueueSender sender = (QueueSender)replySession.producer();

                    sendResponse(context, message, reply, sender, replyTo);
View Full Code Here

   
    public Message marshalResponse(Message message,
                                OutputStreamMessageContext context,
                                PooledSession replySession) throws JMSException {
       
        Message reply;      
        boolean textPayload = message instanceof TextMessage
            ? true : false;
        if (textPayload) {
            reply = marshal(context.getOutputStream().toString(),
                                replySession.session(),
View Full Code Here

        }

        public void run() {
            try {
                while (true) {
                    Message message = listenSession.consumer().receive();
                    if (message == null) {
                        LOG.log(Level.WARNING,
                                "Null message received from message consumer.",
                                " Exiting ListenerThread::run().");
                        return;
View Full Code Here

         MessageProducer publisher = publisherSession.createProducer(this.topic);
         int nmax = 3;

         // test receiveNoWait()
         TextMessage[] msgIn = new TextMessage[nmax];
         Message msg2 = null;
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receiveNoWait();
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
            }
            assertEquals("receive(): messages are not the same", msgIn[i].getText(), ((TextMessage)msg2).getText());        
         }
         msg2 = consumer.receiveNoWait();
         if (msg2 != null) {
            assertTrue("no message was sent, so null should have been returned here but it was " + msg.toString(), false);
         }
        
         // test receive(long)
         msgIn = new TextMessage[nmax];
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receive(200L);
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
            }
            assertEquals("receive(): messages are not the same", msgIn[i].getText(), ((TextMessage)msg2).getText());        
         }
         msg2 = consumer.receive(200L);
         if (msg2 != null) {
            assertTrue("no message was sent, so null should have been returned here but it was " + msg.toString(), false);
         }

         // test receive()
         msgIn = new TextMessage[nmax];
         for (int i=0; i < nmax; i++) {
            msgIn[i] = publisherSession.createTextMessage();
            msgIn[i].setText("msg " + i);
            publisher.send(this.topic, msgIn[i]);
         }
         for (int i=0; i < nmax; i++) {
            msg2 = consumer.receive();
            if (!(msg2 instanceof TextMessage)) {
               assertTrue("received message if of wrong type, should be TextMessage but is '" + msg2.getClass().getName() + "'", false);
            }
            assertEquals("receive(): messages are not the same", msgIn[i].getText(), ((TextMessage)msg2).getText());        
         }
         //PublisherThread pub = new PublisherThread(publisher, msg, 6, 100L);
         //pub.start();
View Full Code Here

      if (log.isLoggable(Level.FINER))
         log.finer("update cbSessionId='" + cbSessionId + "' oid='" + updateKey.getOid() + "'");
      synchronized (this.session.connection.closeSync) {
         try {
            if (this.msgListener != null) {
               Message msg = MessageHelper.convertFromMsgUnit(this.session, updateQos.getSender().getAbsoluteName(), updateKey.getData(), content, updateQos.getData());
               int ackMode = this.session.getAcknowledgeMode();
               if (log.isLoggable(Level.FINE))
                  log.fine("update: acknowledge mode is: " + ackMode);
               if (msg != null) {
                  // TODO keep reference to this and on next event fill this
                 
                 
                  XBMsgEvent msgEvent = new XBMsgEvent(this.msgListener, msg);
                  this.session.channel.put(msgEvent);

                  // for the other modes the difference is made in the run() of the session
                  if (ackMode != Session.AUTO_ACKNOWLEDGE) {
                     synchronized (this.session) {
                        long timeout = this.session.getUpdateTimeout();
                        if (timeout > 0) {
                           long t0 = System.currentTimeMillis();
                           if (log.isLoggable(Level.FINE))
                              log.fine("update: waiting for ack");
                           this.session.wait(timeout);
                           if (log.isLoggable(Level.FINE))
                              log.fine("update: waked up from ack");
                           long dt = System.currentTimeMillis() - t0;
                           if (dt >= timeout) {
                              if (this.exceptionListener != null) {
                                 this.exceptionListener.onException(new XBException(ME + ".update", "timeout of '" + timeout + "' ms occured when waiting for acknowledge of msg '" + msg.getJMSMessageID() + "'"));
                              }
                              throw new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, ME + ".update timeout of '" + timeout + "' ms occured when waiting for acknowledge of msg '" + msg.getJMSMessageID() + "'");
                           }  
                        }
                        else
                           this.session.wait(timeout);
                     }
                  }
                  else {
                     if (log.isLoggable(Level.FINE))
                        log.fine("update: acknowledge mode is AUTO: no waiting for user acknowledge");
                     msg.acknowledge();
                  }
               }
               else {
                  throw new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, ME + ".update: the message was null");        
               }
View Full Code Here

      log.info("run: session started");
      this.controlThread = Thread.currentThread();
      while (true) {
         try {
            XBMsgEvent msgEvent = (XBMsgEvent)this.channel.take();
            Message msg = msgEvent.getMessage();
            if (msg == null) {
               log.info("Shutting down the running thread since close event received");
               break;
            }
            msgEvent.getListener().onMessage(msg);
            // TODO notify the update thread waiting for ACK
            if (log.isLoggable(Level.FINE))
               log.fine("run: msg='" + msg.getJMSMessageID() + "' ack='" + this.ackMode + "'");
            if (this.ackMode == Session.DUPS_OK_ACKNOWLEDGE)
               msg.acknowledge();
         }
         catch (InterruptedException ex) {
            log.severe("run InterruptedException occured " + ex.getMessage());
            ex.printStackTrace();
         }
View Full Code Here

TOP

Related Classes of javax.jms.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.