© 2001 BEA Systems, Inc.

com.bea.commerce.platform.mail
Class MailServiceBean

com.bea.commerce.platform.mail.MailServiceBean

public class MailServiceBean

Remote interface to the MailService stateless session bean. This bean provides basic mail-sending capabilities for sending text email messages.

The smtp server can be specified in the bean's deployment descriptor, or in the weblogic commerce properties file (entries in the deployment descriptor will override those in the properties file).


Constructor Summary
MailServiceBean()
           
 
Method Summary
 void addToBatch(MailMessage message, java.lang.String batch)
          Add a MailMessage to a batch so that it can be sent later.
protected  void close(java.sql.Connection conn)
           
protected  void close(java.sql.PreparedStatement ps)
           
protected  void close(java.sql.ResultSet rs)
           
protected  MailRecipients createRecipients(java.util.ArrayList toAddresses, java.util.ArrayList ccAddresses, java.util.ArrayList bccAddresses)
           
 void deleteBatch(java.lang.String batch)
          Delete a batch and all of its messages
 void ejbActivate()
          This method is required by the EJB Specification, but is not used by this class.
 void ejbCreate()
          Creates the session bean.
 void ejbPassivate()
          This method is required by the EJB Specification, but is not used by this class.
 void ejbRemove()
          This method is required by the EJB Specification, but is not used by this class.
 java.util.ArrayList getBatchNames()
          Return all batch names in the system
 int getBatchSize(java.lang.String batch)
          Return the size of a batch.
protected  java.sql.Connection getConnection()
           
 ServletResults getJSPResults(java.lang.String url, java.util.Map params)
          Similar to getTextFromJSP; but will retrieve contents of the jsp page as a byte array to cut down on string encoding hassles.
protected  com.bea.commerce.platform.mail.Session getMailSession()
           
 java.util.ArrayList getMessagesInBatch(java.lang.String batch, boolean getText)
          Retrieve all messages in a batch.
protected  long getNextAddressId(java.sql.Connection con)
           
protected  long getNextBatchId(java.sql.Connection con)
           
protected  long getNextHeaderId(java.sql.Connection con)
           
protected  long getNextMessageId(java.sql.Connection con)
           
protected  javax.ejb.SessionContext getSessionContext()
           
 java.lang.String getTextFromJSP(java.lang.String url, java.util.Map params)
          Generate text from a JSP page for use in an email message.
 boolean isValidAddress(java.lang.String address)
           
 void sendBatch(java.lang.String batch, boolean delete)
          Send all the messages in a batch.
 void sendMail(MailMessage message)
          Send an email message immediately.
 void sendMail(java.lang.String to, java.lang.String from, java.lang.String subject, java.lang.String text)
          The simplest way to send a mail message; supply the basic information and the message will be sent immediately.
 void setSessionContext(javax.ejb.SessionContext ctx)
          Sets the session context.
protected  void validateMailRecipients(MailRecipients recipients)
          Utility method to check that a MailRecipients object is valid; it must contain at least one 'to' address, and all addresses must be valid addresses.
 

Constructor Detail

MailServiceBean

public MailServiceBean()
Method Detail

ejbCreate

public void ejbCreate()
Creates the session bean.

ejbActivate

public void ejbActivate()
This method is required by the EJB Specification, but is not used by this class.

ejbRemove

public void ejbRemove()
This method is required by the EJB Specification, but is not used by this class.

ejbPassivate

public void ejbPassivate()
This method is required by the EJB Specification, but is not used by this class.

setSessionContext

public void setSessionContext(javax.ejb.SessionContext ctx)
Sets the session context.
Parameters:
ctx - Context for session

getSessionContext

protected javax.ejb.SessionContext getSessionContext()

sendMail

public void sendMail(java.lang.String to,
                     java.lang.String from,
                     java.lang.String subject,
                     java.lang.String text)
              throws java.lang.IllegalArgumentException
