01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.messaging.http;
05:
06: import org.apache.commons.io.IOUtils;
07:
08: import com.tc.config.schema.dynamic.ConfigItem;
09: import com.tc.config.schema.setup.L2TVSConfigurationSetupManager;
10:
11: import java.io.IOException;
12: import java.io.OutputStream;
13: import java.io.PrintWriter;
14: import java.util.Map;
15:
16: import javax.servlet.ServletException;
17: import javax.servlet.http.HttpServlet;
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpServletResponse;
20:
21: public class ConfigServlet extends HttpServlet {
22:
23: public static final String CONFIG_ATTRIBUTE = ConfigServlet.class
24: .getName()
25: + ".config";
26:
27: private volatile L2TVSConfigurationSetupManager configSetupManager;
28:
29: public void init() throws ServletException {
30: configSetupManager = (L2TVSConfigurationSetupManager) getServletContext()
31: .getAttribute(CONFIG_ATTRIBUTE);
32: }
33:
34: protected void doGet(HttpServletRequest request,
35: HttpServletResponse response) throws ServletException,
36: IOException {
37: Map params = request.getParameterMap();
38:
39: if (params.size() == 0) {
40: OutputStream out = response.getOutputStream();
41: IOUtils.copy(this .configSetupManager.rawConfigFile(), out);
42: } else {
43: String query = request.getParameter("query");
44:
45: if ("mode".equals(query)) {
46: OutputStream out = response.getOutputStream();
47: ConfigItem configModel = configSetupManager
48: .systemConfig().configurationModel();
49: Object configObject = configModel.getObject();
50: IOUtils.copy(IOUtils.toInputStream(configObject
51: .toString()), out);
52: } else {
53: response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
54: PrintWriter writer = response.getWriter();
55: writer.println("request not understood");
56: }
57: }
58:
59: response.flushBuffer();
60: }
61: }
|