1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package no.feide.moria.servlet;
19
20 import javax.servlet.http.HttpServlet;
21
22 import no.feide.moria.log.MessageLogger;
23
24 import java.util.Properties;
25
26 /***
27 *
28 * @author Eva Indal
29 *
30 */
31 public class MoriaServlet extends HttpServlet {
32
33 /***
34 * Get the config from the context. The configuration is expected to be set
35 * by the controller before requests are sent to this servlet.
36 *
37 * @in
38 * @return The configuration.
39 * @throws IllegalStateException
40 * If the config is not properly set.
41 *
42 */
43 public Properties getServletConfig(String[] required_parameters, MessageLogger log) throws IllegalStateException {
44 final Properties config;
45
46
47 try {
48 config = (Properties) getServletContext().getAttribute(RequestUtil.PROP_CONFIG);
49 } catch (ClassCastException e) {
50 throw new IllegalStateException("Config is not correctly set in context.");
51 }
52 if (config == null)
53 throw new IllegalStateException("Config is not set in context.");
54
55
56 for (int i = 0; i < required_parameters.length; i++) {
57 String parvalue = config.getProperty(required_parameters[i]);
58 if ((parvalue == null) || (parvalue.equals(""))) {
59 log.logCritical("Required parameter '" + required_parameters[i] + "' is not set");
60 throw new IllegalStateException();
61 }
62 }
63 return config;
64 }
65 }