totally remove server side html content replacement

This commit is contained in:
shrek.wang
2012-08-16 10:11:18 +08:00
parent fd4c1eff90
commit cec81dd657
9 changed files with 32 additions and 67 deletions
@@ -4,23 +4,15 @@ import com.alibaba.druid.util.IpUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.alibaba.druid.support.JSONDruidStatService;
import com.alibaba.druid.util.IOUtils;
import com.alibaba.druid.util.StringUtils;
/**
* 注意:避免直接调用Druid相关对象例如DruidDataSource等,相关调用要到DruidStatManagerFacade里用反射实现
@@ -112,52 +104,12 @@ public class StatViewServlet extends HttpServlet {
response.getWriter().print(jsonDruidStatService.service(fullUrl));
return;
}
if (path.startsWith("/connectionInfo-") && path.endsWith(".html")) {
Integer id = StringUtils.subStringToInteger(path, "connectionInfo-", ".");
returnViewConnectionInfo(id, request, response);
return;
}
if (path.startsWith("/activeConnectionStackTrace-") && path.endsWith(".html")) {
Integer id = StringUtils.subStringToInteger(path, "activeConnectionStackTrace-", ".");
returnViewActiveConnectionStackTrace(id, request, response);
return;
}
if (path.startsWith("/sql-") && path.endsWith(".html")) {
Integer id = StringUtils.subStringToInteger(path, "sql-", ".");
returnViewSqlStat(id, request,response);
return;
}
// find file in resources path
returnResourceFile(path, uri, response);
}
private void returnViewActiveConnectionStackTrace(Integer id, HttpServletRequest request,
HttpServletResponse response) throws IOException {
String text = IOUtils.readFromResource(RESOURCE_PATH + "/activeConnectionStackTrace.html");
text = text.replaceAll("\\{datasourceId\\}", id.toString());
response.getWriter().print(text);
}
private void returnViewConnectionInfo(Integer id, HttpServletRequest request, HttpServletResponse response)
throws IOException {
String text = IOUtils.readFromResource(RESOURCE_PATH + "/connectionInfo.html");
text = text.replaceAll("\\{datasourceId\\}", id.toString());
response.getWriter().print(text);
}
private void returnViewSqlStat(Integer id, HttpServletRequest request, HttpServletResponse response) throws IOException {
String text = IOUtils.readFromResource(RESOURCE_PATH + "/sqlDetail.html");
text = text.replaceAll("\\{sqlId\\}", id.toString());
response.getWriter().print(text);
}
private void returnResourceFile(String fileName, String uri, HttpServletResponse response) throws ServletException, IOException {
String text = IOUtils.readFromResource(RESOURCE_PATH + fileName);
if(text == null) {
@@ -8,8 +8,8 @@
<script src="js/connectionInfo.js" type="text/javascript" charset="utf8"></script>
<script >
function init(){
ajaxRequestForConnectionInfo({datasourceId});
var time3=setInterval("ajaxRequestForConnectionInfo({datasourceId});",1000);
ajaxRequestForConnectionInfo();
var time3=setInterval("ajaxRequestForConnectionInfo();",1000);
}
</script>
</head>
@@ -49,4 +49,4 @@
</div>
<div id="footer">powered by <a href="mailto:sandzhangtoo@gmail.com">sandzhang</a></div>
</body>
</html>
</html>
@@ -1,4 +1,5 @@
function ajaxRequestForActiveConnectionStackTrace(datasourceId) {
function ajaxRequestForActiveConnectionStackTrace() {
var datasourceId = getUrlVar("datasourceId");
var xmlHttpForActiveConnectionStackTrace=getRequestObject();
sendRequest(xmlHttpForActiveConnectionStackTrace,'activeConnectionStackTrace-' + datasourceId + '.json', function() {
ajaxResponseForActiveConnectionStackTrace(xmlHttpForActiveConnectionStackTrace, datasourceId);
@@ -20,4 +21,4 @@ function ajaxResponseForActiveConnectionStackTrace(xmlHttpForActiveConnectionSta
newRow.insertCell(-1).innerHTML = conntionStackTrace;
}
}
}
@@ -60,4 +60,14 @@ function ajaxResponseForReset() {
alert("already reset all stat");
}
}
}
function getUrlVar(name) {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars[name];
}
@@ -72,7 +72,8 @@ function getSqlViewJsonUrl() {
return result;
}
function ajaxRequestForConnectionInfo(datasourceId) {
function ajaxRequestForConnectionInfo() {
var datasourceId = getUrlVar("datasourceId");
xmlHttpForConnectionInfo = getRequestObject();
sendRequest(xmlHttpForConnectionInfo, 'connectionInfo-' + datasourceId + '.json', ajaxResponseForConnectionInfo)
}
@@ -124,4 +125,4 @@ function ajaxResponseForConnectionInfo() {
else
newRow.insertCell(-1).innerHTML = '';
}
}
}
@@ -66,7 +66,7 @@ function fillDataSourceInfo(datasource) {
changeInnerHtml("DS-Info-ConnectionHoldTimeHistogram" + datasource.Identity, '[' + datasource.ConnectionHoldTimeHistogram + ']');
if (datasource.RemoveAbandoned == true)
changeInnerHtml("DS-Info-ActiveConnectionStackTrace" + datasource.Identity, '<a href="activeConnectionStackTrace-' + datasource.Identity + '.html">View</a>');
changeInnerHtml("DS-Info-ActiveConnectionStackTrace" + datasource.Identity, '<a href="activeConnectionStackTrace.html?datasourceId=' + datasource.Identity + '">View</a>');
else
changeInnerHtml("DS-Info-ActiveConnectionStackTrace" + datasource.Identity, "require set removeAbandoned=true");
@@ -139,8 +139,8 @@ function generateDataSourceDiv(datasource) {
listHtml += '<tr><td class="td_lable">ActiveConnection StackTrace</td><td id="DS-Info-ActiveConnectionStackTrace' + datasourceId + '">&nbsp;</td><td>StackTrace for active Connection. <a href="activeConnectionStackTrace-'
+ datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>';
listHtml += '<tr><td class="td_lable">PollingConnection Info</td><td id="DS-Info-PollingConnectionInfo' + datasourceId + '"><a href="connectionInfo-' + datasourceId
+ '.html">View</a></td><td>Info for polling connection. <a href="connectionInfo-' + datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>';
listHtml += '<tr><td class="td_lable">PollingConnection Info</td><td id="DS-Info-PollingConnectionInfo' + datasourceId + '"><a href="connectionInfo.html?datasourceId=' + datasourceId
+ '">View</a></td><td>Info for polling connection. <a href="connectionInfo-' + datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>';
listHtml += '</table>';
listHtml += '</div>';
@@ -95,7 +95,7 @@ function ajaxResponseForDataSourceSqlStatInfo() {
var sqlStat = sqlStatList[i];
var newRow = sqlStatTable.insertRow(-1);
newRow.insertCell(-1).innerHTML = i+1;
newRow.insertCell(-1).innerHTML = '<a target="_blank" href="sql-' + sqlStat.ID + '.html">' + subSqlString(sqlStat.SQL, 25) + '</a>';
newRow.insertCell(-1).innerHTML = '<a target="_blank" href="sqlDetail.html?sqlId=' + sqlStat.ID + '">' + subSqlString(sqlStat.SQL, 25) + '</a>';
// if (sqlStat.File)
// newRow.insertCell(-1).innerHTML = sqlStat.File;
// else
@@ -109,7 +109,7 @@ function ajaxResponseForDataSourceSqlStatInfo() {
//显示执行的时间比配置的均值时间慢的SQL链接
var lastSlowHtml = sqlStat.MaxTimespan;
if(sqlStat.LastSlowParameters!=null&&sqlStat.LastSlowParameters.length>0){
lastSlowHtml ='<a target="_blank" style="color:red" href="sql-' + sqlStat.ID + '.html">'+sqlStat.MaxTimespan+'</a>';
lastSlowHtml ='<a target="_blank" style="color:red" href="sqlDetail.html?sqlId=' + sqlStat.ID + '">'+sqlStat.MaxTimespan+'</a>';
}
newRow.insertCell(-1).innerHTML = lastSlowHtml;
newRow.insertCell(-1).innerHTML = sqlStat.InTransactionCount;
@@ -130,4 +130,4 @@ function ajaxResponseForDataSourceSqlStatInfo() {
newRow.insertCell(-1).innerHTML = '[' + sqlStat.FetchRowCountHistogram + ']';
newRow.insertCell(-1).innerHTML = '[' + sqlStat.EffectedRowCountHistogram + ']';
}
}
}
@@ -1,6 +1,7 @@
function ajaxRequestForSqlInfo(datasourceId) {
function ajaxRequestForSqlInfo() {
var sqlId = getUrlVar("sqlId");
xmlHttpForConnectionInfo = getRequestObject();
sendRequest(xmlHttpForConnectionInfo, 'sql-' + datasourceId + '.json', ajaxResponseForSqlInfo)
sendRequest(xmlHttpForConnectionInfo, 'sql-' + sqlId + '.json', ajaxResponseForSqlInfo)
}
function ajaxResponseForSqlInfo() {
@@ -8,8 +8,8 @@
<script src="js/sqlDetail.js" type="text/javascript" charset="utf8"></script>
<script >
function init(){
ajaxRequestForSqlInfo({sqlId});
var time3=setInterval("ajaxRequestForSqlInfo({sqlId});",5000);
ajaxRequestForSqlInfo();
var time3=setInterval("ajaxRequestForSqlInfo();",5000);
}
</script>
</head>