Skip to content

Commit 263271d

Browse files
committed
[refactor] Address minor code quality items
1 parent e96da7f commit 263271d

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

exist-core/src/main/java/org/exist/management/client/JMXServlet.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@
5454
* A servlet to monitor the database. It returns status information for the database based on the JMX interface. For
5555
* simplicity, the JMX beans provided by eXist are organized into categories. One calls the servlet with one or more
5656
* categories in parameter "c", e.g.:
57-
*
57+
* <p>
5858
* /exist/jmx?c=instances&amp;c=memory
59-
*
59+
* <p>
6060
* If no parameter is specified, all categories will be returned. Valid categories are "memory", "instances", "disk",
6161
* "system", "caches", "locking", "processes", "sanity", "all".
62-
*
62+
* <p>
6363
* The servlet can also be used to test if the database is responsive by using parameter "operation=ping" and a timeout
6464
* (t=timeout-in-milliseconds). For example, the following call
65-
*
65+
* <p>
6666
* /exist/jmx?operation=ping&amp;t=1000
67-
*
67+
* <p>
6868
* will wait for a response within 1000ms. If the ping returns within the specified timeout, the servlet returns the
6969
* attributes of the SanityReport JMX bean, which will include an element &lt;jmx:Status&gt;PING_OK&lt;/jmx:Status&gt;.
7070
* If the ping takes longer than the timeout, you'll instead find an element &lt;jmx:error&gt; in the returned XML. In
7171
* this case, additional information on running queries, memory consumption and database locks will be provided.
72-
*
72+
* <p>
7373
* @author wolf
7474
*/
7575
public class JMXServlet extends HttpServlet {
@@ -92,10 +92,9 @@ public class JMXServlet extends HttpServlet {
9292

9393
private Path dataDir;
9494
private Path tokenFile;
95-
96-
95+
9796
@Override
98-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
97+
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
9998

10099
// Verify if request is from localhost or if user has specific servlet/container managed role.
101100
if (isFromLocalHost(request)) {
@@ -116,8 +115,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
116115
writeXmlData(request, response);
117116
}
118117

119-
private void writeXmlData(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
120-
Element root = null;
118+
private void writeXmlData(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
119+
Element root;
121120

122121
final String operation = request.getParameter("operation");
123122
if ("ping".equals(operation)) {
@@ -143,15 +142,15 @@ private void writeXmlData(HttpServletRequest request, HttpServletResponse respon
143142
if (mbean == null) {
144143
throw new ServletException("to call an operation, you also need to specify parameter 'mbean'");
145144
}
146-
String[] args = request.getParameterValues("args");
145+
final String[] args = request.getParameterValues("args");
147146
try {
148147
root = client.invoke(mbean, operation, args);
149148
if (root == null) {
150149
throw new ServletException("operation " + operation + " not found on " + mbean);
151150
}
152-
} catch (InstanceNotFoundException e) {
151+
} catch (final InstanceNotFoundException e) {
153152
throw new ServletException("mbean " + mbean + " not found: " + e.getMessage(), e);
154-
} catch (MalformedObjectNameException | IntrospectionException | ReflectionException | MBeanException e) {
153+
} catch (final MalformedObjectNameException | IntrospectionException | ReflectionException | MBeanException e) {
155154
throw new ServletException(e.getMessage(), e);
156155
}
157156
} else {
@@ -182,7 +181,7 @@ private void writeXmlData(HttpServletRequest request, HttpServletResponse respon
182181
}
183182

184183
@Override
185-
public void init(ServletConfig config) throws ServletException {
184+
public void init(final ServletConfig config) throws ServletException {
186185
super.init(config);
187186

188187
// Setup JMS client
@@ -228,10 +227,10 @@ void registerLocalHostAddresses() {
228227
} else {
229228
localhostAddresses.add(hostAddress);
230229
}
231-
}
232-
}
230+
}
231+
}
233232

234-
}
233+
}
235234
}
236235

237236
} catch (final SocketException e) {
@@ -251,7 +250,7 @@ void registerLocalHostAddresses() {
251250
* @param request The HTTP request
252251
* @return TRUE if request is from LOCALHOST otherwise FALSE
253252
*/
254-
boolean isFromLocalHost(HttpServletRequest request) {
253+
boolean isFromLocalHost(final HttpServletRequest request) {
255254
String remoteAddr = request.getRemoteAddr();
256255
remoteAddr = remoteAddr.startsWith("[") ? remoteAddr.substring(1, remoteAddr.length() - 1) : remoteAddr;
257256
return localhostAddresses.contains(remoteAddr);
@@ -263,8 +262,8 @@ boolean isFromLocalHost(HttpServletRequest request) {
263262
* @param request The HTTP request
264263
* @return TRUE if request contains correct value for token, else FALSE
265264
*/
266-
boolean hasSecretToken(HttpServletRequest request, String token) {
267-
String[] tokenValue = request.getParameterValues(TOKEN_KEY);
265+
boolean hasSecretToken(final HttpServletRequest request, final String token) {
266+
final String[] tokenValue = request.getParameterValues(TOKEN_KEY);
268267
return ArrayUtils.contains(tokenValue, token);
269268
}
270269

@@ -286,7 +285,7 @@ private void obtainTokenFileReference() {
286285
*/
287286
private String getToken() {
288287

289-
Properties props = new Properties();
288+
final Properties props = new Properties();
290289
String token = null;
291290

292291
// Read if possible
@@ -295,7 +294,7 @@ private String getToken() {
295294
try (final InputStream is = Files.newInputStream(tokenFile)) {
296295
props.load(is);
297296
token = props.getProperty(TOKEN_KEY);
298-
} catch (IOException ex) {
297+
} catch (final IOException ex) {
299298
LOG.error(ex.getMessage());
300299
}
301300

@@ -313,7 +312,7 @@ private String getToken() {
313312
// Write data to file
314313
try (final OutputStream os = Files.newOutputStream(tokenFile)) {
315314
props.store(os, "JMXservlet token: http://localhost:8080/exist/status?token=......");
316-
} catch (IOException ex) {
315+
} catch (final IOException ex) {
317316
LOG.error(ex.getMessage());
318317
}
319318

0 commit comments

Comments
 (0)