1 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 ; 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.getName() + ".config"; 24 25 private volatile L2TVSConfigurationSetupManager configSetupManager; 26 27 public void init() throws ServletException { 28 configSetupManager = (L2TVSConfigurationSetupManager) getServletContext().getAttribute(CONFIG_ATTRIBUTE); 29 } 30 31 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 32 Map params = request.getParameterMap(); 33 34 if (params.size() == 0) { 35 OutputStream out = response.getOutputStream(); 36 IOUtils.copy(this.configSetupManager.rawConfigFile(), out); 37 } else { 38 String query = request.getParameter("query"); 39 40 if ("mode".equals(query)) { 41 OutputStream out = response.getOutputStream(); 42 ConfigItem configModel = configSetupManager.systemConfig().configurationModel(); 43 Object configObject = configModel.getObject(); 44 IOUtils.copy(IOUtils.toInputStream(configObject.toString()), out); 45 } else { 46 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 47 PrintWriter writer = response.getWriter(); 48 writer.println("request not understood"); 49 } 50 } 51 52 response.flushBuffer(); 53 } 54 } 55 | Popular Tags |