1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.catalina.mbeans;
18
19 import javax.management.MBeanException;
20
21 import org.apache.catalina.Context;
22 import org.apache.tomcat.util.descriptor.web.ApplicationParameter;
23 import org.apache.tomcat.util.descriptor.web.ErrorPage;
24 import org.apache.tomcat.util.descriptor.web.FilterDef;
25 import org.apache.tomcat.util.descriptor.web.FilterMap;
26 import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
27
28 public class ContextMBean extends BaseCatalinaMBean<Context> {
29
30 /**
31 * Return the set of application parameters for this application.
32 * @return a string array with a representation of each parameter
33 * @throws MBeanException propagated from the managed resource access
34 */
35 public String[] findApplicationParameters() throws MBeanException {
36
37 Context context = doGetManagedResource();
38
39 ApplicationParameter[] params = context.findApplicationParameters();
40 String[] stringParams = new String[params.length];
41 for (int counter = 0; counter < params.length; counter++) {
42 stringParams[counter] = params[counter].toString();
43 }
44
45 return stringParams;
46 }
47
48
49 /**
50 * Return the security constraints for this web application.
51 * If there are none, a zero-length array is returned.
52 * @return a string array with a representation of each
53 * security constraint
54 * @throws MBeanException propagated from the managed resource access
55 */
56 public String[] findConstraints() throws MBeanException {
57
58 Context context = doGetManagedResource();
59
60 SecurityConstraint[] constraints = context.findConstraints();
61 String[] stringConstraints = new String[constraints.length];
62 for (int counter = 0; counter < constraints.length; counter++) {
63 stringConstraints[counter] = constraints[counter].toString();
64 }
65
66 return stringConstraints;
67 }
68
69
70 /**
71 * Return the error page entry for the specified HTTP error code,
72 * if any; otherwise return <code>null</code>.
73 *
74 * @param errorCode Error code to look up
75 * @return a string representation of the error page
76 * @throws MBeanException propagated from the managed resource access
77 */
78 public String findErrorPage(int errorCode) throws MBeanException {
79 Context context = doGetManagedResource();
80 return context.findErrorPage(errorCode).toString();
81 }
82
83
84 /**
85 * Return the error page entry for the specified Java exception type,
86 * if any; otherwise return <code>null</code>.
87 *
88 * @param exceptionType Exception type to look up
89 * @return a string representation of the error page
90 * @throws MBeanException propagated from the managed resource access
91 * @deprecated Unused. Will be removed in Tomcat 10.
92 * Use {@link #findErrorPage(Throwable)} instead.
93 */
94 @Deprecated
95 public String findErrorPage(String exceptionType) throws MBeanException {
96 Context context = doGetManagedResource();
97 return context.findErrorPage(exceptionType).toString();
98 }
99
100
101 /**
102 * Return the error page entry for the specified Java exception type,
103 * if any; otherwise return <code>null</code>.
104 *
105 * @param exceptionType Exception type to look up
106 * @return a string representation of the error page
107 * @throws MBeanException propagated from the managed resource access
108 */
109 public String findErrorPage(Throwable exceptionType) throws MBeanException {
110 Context context = doGetManagedResource();
111 return context.findErrorPage(exceptionType).toString();
112 }
113
114
115 /**
116 * Return the set of defined error pages for all specified error codes
117 * and exception types.
118 * @return a string array with a representation of each error page
119 * @throws MBeanException propagated from the managed resource access
120 */
121 public String[] findErrorPages() throws MBeanException {
122
123 Context context = doGetManagedResource();
124
125 ErrorPage[] pages = context.findErrorPages();
126 String[] stringPages = new String[pages.length];
127 for (int counter = 0; counter < pages.length; counter++) {
128 stringPages[counter] = pages[counter].toString();
129 }
130
131 return stringPages;
132 }
133
134
135 /**
136 * Return the filter definition for the specified filter name, if any;
137 * otherwise return <code>null</code>.
138 *
139 * @param name Filter name to look up
140 * @return a string representation of the filter definition
141 * @throws MBeanException propagated from the managed resource access
142 */
143 public String findFilterDef(String name) throws MBeanException {
144
145 Context context = doGetManagedResource();
146
147 FilterDef filterDef = context.findFilterDef(name);
148 return filterDef.toString();
149 }
150
151
152 /**
153 * Return the set of defined filters for this Context.
154 * @return a string array with a representation of all
155 * the filter definitions
156 * @throws MBeanException propagated from the managed resource access
157 */
158 public String[] findFilterDefs() throws MBeanException {
159
160 Context context = doGetManagedResource();
161
162 FilterDef[] filterDefs = context.findFilterDefs();
163 String[] stringFilters = new String[filterDefs.length];
164 for (int counter = 0; counter < filterDefs.length; counter++) {
165 stringFilters[counter] = filterDefs[counter].toString();
166 }
167
168 return stringFilters;
169 }
170
171
172 /**
173 * Return the set of filter mappings for this Context.
174 * @return a string array with a representation of all the filter mappings
175 * @throws MBeanException propagated from the managed resource access
176 */
177 public String[] findFilterMaps() throws MBeanException {
178
179 Context context = doGetManagedResource();
180
181 FilterMap[] maps = context.findFilterMaps();
182 String[] stringMaps = new String[maps.length];
183 for (int counter = 0; counter < maps.length; counter++) {
184 stringMaps[counter] = maps[counter].toString();
185 }
186
187 return stringMaps;
188 }
189 }
190