summaryrefslogtreecommitdiff
path: root/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/LoggingConfigurationAction.java
blob: aefd4ca8dd001c87e8f3a651eb78430ecd8d97ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.management.web.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.qpid.qman.debug.WsdlDebugger;
import org.apache.qpid.qman.debug.XmlDebugger;

/**
 * Logging configuration controller.
 * Accepts input parameters from admin console and configure the underlying
 * logging subsystem at runtime.
 * 
 * @author Andrea Gazzarini
 */
public class LoggingConfigurationAction extends HttpServlet
{
	private static final long serialVersionUID = 633352305870632824L;

	private final static String WSDL_DEBUG_ENABLED_PARAM = "wsdlDebugEnabled";
	private final static String SOAP_DEBUG_ENABLED_PARAM = "soapDebugEnabled";
	private final static String WEB_SERVER_LOG_LEVEL_PARAM = "webServerLogLevel";
	private final static String QMAN_LOG_LEVEL_PARAM = "qmanLogLevel";
	
	private final static String WEB_SERVER_PACKAGE = "org.mortbay";
	private final static String QMAN_PACKAGE = "org.qpid.apache.management";
	
	/**
	 * Retrieves current logging configuration and forward those data to the logging configuration view page.
	 * In this way that page will be able to display the current logging settings.
	 * 
	 * @param request the http request.
	 * @param response the http response.
	 * @throws ServletException when this controller is not able to forward to the appropriate view page.
	 * @throws IOException when this controller is not able to forward to the appropriate view page.
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Level messageDebuggerLogLevel = Logger.getLogger(XmlDebugger.class).getEffectiveLevel();
		Level wsdlDebuggerLogLevel = Logger.getLogger(WsdlDebugger.class).getEffectiveLevel();		
		Level webServerLogLevel = Logger.getLogger(WEB_SERVER_PACKAGE).getEffectiveLevel();		
		Level qmanLogLevel = Logger.getLogger(QMAN_PACKAGE).getEffectiveLevel();		
		
		request.setAttribute(WSDL_DEBUG_ENABLED_PARAM,wsdlDebuggerLogLevel.equals(Level.DEBUG));
		request.setAttribute(SOAP_DEBUG_ENABLED_PARAM,messageDebuggerLogLevel.equals(Level.DEBUG));
		request.setAttribute(WEB_SERVER_LOG_LEVEL_PARAM,webServerLogLevel);
		request.setAttribute(QMAN_LOG_LEVEL_PARAM,qmanLogLevel);		
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("/logging_configuration.jsp");
		dispatcher.forward(request, response);
	}
	
	/**
	 * Accepts user data coming from admin console and use it for configure the underlying logging 
	 * subsystem.
	 * 
	 * @param request the http request.
	 * @param response the http response.
	 * @throws ServletException when this controller is not able to forward to the appropriate view page.
	 * @throws IOException when this controller is not able to forward to the appropriate view page.
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String wsdlDebugEnabled = request.getParameter(WSDL_DEBUG_ENABLED_PARAM);
		String soapDebugEnabled = request.getParameter(SOAP_DEBUG_ENABLED_PARAM);
		
		String qmanLevel = request.getParameter(QMAN_LOG_LEVEL_PARAM);
		String serverLevel = request.getParameter(WEB_SERVER_LOG_LEVEL_PARAM);
		
		Logger.getLogger(WEB_SERVER_PACKAGE).setLevel(Level.toLevel(serverLevel));
		Logger.getLogger(QMAN_PACKAGE).setLevel(Level.toLevel(qmanLevel));
		
		Logger.getLogger(WsdlDebugger.class).setLevel(
				"on".equals(wsdlDebugEnabled)
					? Level.DEBUG
					: Level.INFO);

		Logger.getLogger(XmlDebugger.class).setLevel(
				"on".equals(soapDebugEnabled)
					? Level.DEBUG
					: Level.INFO);
		
		doGet(request, response);
	}
}