Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block

    private QueueConnectionFactory connectionFactory;
    private Queue myQueue;

    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        try
        {
            InitialContext ic = new InitialContext();
            connectionFactory = (QueueConnectionFactory)ic.lookup("java:comp/env/jms/connectionFactory");
            myQueue = (Queue)ic.lookup("java:comp/env/jms/myQueue");
        }
        catch (Exception e)
        {
          e.printStackTrace();
            throw new ServletException(e);
        }
    }
.
.
.
    public void sendMessage(String msg)
    throws Exception
    {
        QueueConnection connection = null;
        QueueSession session = null;
        MessageProducer producer = null;
        try
        {
          connection = connectionFactory.createQueueConnection();
          session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
          producer = session.createProducer(myQueue);
          TextMessage message = session.createTextMessage(msg);
          producer.send(message);
        }
        finally
        {
          try
          {
            if (producer!=null)producer.close();
            if (session!=null)session.close();
            if (connection!=null)connection.close();
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
    }
  • Now deploy your webapp to $JETTY-HOME/webapps-plus
  • Run it with:
Code Block

java -jar start.jar etc/jetty.xml etc/jetty-plus.xml

You're done!

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery