001    /*
002     * Copyright (C) The Apache Software Foundation. All rights reserved.
003     *
004     * This software is published under the terms of the Apache Software License
005     * version 1.1, a copy of which has been included with this distribution in
006     * the LICENSE file.
007     * 
008     * $Id: Messagelet.java 155459 2005-02-26 13:24:44Z dirkv $
009     */
010    package org.apache.commons.messagelet;
011    
012    import java.io.IOException;
013    
014    import javax.jms.JMSException;
015    import javax.servlet.GenericServlet;
016    import javax.servlet.ServletException;
017    import javax.servlet.ServletRequest;
018    import javax.servlet.ServletResponse;
019    
020    /** <p><code>Messengerlet</code> the base class for a servlet which processes 
021      * JMS messages via a MessageletRequest and MessageletResponse.</p>
022      *
023      * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
024      * @version $Revision: 155459 $
025      */
026    public abstract class Messagelet extends GenericServlet {
027    
028        public abstract void service( MessageletRequest request, MessageletResponse response ) 
029            throws IOException, JMSException, ServletException;
030        
031        
032        public void service( ServletRequest req, ServletResponse res ) throws ServletException, IOException {
033            MessageletRequest request;
034            MessageletResponse response;
035            
036        try {
037            request = (MessageletRequest) req;
038            response = (MessageletResponse) res;
039                
040        } 
041            catch (ClassCastException e) {
042            throw new ServletException("non-Message request or response");
043        }
044            
045            try {
046                service(request, response);
047            }
048            catch (JMSException e) {
049                throw new ServletException(e);
050            }
051        }
052    }