Coverage Report - org.apache.commons.messenger.InitMessengerServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
InitMessengerServlet
0%
0/17
0%
0/6
2.667
 
 1  
 /*
 2  
  * Copyright (C) The Apache Software Foundation. All rights reserved.
 3  
  *
 4  
  * This software is published under the terms of the Apache Software License
 5  
  * version 1.1, a copy of which has been included with this distribution in
 6  
  * the LICENSE file.
 7  
  *
 8  
  * $Id: InitMessengerServlet.java 155459 2005-02-26 13:24:44Z dirkv $
 9  
  */
 10  
 package org.apache.commons.messenger;
 11  
 
 12  
 import java.net.URL;
 13  
 
 14  
 import javax.servlet.ServletException;
 15  
 import javax.servlet.http.HttpServlet;
 16  
 
 17  
 
 18  
 /** <p><code>InitMessengerServlet</code> is a simple servlet that
 19  
  * will initialize the MessengerManager from a URL specified in the
 20  
  * web.xml deployment descriptor.</p>
 21  
  *
 22  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 23  
  * @version $Revision: 155459 $
 24  
  */
 25  
 public class InitMessengerServlet extends HttpServlet {
 26  
 
 27  0
     private static boolean initialized = false;
 28  
     
 29  0
     public InitMessengerServlet() {
 30  0
     }
 31  
     
 32  
     public void init() throws ServletException {
 33  0
         if ( ! initialized ) {
 34  0
             initialized = true;
 35  
             
 36  0
             getServletContext().log( "About to initialize MessengerManager" );
 37  
             
 38  0
             String config = getRequiredInitParmeter( "config", "The URL of the Messenger XML deployment document" );
 39  
             try {            
 40  0
                 URL url = getServletContext().getResource( config );
 41  0
                 MessengerManager.configure( url.toString() );
 42  
             }
 43  0
             catch (Exception e) {
 44  0
                 throw new ServletException( "Failed to initialise MessengerManager from config: " + config + ". Reason : " + e, e );
 45  0
             }
 46  
         }
 47  0
     }
 48  
     
 49  
     // Implementation methods
 50  
     //-------------------------------------------------------------------------        
 51  
     protected String getRequiredInitParmeter(String key, String description) throws ServletException {
 52  0
         String value = getInitParameter( key );
 53  0
         if ( value == null || value.length() == 0 ) {
 54  0
             throw new ServletException( 
 55  
                 "No initialization parameter for parameter: " + key 
 56  
                 + " description: " + description 
 57  
             );
 58  
         }
 59  0
         return value;
 60  
     }
 61  
 }
 62