Skip to content

Instantly share code, notes, and snippets.

@andreybpanfilov
Created June 15, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreybpanfilov/d6a616202bde7a49a80c26dc62daa61d to your computer and use it in GitHub Desktop.
Save andreybpanfilov/d6a616202bde7a49a80c26dc62daa61d to your computer and use it in GitHub Desktop.
<%@ page import="java.io.ByteArrayOutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.lang.reflect.Field" %>
<%@ page import="com.documentum.fc.common.DfPreferences" %>
<%@ page import="com.documentum.fc.common.DfRuntimeException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>DFC Diagnostics</title>
</head>
<body>
<%!
static Field getField(Class<?> clazz, String fieldName) {
Class<?> cls = clazz;
while (true) {
try {
Field field = cls.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
if (cls == Object.class) {
throw DfRuntimeException.convertToRuntimeException(ex);
}
cls = cls.getSuperclass();
}
}
}
%>
<%
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
boolean enabled = false;
try {
Class sessionHandle = Class.forName("com.documentum.fc.client.impl.session.StrongSessionHandle");
Class collectionHandle = Class.forName("com.documentum.fc.client.impl.collection.CollectionHandle");
if (request.getParameterMap().containsKey("submit")) {
boolean enable = false;
if (request.getParameterMap().containsKey("enable")) {
Object values = request.getParameterMap().get("enable");
if (values != null && values instanceof String[]) {
enable = "on".equals(((String[]) values)[0]);
}
}
DfPreferences.getInstance().loadProperty(DfPreferences.DFC_DIAGNOSTICS_RESOURCES_ENABLE, String.valueOf(enable));
getField(sessionHandle, "s_saveStacks").set(null, enable);
getField(sessionHandle, "s_watchForLeaks").set(null, enable);
getField(collectionHandle, "s_saveStacks").set(null, enable);
getField(collectionHandle, "s_watchForLeaks").set(null, enable);
}
enabled = (Boolean) getField(sessionHandle, "s_saveStacks").get(null);
enabled &= (Boolean) getField(sessionHandle, "s_watchForLeaks").get(null);
enabled &= (Boolean) getField(collectionHandle, "s_saveStacks").get(null);
enabled &= (Boolean) getField(collectionHandle, "s_watchForLeaks").get(null);
enabled &= DfPreferences.getInstance().areResourceDiagnosticsEnabled();
} catch (Throwable ex) {
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(errorStream));
ex.printStackTrace(printWriter);
printWriter.flush();
printWriter.close();
}
%>
<%
if (errorStream.size() > 0) {
%>
<pre>
<%= new String(errorStream.toByteArray())%>
</pre>
<%
}
%>
<form action="<%=request.getRequestURI()%>" method="post">
<table>
<tr>
<td>Enabled:</td>
<td><input type="checkbox" name="enable" <%=enabled ? "checked" : ""%>/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit"/></td>
</tr>
</table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment