KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > messaging > http > ConfigServlet


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.messaging.http;
5
6 import org.apache.commons.io.IOUtils;
7
8 import com.tc.config.schema.dynamic.ConfigItem;
9 import com.tc.config.schema.setup.L2TVSConfigurationSetupManager;
10
11 import java.io.IOException JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import javax.servlet.ServletException JavaDoc;
17 import javax.servlet.http.HttpServlet JavaDoc;
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 public class ConfigServlet extends HttpServlet JavaDoc {
22
23   public static final String JavaDoc CONFIG_ATTRIBUTE = ConfigServlet.class.getName() + ".config";
24
25   private volatile L2TVSConfigurationSetupManager configSetupManager;
26
27   public void init() throws ServletException JavaDoc {
28     configSetupManager = (L2TVSConfigurationSetupManager) getServletContext().getAttribute(CONFIG_ATTRIBUTE);
29   }
30
31   protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
32     Map JavaDoc params = request.getParameterMap();
33
34     if (params.size() == 0) {
35       OutputStream JavaDoc out = response.getOutputStream();
36       IOUtils.copy(this.configSetupManager.rawConfigFile(), out);
37     } else {
38       String JavaDoc query = request.getParameter("query");
39
40       if ("mode".equals(query)) {
41         OutputStream JavaDoc out = response.getOutputStream();
42         ConfigItem configModel = configSetupManager.systemConfig().configurationModel();
43         Object JavaDoc configObject = configModel.getObject();
44         IOUtils.copy(IOUtils.toInputStream(configObject.toString()), out);
45       } else {
46         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
47         PrintWriter JavaDoc writer = response.getWriter();
48         writer.println("request not understood");
49       }
50     }
51
52     response.flushBuffer();
53   }
54 }
55
Popular Tags