1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
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 | |
|
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 | |
|