FileDocCategorySizeDatePackage
MailerMDB.javaAPI DocJBoss 4.2.13416Fri Jul 13 20:55:56 BST 2007xpetstore.services.mail.ejb

MailerMDB

public class MailerMDB extends Object implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener
author
Herve Tchepannou
ejb.bean
name="Mailer" acknowledge-mode="Auto-acknowledge" destination-type="javax.jms.Queue" subscription-durability="Durable" transaction-type="Container"
ejb.transaction
type="NotSupported"
ejb.resource-ref
res-ref-name="${jndi.mail.session}" res-type="javax.mail.Session" res-auth="Container" jndi-name="${orion.mail.session}"
jboss.destination-jndi-name
name="${jboss.queue.mail}"
jboss.resource-ref
res-ref-name="${jndi.mail.session}" jndi-name="${jboss.mail.session}"
weblogic.message-driven
destination-jndi-name="${weblogic.queue.mail}"
weblogic.resource-description
res-ref-name="${jndi.mail.session}" jndi-name="${weblogic.mail.session}"
orion.bean
connection-factory-location="${orion.queue.ConnectionFactory}" destination-location="${orion.queue.mail}"

Fields Summary
Constructors Summary
Methods Summary
public voidejbCreate()

public voidejbRemove()

public voidonMessage(javax.jms.Message recvMsg)
This method expect a javax.jms.ObjectMessage that contains a {@link Email} as the message object

        try
        {
            Debug.print( "MailerMDB.onMessage(" + recvMsg + ")" );

            ObjectMessage msg = ( ObjectMessage ) recvMsg;
            Email         email = ( Email ) msg.getObject(  );

            send( email.getTo(  ), email.getSubject(  ), email.getBody(  ) );
        }
        catch ( Exception e )
        {
            Debug.print( "Unable to send the email", e );
        }
    
public voidsend(java.lang.String to, java.lang.String subject, java.lang.String body)

        Debug.print( "MailerMDB.send(" + to + "," + subject + ",...)" );

        InitialContext     ic = new InitialContext(  );
        Session            session = ( Session ) ic.lookup( JNDINames.MAIL_SESSION );
        javax.mail.Message msg = new MimeMessage( session );

        msg.setFrom(  );
        msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( to, false ) );
        msg.setSubject( subject );

        msg.setDataHandler( new DataHandler( body, "text/html" ) );
        msg.setHeader( "X-Mailer", "JavaMailer" );
        msg.setSentDate( new Date(  ) );

        Transport.send( msg );
    
public voidsetMessageDrivenContext(javax.ejb.MessageDrivenContext mdc)