LoggingConfigurationAction.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.web.action;
022 
023 import java.io.IOException;
024 
025 import javax.servlet.RequestDispatcher;
026 import javax.servlet.ServletException;
027 import javax.servlet.http.HttpServlet;
028 import javax.servlet.http.HttpServletRequest;
029 import javax.servlet.http.HttpServletResponse;
030 
031 import org.apache.log4j.Level;
032 import org.apache.log4j.Logger;
033 import org.apache.qpid.qman.debug.WsdlDebugger;
034 import org.apache.qpid.qman.debug.XmlDebugger;
035 
036 /**
037  * Logging configuration controller.
038  * Accepts input parameters from admin console and configure the underlying
039  * logging subsystem at runtime.
040  
041  @author Andrea Gazzarini
042  */
043 public class LoggingConfigurationAction extends HttpServlet
044 {
045   private static final long serialVersionUID = 633352305870632824L;
046 
047   private final static String WSDL_DEBUG_ENABLED_PARAM = "wsdlDebugEnabled";
048   private final static String SOAP_DEBUG_ENABLED_PARAM = "soapDebugEnabled";
049   private final static String WEB_SERVER_LOG_LEVEL_PARAM = "webServerLogLevel";
050   private final static String QMAN_LOG_LEVEL_PARAM = "qmanLogLevel";
051   
052   private final static String WEB_SERVER_PACKAGE = "org.mortbay";
053   private final static String QMAN_PACKAGE = "org.qpid.apache.management";
054   
055   /**
056    * Retrieves current logging configuration and forward those data to the logging configuration view page.
057    * In this way that page will be able to display the current logging settings.
058    
059    @param request the http request.
060    @param response the http response.
061    @throws ServletException when this controller is not able to forward to the appropriate view page.
062    @throws IOException when this controller is not able to forward to the appropriate view page.
063    */
064   protected void doGet(HttpServletRequest request, HttpServletResponse responsethrows ServletException, IOException
065   {
066     Level messageDebuggerLogLevel = Logger.getLogger(XmlDebugger.class).getEffectiveLevel();
067     Level wsdlDebuggerLogLevel = Logger.getLogger(WsdlDebugger.class).getEffectiveLevel();    
068     Level webServerLogLevel = Logger.getLogger(WEB_SERVER_PACKAGE).getEffectiveLevel();    
069     Level qmanLogLevel = Logger.getLogger(QMAN_PACKAGE).getEffectiveLevel();    
070     
071     request.setAttribute(WSDL_DEBUG_ENABLED_PARAM,wsdlDebuggerLogLevel.equals(Level.DEBUG));
072     request.setAttribute(SOAP_DEBUG_ENABLED_PARAM,messageDebuggerLogLevel.equals(Level.DEBUG));
073     request.setAttribute(WEB_SERVER_LOG_LEVEL_PARAM,webServerLogLevel);
074     request.setAttribute(QMAN_LOG_LEVEL_PARAM,qmanLogLevel);    
075     
076     RequestDispatcher dispatcher = request.getRequestDispatcher("/logging_configuration.jsp");
077     dispatcher.forward(request, response);
078   }
079   
080   /**
081    * Accepts user data coming from admin console and use it for configure the underlying logging 
082    * subsystem.
083    
084    @param request the http request.
085    @param response the http response.
086    @throws ServletException when this controller is not able to forward to the appropriate view page.
087    @throws IOException when this controller is not able to forward to the appropriate view page.
088    */
089   @Override
090   protected void doPost(HttpServletRequest request, HttpServletResponse responsethrows ServletException, IOException
091   {
092     String wsdlDebugEnabled = request.getParameter(WSDL_DEBUG_ENABLED_PARAM);
093     String soapDebugEnabled = request.getParameter(SOAP_DEBUG_ENABLED_PARAM);
094     
095     String qmanLevel = request.getParameter(QMAN_LOG_LEVEL_PARAM);
096     String serverLevel = request.getParameter(WEB_SERVER_LOG_LEVEL_PARAM);
097     
098     Logger.getLogger(WEB_SERVER_PACKAGE).setLevel(Level.toLevel(serverLevel));
099     Logger.getLogger(QMAN_PACKAGE).setLevel(Level.toLevel(qmanLevel));
100     
101     Logger.getLogger(WsdlDebugger.class).setLevel(
102         "on".equals(wsdlDebugEnabled)
103           ? Level.DEBUG
104           : Level.INFO);
105 
106     Logger.getLogger(XmlDebugger.class).setLevel(
107         "on".equals(soapDebugEnabled)
108           ? Level.DEBUG
109           : Level.INFO);
110     
111     doGet(request, response);
112   }
113 }
114