FileDocCategorySizeDatePackage
EmailSystemBean.javaAPI DocJBoss 4.2.15201Fri Jul 13 20:54:52 BST 2007org.jboss.tutorial.interceptor.bean

EmailSystemBean

public class EmailSystemBean extends Object implements EmailSystem

Fields Summary
Constructors Summary
Methods Summary
public voidemailLostPassword(java.lang.String username)

      System.out.println("<In EmailSystemBean.emailLostPassword business method");
      //Pretend we are looking up password and email, and place a message on the queue
      String password = "xyz";
      String email = "xyz@lalala.com";
      sendMessage(email, "Password Reminder", "Your password is " + password);
      System.out.println("Exiting EmailSystemBean.emailLostPassword business method>");
   
public java.lang.ObjectmyBeanInterceptor(javax.interceptor.InvocationContext ctx)

      if (ctx.getMethod().getName().equals("emailLostPassword"))
      {
         System.out.println("*** EmailSystemBean.myBeanInterceptor - username: " + ctx.getParameters()[0]);
      }

      return ctx.proceed();
   
public voidnoop()

      System.out.println("<In EmailSystemBean.noop business method");
      System.out.println("Exiting EmailSystemBean.noop business method>");
   
public voidnoop2()

      System.out.println("<In EmailSystemBean.noop2 business method");
      System.out.println("Exiting EmailSystemBean.noop2 business method>");
   
public voidsendBookingCancellationMessage(long orderId)

      System.out.println("<In EmailSystemBean.sendBookingCancellationMessage business method");
      //Pretend we are looking email, and place a message on the queue
      String email = "xyz@lalala.com";
      sendMessage(email, "Booking Confirmed!", "Your order " + orderId + "is confirmed!");
      System.out.println("Exiting EmailSystemBean.sendBookingCancellationMessage business method>");
   
public voidsendBookingConfirmationMessage(long orderId)

      System.out.println("<In EmailSystemBean.sendBookingConfirmationMessage business method");
      //Pretend we are looking email, and place a message on the queue
      String email = "xyz@lalala.com";
      sendMessage(email, "Booking Confirmed!", "Your order " + orderId + "is confirmed!");
      System.out.println("Exiting EmailSystemBean.sendBookingConfirmationMessage business method>");
   
private voidsendMessage(java.lang.String email, java.lang.String subject, java.lang.String body)

      QueueConnection cnn = null;
      QueueSession session = null;
      try
      {
         QueueSender sender = null;
         InitialContext ctx = new InitialContext();
         Queue queue = (Queue) ctx.lookup("queue/tutorial/email");
         QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
         cnn = factory.createQueueConnection();
         session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

         TextMessage msg = session.createTextMessage(
               "<mail>" +
               "<to>" + email + "</to>" +
               "<to>" + subject + "</to>" +
               "<msg>" + body +"</msg>" +
               "</mail>");

         sender = session.createSender(queue);
         sender.send(msg);
         System.out.println("Message sent successfully to remote queue.");
      }
      catch(Exception e)
      {
         throw new RuntimeException(e);
      }
      finally
      {
         try
         {
            session.close();
            cnn.close();
         }
         catch (JMSException e)
         {
            throw new RuntimeException(e);
         }
      }