Правка приёма JSON
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
package kz.locust.CCALM; //Главная
|
package com.geovizor.monitoring; //Главная 2
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -29,8 +29,8 @@ import java.util.Random;
|
|||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import jakarta.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
@ -48,7 +48,10 @@ import javax.xml.xpath.XPathFactory;
|
|||||||
//import org.apache.commons.fileupload.FileItem;
|
//import org.apache.commons.fileupload.FileItem;
|
||||||
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
@ -94,9 +97,15 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
return new User("none");
|
return new User("none");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/
|
public String sendError(int code, String message) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("errorCode",code);
|
||||||
|
json.put("errorMessage",message);
|
||||||
|
return json.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/records",method = RequestMethod.POST,produces = "application/xml; charset=utf-8")
|
//Документация по @RequestBody http://javastudy.ru/spring-mvc/json-xml/ application/xml
|
||||||
|
@RequestMapping(value = "/records.php",method = {RequestMethod.POST,RequestMethod.GET},produces = "text/plain; charset=utf-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object ajaxTamer(@ModelAttribute User user,@RequestBody byte[] reqData,@RequestParam(required=false,name="lng") String language_id) {
|
public Object ajaxTamer(@ModelAttribute User user,@RequestBody byte[] reqData,@RequestParam(required=false,name="lng") String language_id) {
|
||||||
|
|
||||||
@ -105,7 +114,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id+" user.country_id="+user.country_id);
|
logger.info("user.id="+user.id+" user.name="+user.name+" user.language_id="+user.language_id+" user.country_id="+user.country_id);
|
||||||
|
|
||||||
boolean error=false;
|
boolean error=false;
|
||||||
String result="<metadata fn=\"-1\"><![CDATA[Request not processed!]]></metadata>";
|
String result=sendError(1,"Request not processed!");
|
||||||
//response.setCharacterEncoding("UTF-8");
|
//response.setCharacterEncoding("UTF-8");
|
||||||
|
|
||||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||||
@ -114,15 +123,39 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
String db_url = "";
|
String db_url = "";
|
||||||
String db_login = "";
|
String db_login = "";
|
||||||
String db_password = "";
|
String db_password = "";
|
||||||
|
String data_dir = "";
|
||||||
|
Properties prop = new Properties();
|
||||||
|
InputStream input = null;
|
||||||
|
try {
|
||||||
|
prop.load(new FileInputStream("monitoring.properties")); // load a properties file
|
||||||
|
//Читаю настройки базы
|
||||||
|
db_url = prop.getProperty("db.url");
|
||||||
|
System.out.println("db.url = " + db_url);
|
||||||
|
//dbSchema = prop.getProperty("db.schema");
|
||||||
|
//System.out.println("db.schema = " + dbSchema);
|
||||||
|
db_login = prop.getProperty("db.login");
|
||||||
|
System.out.println("db.login = " + db_login);
|
||||||
|
db_password = prop.getProperty("db.password");
|
||||||
|
//System.out.println("db.password = " + db_password);
|
||||||
|
data_dir = prop.getProperty("data-dir");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
/*if (input != null) {
|
||||||
|
try {
|
||||||
|
input.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
String mail_host = "";
|
String mail_host = "";
|
||||||
String mail_port = "";
|
String mail_port = "";
|
||||||
String mail_login = "";
|
String mail_login = "";
|
||||||
String mail_password = "";
|
String mail_password = "";
|
||||||
String data_dir = "";
|
|
||||||
//Load DB configuration from "config.xml"
|
//Load DB configuration from "config.xml"
|
||||||
try {
|
/*try {
|
||||||
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
|
|
||||||
//File fXmlFile = new File(fullPath);
|
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
//Document doc = dBuilder.parse(fXmlFile);
|
//Document doc = dBuilder.parse(fXmlFile);
|
||||||
@ -130,13 +163,6 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
Element nMain = doc.getDocumentElement();
|
Element nMain = doc.getDocumentElement();
|
||||||
NodeList nl = nMain.getChildNodes();
|
NodeList nl = nMain.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
if (nl.item(i).getNodeName().equals("db-url"))
|
|
||||||
db_url = nl.item(i).getTextContent();
|
|
||||||
if (nl.item(i).getNodeName().equals("db-login"))
|
|
||||||
db_login = nl.item(i).getTextContent();
|
|
||||||
if (nl.item(i).getNodeName().equals("db-password"))
|
|
||||||
db_password = nl.item(i).getTextContent();
|
|
||||||
|
|
||||||
if (nl.item(i).getNodeName().equals("mail-host"))
|
if (nl.item(i).getNodeName().equals("mail-host"))
|
||||||
mail_host = nl.item(i).getTextContent();
|
mail_host = nl.item(i).getTextContent();
|
||||||
if (nl.item(i).getNodeName().equals("mail-port"))
|
if (nl.item(i).getNodeName().equals("mail-port"))
|
||||||
@ -145,16 +171,10 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
mail_login = nl.item(i).getTextContent();
|
mail_login = nl.item(i).getTextContent();
|
||||||
if (nl.item(i).getNodeName().equals("mail-password"))
|
if (nl.item(i).getNodeName().equals("mail-password"))
|
||||||
mail_password = nl.item(i).getTextContent();
|
mail_password = nl.item(i).getTextContent();
|
||||||
|
|
||||||
//if (nl.item(i).getNodeName().equals("metadata"))
|
|
||||||
// metadata_file = nl.item(i).getTextContent();
|
|
||||||
|
|
||||||
if (nl.item(i).getNodeName().equals("data-dir"))
|
|
||||||
data_dir = nl.item(i).getTextContent();
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
String jspPath = context.getRealPath("/");
|
String jspPath = context.getRealPath("/");
|
||||||
|
|
||||||
@ -174,7 +194,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
doc = dBuilder.parse(body);
|
doc = dBuilder.parse(body);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
return "<metadata fn=\"-1\"><![CDATA[Parsing request error!]]></metadata>";
|
//return "<metadata fn=\"-1\"><![CDATA[Parsing request error!]]></metadata>";
|
||||||
|
return sendError(1,"Parsing request error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc != null) {
|
if (doc != null) {
|
||||||
@ -194,12 +215,14 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
logger.info("Connect is OK!");
|
logger.info("Connect is OK!");
|
||||||
} else {
|
} else {
|
||||||
error=true;
|
error=true;
|
||||||
result="<metadata fn=\"-1\"><![CDATA[An error occurred while connecting to the database!]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[An error occurred while connecting to the database!]]></metadata>";
|
||||||
|
result=sendError(1,"An error occurred while connecting to the database!");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
result="<metadata fn=\"-1\"><![CDATA[An error occurred while connecting to the database!]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[An error occurred while connecting to the database!]]></metadata>";
|
||||||
|
result=sendError(1,"An error occurred while connecting to the database!");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -210,7 +233,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
result="<metadata fn=\"-1\"><![CDATA[An set TYPE_SCROLL_SENSITIVE!]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[An set TYPE_SCROLL_SENSITIVE!]]></metadata>";
|
||||||
|
result=sendError(1,"An set TYPE_SCROLL_SENSITIVE!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//response.getWriter().append("fn="+fn);
|
//response.getWriter().append("fn="+fn);
|
||||||
@ -300,7 +324,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage() + " SQL=" + sql_query);
|
logger.info(ex.getMessage() + " SQL=" + sql_query);
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}finally {
|
}finally {
|
||||||
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
||||||
@ -327,7 +352,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}finally {
|
}finally {
|
||||||
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
||||||
@ -354,7 +380,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}finally {
|
}finally {
|
||||||
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
||||||
@ -381,7 +408,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}finally {
|
}finally {
|
||||||
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
if(rs!=null) try{rs.close();}catch(SQLException ex){}
|
||||||
@ -505,7 +533,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
rs=null;
|
rs=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -616,7 +645,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt.close();
|
stt.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -705,7 +735,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt.close();
|
stt.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,7 +842,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
pagecount = (int) Math.ceil((double) pagecount / (double) rowspagecount);
|
pagecount = (int) Math.ceil((double) pagecount / (double) rowspagecount);
|
||||||
@ -844,7 +876,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//перебираем RS и строим XML только из тех столбцов которые записанны в секци objects-list поля column в не зависимости от их видимости
|
//перебираем RS и строим XML только из тех столбцов которые записанны в секци objects-list поля column в не зависимости от их видимости
|
||||||
String xmlstring = "";
|
/*String xmlstring = "";
|
||||||
xmlstring += "<metadata fn=\"" + fn + "\"><type n=\"" + typename + "\" pc=\"" + pagecount + "\" pp=\"" + pagepos + "\">\n";
|
xmlstring += "<metadata fn=\"" + fn + "\"><type n=\"" + typename + "\" pc=\"" + pagecount + "\" pp=\"" + pagepos + "\">\n";
|
||||||
|
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
@ -893,9 +925,69 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmlstring += "</type></metadata>\n";
|
xmlstring += "</type></metadata>\n";
|
||||||
|
result=xmlstring;*/
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("errorCode",0);
|
||||||
|
json.put("errorMessage","");
|
||||||
|
json.put("fn",fn);
|
||||||
|
json.put("n",typename);
|
||||||
|
json.put("pc",pagecount);
|
||||||
|
json.put("pp",pagepos);
|
||||||
|
JSONArray datas = new JSONArray();
|
||||||
|
json.put("data",datas);
|
||||||
|
|
||||||
result=xmlstring;
|
int pos = -1;
|
||||||
//logger.info("xmlstring = " + xmlstring);
|
|
||||||
|
// iterate through the java resultset
|
||||||
|
try {
|
||||||
|
while (rs.next()) {
|
||||||
|
pos++;
|
||||||
|
if ((Integer.parseInt(pagepos) != -1) && ((pos < (Integer.parseInt(pagepos) * rowspagecount)) || (pos >= Integer.parseInt(pagepos) * rowspagecount + rowspagecount)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
datas.put(data);
|
||||||
|
|
||||||
|
|
||||||
|
String access = ""; //u = enable update field, d = enable delete field
|
||||||
|
try {
|
||||||
|
if (rs.getBoolean("_u") == true)
|
||||||
|
access += "u";
|
||||||
|
} catch (java.sql.SQLException e) {
|
||||||
|
access += "u";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (rs.getBoolean("_d") == true)
|
||||||
|
access += "d";
|
||||||
|
} catch (java.sql.SQLException e) {
|
||||||
|
access += "d";
|
||||||
|
}
|
||||||
|
|
||||||
|
String id = "";
|
||||||
|
try {
|
||||||
|
id = rs.getString(nTypeS.getAttributes().getNamedItem("ObjectID").getNodeValue());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
data.put("id", id);
|
||||||
|
data.put("a", access);
|
||||||
|
|
||||||
|
JSONArray row = new JSONArray();
|
||||||
|
data.put("row",row);
|
||||||
|
for (int i = 0; i < columns.size(); i++) {
|
||||||
|
try {
|
||||||
|
String val = rs.getString(columns.get(i));
|
||||||
|
row.put(val);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException | DOMException | SQLException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
result=json.toString();
|
||||||
|
//logger.info("json = " + json);
|
||||||
|
|
||||||
rs.close();
|
rs.close();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
@ -905,7 +997,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -997,7 +1090,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1131,14 +1225,16 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage()+"\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Could not find the requested node!]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Could not find the requested node!]]></metadata>";
|
||||||
|
result=sendError(1,"Could not find the requested node!");
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1202,7 +1298,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1217,7 +1314,6 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
String content = "Login is: "+ email.toLowerCase()+"\n<br> New password: <b>" + newPass+"</b>";
|
String content = "Login is: "+ email.toLowerCase()+"\n<br> New password: <b>" + newPass+"</b>";
|
||||||
content += "<br><br>Sincerely, the administration of ccalm.org.";
|
content += "<br><br>Sincerely, the administration of ccalm.org.";
|
||||||
|
|
||||||
|
|
||||||
String answer = "";
|
String answer = "";
|
||||||
try {
|
try {
|
||||||
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, recipient, subject, content);
|
EmailUtility.sendEmail(mail_host, mail_port, mail_login, mail_password, recipient, subject, content);
|
||||||
@ -1239,13 +1335,15 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlstring = "<metadata fn=\"7\"><![CDATA[" + answer + "]]></metadata>";
|
xmlstring = "<metadata fn=\"7\"><![CDATA[" + answer + "]]></metadata>";
|
||||||
} else {
|
} else {
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[This email address was not registered!]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[This email address was not registered!]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"This email address was not registered!");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (cmd.equals("1")) //Logout
|
} else if (cmd.equals("1")) //Logout
|
||||||
@ -1262,7 +1360,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1345,7 +1444,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
+ "]]></expiration><renewal><![CDATA[" + renewal + "]]></renewal></metadata>";
|
+ "]]></expiration><renewal><![CDATA[" + renewal + "]]></renewal></metadata>";
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error_in_login_or_password]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA["+trt(conn,"Error_in_login_or_password",user)+"]]></metadata>";
|
||||||
|
xmlstring=sendError(1,trt(conn,"Error_in_login_or_password",user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
@ -1354,7 +1454,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,11 +1464,40 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
} else if (cmd.equals("4")) //Create new user
|
} else if (cmd.equals("4")) //Create new user
|
||||||
{
|
{
|
||||||
xmlstring = "<metadata fn=\"7\"><cmd><![CDATA[4]]></cmd><![CDATA[0]]></metadata>"; //if error
|
xmlstring = "<metadata fn=\"7\"><cmd><![CDATA[4]]></cmd><![CDATA[0]]></metadata>"; //if error
|
||||||
|
String sql_query = "";
|
||||||
String newPass = getRandomString(8);
|
|
||||||
String sql_query = "select * from main.p__Users_1(4,${country_id},${surname},${name},${company},${position},${phone},${email},${password});";
|
|
||||||
|
|
||||||
String val;
|
String val;
|
||||||
|
|
||||||
|
//Check exists user by email email
|
||||||
|
sql_query = "select id from main._users where email=LOWER(TRIM(${email}))";
|
||||||
|
val = getSQLValue("string", email);
|
||||||
|
sql_query = Tools.replaceAll(sql_query,"${email}", val);
|
||||||
|
try {
|
||||||
|
Statement stt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
ResultSet rs = stt.executeQuery(sql_query);
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
if (rs.next()) {
|
||||||
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA["+trt(conn,"E_mail_already_exists_in_the_database",user)+"]]></metadata>";
|
||||||
|
xmlstring=sendError(1,trt(conn,"E_mail_already_exists_in_the_database",user));
|
||||||
|
error=true;
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stt.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage());
|
||||||
|
error=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!error) {
|
||||||
|
String newPass = getRandomString(8);
|
||||||
|
sql_query = "select * from main.p__Users_1(4,${country_id},${surname},${name},${company},${position},${phone},${email},${password});";
|
||||||
|
|
||||||
val = getSQLValue("i4", country_id);
|
val = getSQLValue("i4", country_id);
|
||||||
sql_query = Tools.replaceAll(sql_query,"${country_id}", val);
|
sql_query = Tools.replaceAll(sql_query,"${country_id}", val);
|
||||||
val = getSQLValue("string", lastname);
|
val = getSQLValue("string", lastname);
|
||||||
@ -1425,10 +1555,12 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//xmlstring = "<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
xmlstring=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result=xmlstring;
|
result=xmlstring;
|
||||||
//logger.info("xmlstring = " + xmlstring);
|
//logger.info("xmlstring = " + xmlstring);
|
||||||
@ -1455,7 +1587,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1635,7 +1768,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage());
|
||||||
error=true;
|
error=true;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@ -1652,7 +1786,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
stt=null;
|
stt=null;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
//result="<metadata fn=\"-1\"><![CDATA[Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query + "]]></metadata>";
|
||||||
|
result=sendError(1,"Error: " + ex.getMessage() + "\n\nSQL query: " + sql_query);
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1749,7 +1884,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result="<metadata fn=\"-1\"><![CDATA[Unknown function \"" + fn + "\" !]]></metadata>";
|
result=sendError(1,"Unknown function \"" + fn + "\" !");
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1763,8 +1898,8 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setServletContext(ServletContext context) {
|
public void setServletContext(ServletContext servletContext) {
|
||||||
this.context=context;
|
this.context=servletContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1775,7 +1910,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
public FileSystemResource home(HttpServletResponse response,@ModelAttribute User user,@RequestParam(required=false,name="t") String typename,@RequestParam(required=false,name="f") String field,@RequestParam(required=false,name="i") String id) {
|
public FileSystemResource home(HttpServletResponse response,@ModelAttribute User user,@RequestParam(required=false,name="t") String typename,@RequestParam(required=false,name="f") String field,@RequestParam(required=false,name="i") String id) {
|
||||||
|
|
||||||
String metadata_file = "";
|
String metadata_file = "";
|
||||||
String db_url = "";
|
/*String db_url = "";
|
||||||
String db_login = "";
|
String db_login = "";
|
||||||
String db_password = "";
|
String db_password = "";
|
||||||
//String data_dir = "";
|
//String data_dir = "";
|
||||||
@ -1805,6 +1940,33 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.info(ex.getMessage());
|
||||||
|
}*/
|
||||||
|
String db_url="";
|
||||||
|
String db_login="";
|
||||||
|
String db_password="";
|
||||||
|
Properties prop = new Properties();
|
||||||
|
InputStream input = null;
|
||||||
|
try {
|
||||||
|
prop.load(new FileInputStream("monitoring.properties")); // load a properties file
|
||||||
|
//Читаю настройки базы
|
||||||
|
db_url = prop.getProperty("db.url");
|
||||||
|
System.out.println("db.url = " + db_url);
|
||||||
|
//dbSchema = prop.getProperty("db.schema");
|
||||||
|
//System.out.println("db.schema = " + dbSchema);
|
||||||
|
db_login = prop.getProperty("db.login");
|
||||||
|
System.out.println("db.login = " + db_login);
|
||||||
|
db_password = prop.getProperty("db.password");
|
||||||
|
//System.out.println("db.password = " + db_password);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
/*if (input != null) {
|
||||||
|
try {
|
||||||
|
input.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1920,7 +2082,6 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
String result="";
|
String result="";
|
||||||
String data_dir="";
|
String data_dir="";
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
|
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
|
||||||
//File fXmlFile = new File(fullPath);
|
//File fXmlFile = new File(fullPath);
|
||||||
@ -2157,7 +2318,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Перевести слово по идентификатору из базы
|
//Translate word by id from database
|
||||||
public String trt(Connection conn,String key,User user)
|
public String trt(Connection conn,String key,User user)
|
||||||
{
|
{
|
||||||
String result="";
|
String result="";
|
||||||
@ -2165,7 +2326,7 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
Statement st = null;
|
Statement st = null;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st = conn.createStatement();
|
||||||
String sql = "select case when '"+user.language_id+"'='666' then t.translation||'''\"' alse t.translation end as translation from main._translations t where t.identifier='"+key+"' and (t.language_id='"+user.language_id+"' or ('"+user.language_id+"'='666' and t.language_id=1));";
|
String sql = "select case when '"+user.language_id+"'='666' then translation||'''\"' else translation end as translation from main._translations t where t.identifier='"+key+"' and (t.language_id='"+user.language_id+"' or ('"+user.language_id+"'='666' and t.language_id=1));";
|
||||||
rs = st.executeQuery(sql);
|
rs = st.executeQuery(sql);
|
||||||
if(rs != null) {
|
if(rs != null) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
@ -2179,7 +2340,6 @@ public class DBMSRecords implements ServletContextAware {
|
|||||||
if(st!=null) try{st.close();}catch(SQLException ex) {}
|
if(st!=null) try{st.close();}catch(SQLException ex) {}
|
||||||
if(rs!=null) try{rs.close();}catch(SQLException ex) {}
|
if(rs!=null) try{rs.close();}catch(SQLException ex) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result.equals(""))
|
if(result.equals(""))
|
||||||
{
|
{
|
||||||
result = Tools.replaceAll(key,"_", " ");
|
result = Tools.replaceAll(key,"_", " ");
|
||||||
|
|||||||
@ -1,18 +1,23 @@
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
//var g_translations = {'':''};
|
||||||
|
|
||||||
//Массив g_translations подгружается отдельно
|
//Массив g_translations подгружается отдельно
|
||||||
function trt(key)
|
function trt(key)
|
||||||
{
|
{
|
||||||
if(key==null || key===undefined) return '';
|
if(key==null || key===undefined) return '';
|
||||||
let val=g_translations[key];
|
let val=null;
|
||||||
if(val==null || val===undefined)
|
if(g_translations !== undefined){
|
||||||
{
|
val=g_translations[key];
|
||||||
for(let item in g_translations) {
|
if(val==null || val===undefined)
|
||||||
if(item.toLowerCase()==(''+key).toLowerCase())
|
{
|
||||||
{
|
for(let item in g_translations) {
|
||||||
val=g_translations[item];
|
if(item.toLowerCase()==(''+key).toLowerCase())
|
||||||
break;
|
{
|
||||||
|
val=g_translations[item];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1163,6 +1168,7 @@ class TRequest
|
|||||||
{
|
{
|
||||||
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
|
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
|
||||||
{
|
{
|
||||||
|
//console.log()
|
||||||
if(xmlHttpRequest.responseXML!=null) {
|
if(xmlHttpRequest.responseXML!=null) {
|
||||||
//if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
|
//if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
|
||||||
// xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
|
// xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
|
||||||
@ -1182,9 +1188,10 @@ class TRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
let obj = JSON.parse(xmlHttpRequest.responseText);
|
let obj=null;
|
||||||
|
try { obj = JSON.parse(xmlHttpRequest.responseText); } catch (e) {}
|
||||||
if(obj==null) {
|
if(obj==null) {
|
||||||
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ')');
|
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ') ',xmlHttpRequest.responseURL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.winObj!=null)
|
if(this.winObj!=null)
|
||||||
|
|||||||
Reference in New Issue
Block a user