1 Reply Latest reply on Oct 19, 2008 2:44 PM by ilangocal

    problem in doProcess() method in a servlet that posts messag

      My environment is: JBoss 5, Windows Vista.
      I have written a servlet that will post messages to queue via a Session Bean Facade. Now this is the error the Netbeans IDE is giving me: The IDE (Netbeans is telling me the following:
      incompatible types:
      found: javax.jms.QueueSession.CreateProducer
      required:javax.jms.MessageProducer


      The error is right here on: messageProducer = session.createProducer(queue); in the processRequest(...) method.

      Therefore this is what I have in the doProcess method in this servlet,

      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
       response.setContentType("text/html;charset=UTF-8");
       String title=request.getParameter("title");
       String body=request.getParameter("body");
      
       if ((title!=null) && (body!=null)) {
      
       Queue queue = null;
       QueueConnection connection = null;
       QueueSession session = null;
       MessageProducer messageProducer = null;
       try {
      
       InitialContext ctx = new InitialContext();
       queue = (Queue) ctx.lookup("queue/mdb");
       QueueConnectionFactory factory =
       (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
       connection = factory.createQueueConnection();
       session = connection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
      
       messageProducer = session.createProducer(queue);
      
       ObjectMessage message = session.createObjectMessage();
       // here we create a Queueing Entity, that will be sent in JMS message
       QueueingEntity e = new QueueingEntity();
       e.setTitle(title);
       e.setBody(body);
      
       message.setObject(e);
       messageProducer.send(message);
       messageProducer.close();
       connection.close();
       response.sendRedirect("ListMessages");
      
       } catch (JMSException ex) {
       ex.printStackTrace();
       } catch (NamingException ex) {
       ex.printStackTrace();
       }
      
      }
      
       PrintWriter out = response.getWriter();
       try {
       /* TODO output your page here
       out.println("<html>");
       out.println("<head>");
       out.println("<title>Servlet ServletToPostMessagesOnDexSubmitQueue</title>");
       out.println("</head>");
       out.println("<body>");
       out.println("<h1>Servlet ServletToPostMessagesOnDexSubmitQueue at " + request.getContextPath () + "</h1>");
       out.println("</body>");
       out.println("</html>");
       */
       } finally {
       out.close();
       }
       }


      I am not able to figure this out, even though it looks like a simple Java problem.
      Any suggestions are appreciated.

      thanks