use of com.alibaba.fastjson2.JSON in project druid by alibaba.
the class Oracle_param_2 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "SELECT TO_DATE('2013-02-11', 'YYYY-MM-DD') FROM dual;";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement statement = stmtList.get(0);
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.ORACLE);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
/*visitor.setPrettyFormat(false);*/
statement.accept(visitor);
/* JSONArray array = new JSONArray();
for(String table : visitor.getTables()){
array.add(table.replaceAll("`",""));
}*/
String psql = out.toString();
assertEquals("SELECT TO_DATE(?, 'YYYY-MM-DD')\n" + "FROM dual;", psql);
String params_json = JSON.toJSONString(parameters, JSONWriter.Feature.WriteClassName);
System.out.println(params_json);
JSONArray jsonArray = JSON.parseArray(params_json);
String json = JSON.toJSONString(jsonArray, JSONWriter.Feature.WriteClassName);
assertEquals("[\"2013-02-11\"]", json);
String rsql = SQLUtils.toSQLString(SQLUtils.parseStatements(psql, dbType), dbType, jsonArray);
assertEquals("SELECT TO_DATE('2013-02-11', 'YYYY-MM-DD')\n" + "FROM dual;", rsql);
}
use of com.alibaba.fastjson2.JSON in project druid by alibaba.
the class MonitorStatService method service.
@Override
public String service(String url) {
Map<String, String> parameters = getParameters(url);
if (url.endsWith("serviceList.json")) {
return JSON.toJSONString(monitorProperties.getApplications());
}
if (url.equals("/datasource.json")) {
String serviceName = StringUtils.subString(url, "serviceName=", "&sql-");
Integer id = StringUtils.subStringToInteger(url, "datasource-", ".");
return getDataSourceStatData();
}
if (url.startsWith("/datasource-")) {
String serviceName = StringUtils.subString(url, "serviceName=", "&sql-");
Integer id = StringUtils.subStringToInteger(url, "datasource-", ".");
Object result = getDataSourceStatData();
return returnJSONResult(result == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, result);
}
// 活跃连接数查看
if (url.startsWith("/connectionInfo-") && url.endsWith(".json")) {
String serviceId = StringUtils.subString(url, "&serviceId=", ".json");
Integer id = StringUtils.subStringToInteger(url, "connectionInfo-", "&");
return getPoolingConnectionInfoByDataSourceId(id, serviceId);
}
// SQL监控列表
if (url.startsWith("/sql.json")) {
return getSqlStatDataList(parameters);
}
// SQL防火墙
if (url.startsWith("/wall.json")) {
return getWallStatMap(parameters);
}
// SQL详情
if (url.startsWith("/serviceId") && url.indexOf(".json") > 0) {
String serviceId = StringUtils.subString(url, "serviceId=", "&");
Integer id = StringUtils.subStringToInteger(url, "sql-", ".json");
return getSqlStat(id, serviceId);
}
if (url.startsWith("/weburi.json")) {
return getWebURIStatDataList(parameters);
}
if (url.startsWith("/weburi-") && url.indexOf(".json") > 0) {
String uri = StringUtils.subString(url, "weburi-", ".json", true);
return returnJSONResult(RESULT_CODE_SUCCESS, getWebURIStatData(uri));
}
if (url.startsWith("/webapp.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getWebAppStatDataList(parameters));
}
if (url.startsWith("/websession.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionStatDataList(parameters));
}
if (url.startsWith("/websession-") && url.indexOf(".json") > 0) {
String id = StringUtils.subString(url, "websession-", ".json");
return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionStatData(id));
}
if (url.startsWith("/spring.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getSpringStatDataList(parameters));
}
if (url.startsWith("/spring-detail.json")) {
String clazz = parameters.get("class");
String method = parameters.get("method");
return returnJSONResult(RESULT_CODE_SUCCESS, getSpringMethodStatData(clazz, method));
}
return returnJSONResult(RESULT_CODE_ERROR, "Do not support this request, please contact with administrator.");
}
use of com.alibaba.fastjson2.JSON in project RuoYi-Vue by yangzongzhuan.
the class AddressUtils method getRealAddressByIP.
public static String getRealAddressByIP(String ip) {
// 内网不查询
if (IpUtils.internalIp(ip)) {
return "内网IP";
}
if (RuoYiConfig.isAddressEnabled()) {
try {
String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
if (StringUtils.isEmpty(rspStr)) {
log.error("获取地理位置异常 {}", ip);
return UNKNOWN;
}
JSONObject obj = JSON.parseObject(rspStr);
String region = obj.getString("pro");
String city = obj.getString("city");
return String.format("%s %s", region, city);
} catch (Exception e) {
log.error("获取地理位置异常 {}", ip);
}
}
return UNKNOWN;
}
Aggregations