/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ 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.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; import at.gv.egovernment.moaspss.logging.LogMsg; import at.gv.egovernment.moaspss.logging.Logger; import at.gv.egovernment.moaspss.logging.LoggingContext; import at.gv.egovernment.moaspss.logging.LoggingContextManager; /** * A servlet to initialize and update the MOA configuration. * * @author Fatemeh Philippi * @author Patrick Peck * @version $Id$ */ public class ConfigurationServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 8372961105222028696L; /** 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) */ @SuppressWarnings({ "rawtypes", "unchecked" }) 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(); } }