The simplest way to send a mail message; supply the basic information and the message will be sent immediately.
Parameters:
to - The address to mail to
from - The "from" address
subject - The message's subject. Can be null.
text - The message's text. Can be null.
Throws:
java.lang.IllegalArgumentException - If the "to" address is null or invalid

sendMail

public void sendMail(MailMessage message)
              throws java.lang.IllegalArgumentException
Send an email message immediately. A valid MailMessage is required; i.e., there must be at least one recipient.
Parameters:
message - A MailMessage to send.
Throws:
java.lang.IllegalArgumentException - if the MailMessage is not valid

addToBatch

public void addToBatch(MailMessage message,
                       java.lang.String batch)
                throws java.lang.IllegalArgumentException
Add a MailMessage to a batch so that it can be sent later. If the specified batch does not exist, it will be created.
Parameters:
message - A MailMessage to batch
batch - the name of the batch to add it to
Throws:
java.lang.IllegalArgumentException - if the MailMessage is not valid

sendBatch

public void sendBatch(java.lang.String batch,
                      boolean delete)
Send all the messages in a batch.
Parameters:
batch - the name of the batch to send

deleteBatch

public void deleteBatch(java.lang.String batch)
Delete a batch and all of its messages
Parameters:
batch - the name of the batch to delete

getMessagesInBatch

public java.util.ArrayList getMessagesInBatch(java.lang.String batch,
                                              boolean getText)
Retrieve all messages in a batch. If the getText flag is false, all message information will be retrieved except for the message text. This option is provided to avoid memory/bandwidth problems for batches that may contain large mail messages.
Parameters:
batch - the name of the batch to examine
getText - flag to retrieve message text
Returns:
an ArrayList of MailMessage objects

getBatchSize

public int getBatchSize(java.lang.String batch)
Return the size of a batch.
Parameters:
batch - the name of the batch to examine
Returns:
the number of messages in the batch

getBatchNames

public java.util.ArrayList getBatchNames()
Return all batch names in the system
Returns:
an ArrayList of batch names

getTextFromJSP

public java.lang.String getTextFromJSP(java.lang.String url,
                                       java.util.Map params)
                                throws java.io.IOException
Generate text from a JSP page for use in an email message. Any parameters will be passed as HTTP POST parameters. If the URL is relative, it will be assumed it is an HTTP request to the local server, at the local server's port.
Parameters:
url - the URL of the jsp page.
params - a map of parameters to pass to the JSP
Returns:
the generated text

getJSPResults

public ServletResults getJSPResults(java.lang.String url,
                                    java.util.Map params)
                             throws java.io.IOException
Similar to getTextFromJSP; but will retrieve contents of the jsp page as a byte array to cut down on string encoding hassles. The ServletResults object also includes the content-type directive of the JSP page, if any is given.

validateMailRecipients

protected void validateMailRecipients(MailRecipients recipients)
                               throws java.lang.IllegalArgumentException
Utility method to check that a MailRecipients object is valid; it must contain at least one 'to' address, and all addresses must be valid addresses.
Parameters:
recipients - the MailRecipients object to check

isValidAddress

public boolean isValidAddress(java.lang.String address)

getMailSession

protected com.bea.commerce.platform.mail.Session getMailSession()

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException

close

protected void close(java.sql.Connection conn)

close

protected void close(java.sql.PreparedStatement ps)

close

protected void close(java.sql.ResultSet rs)

createRecipients

protected MailRecipients createRecipients(java.util.ArrayList toAddresses,
                                          java.util.ArrayList ccAddresses,
                                          java.util.ArrayList bccAddresses)

getNextMessageId

protected long getNextMessageId(java.sql.Connection con)
                         throws java.sql.SQLException

getNextBatchId

protected long getNextBatchId(java.sql.Connection con)
                       throws java.sql.SQLException

getNextHeaderId

protected long getNextHeaderId(java.sql.Connection con)
                        throws java.sql.SQLException

getNextAddressId

protected long getNextAddressId(java.sql.Connection con)
                         throws java.sql.SQLException

© 2001 BEA Systems, Inc.

Copyright © 2001 BEA Systems, Inc. All Rights Reserved