2 Replies Latest reply on Nov 29, 2007 10:15 AM by Simonluca Landi

    Properties inside an ObjectMessage becomes a HashMap

    Simonluca Landi Newbie

      Hi
      We are running the following test:
      A producer sends an ObjectMessage with a Properties inside to a Queue.
      A consumer dequeues the ObjectMessage from the Queue, but we found an HashMap instead of a Properties.

      Procuder:
      
       if ( !initError ){
       Session session = null;
       MessageProducer publisher = null;
       ObjectMessage message = null;
       int numMsgs = ciclesNumber.intValue();
      
       try {
       StringBuffer sb = new StringBuffer();
       properties = new Properties();
      
       for (int i = 0; i < numMsgs; i++) {
       if ( stop ){
       break;
       }
       session = connection.createSession(false, 0); //autocommit
       publisher = session.createProducer(dest);
       message = session.createObjectMessage();
       properties.clear();
       properties.put("properties iteration",
      String.valueOf( i ) );
       message.setIntProperty("iteration", i );
       message.setObject( properties );
      
       sb.setLength( 0 );
       sb.append( " iteration number : " ).append( i );
       log.info( sb.toString() );
      
       publisher.send( message, DeliveryMode.PERSISTENT,
      Message.DEFAULT_PRIORITY, timeToLive.intValue() );
      
       session.close();
       }
       mess = "messaggio spedito";
       } catch (Throwable t) {
       // JMSException could be thrown
       mess = t.toString();
       log.error("PublisherBean.publishNews: ", t);
       }
       }
      


      Consumer:
      
       ObjectMessage msg = null;
       StringBuffer sb = new StringBuffer();
      
       try {
       if (message instanceof ObjectMessage ) {
       msg = (ObjectMessage) message;
       Integer id = msg.getIntProperty("iteration");
       sb.setLength( 0 );
       sb.append( "MESSAGE BEAN: IntProperty iteration: " ).append( id );
       log.info( sb );
       Object array = msg.getObject();
       log.info( array.getClass() );
      
       long now = System.currentTimeMillis();
      
       while(true){
       if ( System.currentTimeMillis() - now > 10000 )
       break;
       }
      
       } else {
       log.warn("Message of wrong type: " + message.getClass().getName());
       }
       } catch (JMSException e) {
       e.printStackTrace();
       } catch (Throwable te) {
       te.printStackTrace();
       }
      


      The cosumer writes:

      base.MessageMdb.onMessage INFO - class java.util.HashMap
      


      Any hints?