package at.gv.egovernment.moa.spss.server.service; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import at.gv.egovernment.moa.logging.LogMsg; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.logging.LoggingContext; import at.gv.egovernment.moa.logging.LoggingContextManager; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; import at.gv.egovernment.moa.spss.server.init.*; import at.gv.egovernment.moa.spss.util.MessageProvider; /** * A servlet to initialize and update the MOA configuration. * * @author Fatemeh Philippi * @author Patrick Peck * @version $Id$ */ public class ConfigurationServlet extends HttpServlet { /** The document type of the HTML to generate. */ private static final String DOC_TYPE = "\n"; /** * Handle a HTTP GET request, used to indicated that the MOA * configuration needs to be updated (reloaded). * * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse) */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MessageProvider msg = MessageProvider.getInstance(); PrintWriter out; // set up a logging context for logging the reconfiguration LoggingContextManager.getInstance().setLoggingContext( new LoggingContext("configuration update")); response.setContentType("text/html"); out = response.getWriter(); out.println(DOC_TYPE); out.println("MOA configuration update"); out.println(""); try { // reconfigure the system ConfigurationProvider config = ConfigurationProvider.reload(); IaikConfigurator iaikConfigurator = new IaikConfigurator(); iaikConfigurator.configure(config); // print a status message out.println("

" + msg.getMessage("config.06", null) + "

"); Logger.info(new LogMsg(msg.getMessage("config.06", null))); if (!config.getWarnings().isEmpty()) { // print the warnings List allWarnings = new ArrayList(); Iterator iter; allWarnings.addAll(config.getWarnings()); allWarnings.addAll(iaikConfigurator.getWarnings()); out.println("

" + msg.getMessage("config.29", null) + "

"); for (iter = allWarnings.iterator(); iter.hasNext();) { out.println(iter.next() + "
"); } out.println("

" + msg.getMessage("config.28", null) + "

"); } } catch (Throwable t) { out.println("

" + msg.getMessage("config.20", null) + "

"); out.println("

" + msg.getMessage("config.28", null) + "

"); Logger.warn(new LogMsg(msg.getMessage("config.20", null)), t); } out.println(""); out.flush(); out.close(); // tear down the logging context LoggingContextManager.getInstance().setLoggingContext(null); } /** * Do the same as doGet. * * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest, HttpServletResponse) */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } /** * Perform some initial initialization tasks for the MOA web services * application. * * Does an initial load of the MOA configuration to test if a working web * service can be provided. * * @see javax.servlet.GenericServlet#init() */ public void init() throws ServletException { SystemInitializer.init(); } }