2 Replies Latest reply on Nov 2, 2010 2:02 PM by Steven Wyatt

    Casting SpyTextMessage to TextMessage

    Steven Wyatt Newbie

      Below is the code for an MDB onMessage method. The message parameter fails the instanceof check. The actual type of message is SpyTextMessage so don't understand why the cast fails.Anyone have a clue on what I'm doing wrong?

       

      public void onMessage(Message message) {
      String messageText = "No message";
      if (message instanceof TextMessage) {
      try {
      messageText = ((TextMessage)message).getText();
      } catch (JMSException e) {
      e.printStackTrace();
      }
      }
      System.out.println("Received Message:"+messageText);
      }

      public void onMessage(Message message) {

      String messageText = "No message";

      if (message instanceof TextMessage) {

      try {

      messageText = ((TextMessage)message).getText();

      } catch (JMSException e) {

      e.printStackTrace();

      }

      }

      System.out.println("Received Message:"+messageText);

      }