Email Answering System
Version 1.0

com.ninecode.email.beans.master
Class EmailDispatcher

java.lang.Object
  |
  +--com.ninecode.email.beans.master.EmailDispatcher
All Implemented Interfaces:
EnterpriseBean, MessageDrivenBean, MessageListener, Serializable

public class EmailDispatcher
extends Object
implements MessageDrivenBean, MessageListener

Message driven bean reads from a queue and dispatches to topics based on subject. The plan was to examine the Subject property set on a BytesMessage and try to find a matching Topic. To do that it converts the subject to lower case so the case-sensitivity of the lookup doesn't matter. It also trys "jms/" + topic in the case of a failed lookup. If no topic is found it sends a message to the output queue (return to sender) with a "help" message. This, however, is not allowed since arbitrary jndi lookups are not allowed. So... Another method is used. This is a configured list of subject-topic pairs that have a direct mapping. This list can't be dynamic due to the life-cycle of the message bean. Each message driven bean that is in the list would have it's own "help" command. That is, a message with subject xxx would be forwarded on to the topic associated with xxx and if the message body is the text string "help" (case-insensitive) it would answer with some help text. If no topic can be found using the above mechanisms it responds with the list of subjects it was configured with and a helpful message that says ask them for help on the topic. If a matching topic is found the message is essentially forwarded to the topic.

See Also:
Serialized Form

Field Summary
protected  EmailProperties mMap
          The list of subject-topic pairs.
 
Constructor Summary
EmailDispatcher()
          Creates a EmailDispatcher bean.
 
Method Summary
 void bounceMessage(Message message, String subject, String content)
          Reply with help for unhandled messages.
protected  void dispatch(Message message)
          Dispatch the message.
 void ejbCreate()
          Startup call.
 void ejbRemove()
          Shutdown call.
 void forwardMessage(Message message, String name)
          Forward a jms message to the topic given.
 byte[] getBytes(BytesMessage message)
          Read all bytes from a bytes message.
protected  String getTopics()
          Get the list of configured topics.
 void helpMessage(Message message)
          Send help messages to all topics.
protected  void initializeMapping()
          Internalize the configured environment "Subject Topic Map".
 void onMessage(Message message)
          Process a message.
 void setMessageDrivenContext(MessageDrivenContext mdc)
          Remember the context for this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mMap

protected EmailProperties mMap
The list of subject-topic pairs.

Constructor Detail

EmailDispatcher

public EmailDispatcher()
Creates a EmailDispatcher bean. Life cycle:
  • constructor
  • set context
  • create
  • message
  • remove
  • Method Detail

    ejbCreate

    public void ejbCreate()
    Startup call.


    ejbRemove

    public void ejbRemove()
                   throws EJBException
    Shutdown call.

    Specified by:
    ejbRemove in interface MessageDrivenBean
    EJBException

    initializeMapping

    protected void initializeMapping()
    Internalize the configured environment "Subject Topic Map". The "Subject Topic Map" item within the "java:comp/env" context is fetched and iterpreted as a list of subject topic pairs. This is cached in the mMap member field.


    getBytes

    public byte[] getBytes(BytesMessage message)
                    throws JMSException
    Read all bytes from a bytes message. Necessary because of the poor API available on bytes messages. This isn't really efficient, maybe we should put the size in the message first.

    JMSException

    forwardMessage

    public void forwardMessage(Message message,
                               String name)
                        throws NamingException,
                               JMSException
    Forward a jms message to the topic given.

    Parameters:
    message - The message to forward.
    name - The topic name. A lookup is performed on this name within the "java:comp/env" environment.
    NamingException
    JMSException

    helpMessage

    public void helpMessage(Message message)
                     throws NamingException,
                            JMSException
    Send help messages to all topics.

    Parameters:
    message - The help message.
    NamingException
    JMSException

    getTopics

    protected String getTopics()
    Get the list of configured topics.

    Returns:
    The list of topics separated by spaces.

    bounceMessage

    public void bounceMessage(Message message,
                              String subject,
                              String content)
                       throws NamingException,
                              JMSException
    Reply with help for unhandled messages.

    Parameters:
    message - The message to bounce.
    NamingException
    JMSException

    dispatch

    protected void dispatch(Message message)
    Dispatch the message.

    Parameters:
    message - The message to dispatch.

    setMessageDrivenContext

    public void setMessageDrivenContext(MessageDrivenContext mdc)
                                 throws EJBException
    Remember the context for this instance.

    Specified by:
    setMessageDrivenContext in interface MessageDrivenBean
    EJBException

    onMessage

    public void onMessage(Message message)
    Process a message.

    Specified by:
    onMessage in interface MessageListener
    Parameters:
    message - The message to process.

    Email Answering System
    Version 1.0

    Copyright © 2003 Derrick Oswald. All rights reserved.