Browse Source

Merge pull request #841 in DESIGN/design from ~PLOUGH/10-design:feature/10.0 to feature/10.0

* commit '376cc6c7b5b37016c5be9b261f5782ea14f711c6':
  REPORT-16494 模板信息收集, 设计器启动有报错=>调整代码
  REPORT-16494 模板信息收集, 设计器启动有报错=>调整代码
  REPORT-16494 模板信息收集, 设计器启动有报错
research/10.0
plough 5 years ago
parent
commit
c9ed1601a0
  1. 11
      designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java
  2. 35
      designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java

11
designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java

@ -5,9 +5,10 @@ import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 负责向服务器发送信息
@ -30,14 +31,16 @@ class SendHelper {
}
private static boolean sendSingleTemplateInfo(String url, String content) {
HashMap<String, String> para = new HashMap<>();
Map<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
try {
String res = HttpToolbox.get(url, para);
String res = HttpToolbox.post(url, para);
return ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (IOException ignore) {
} catch (Throwable e) {
// 客户不需要关心,错误等级为 debug 就行了
FineLoggerFactory.getLogger().debug(e.getMessage(), e);
}
return false;
}

35
designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java

@ -0,0 +1,35 @@
package com.fr.design.mainframe.template.info;
import com.fr.invoke.Reflect;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import java.io.StringReader;
import static org.junit.Assert.assertTrue;
/**
* Created by plough on 2019/4/25.
*/
public class SendHelperTest {
private static final String CONSUMING_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_consuming/single";
private static final String PROCESS_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_process/single";
private static final String NORMAL_INFO = "<TemplateInfo templateID=\"16a988ce-8529-42f5-b17c-2ee849355071\" day_count=\"9\">\n" +
"<processMap process=\"\" float_count=\"0\" widget_count=\"0\" cell_count=\"1\" block_count=\"0\" report_type=\"0\"/>\n" +
"<consumingMap activitykey=\"2e0ea413-fa9c241e0-9723-4354fce51e81\" jar_time=\"不是安装版本\" create_time=\"2019-03-26 16:13\" uuid=\"476ca2cc-f789-4c5d-8e89-ef146580775c\" time_consume=\"129\" version=\"10.0\" username=\"plough\"/>\n" +
"</TemplateInfo>";
// 只在调试的时候运行,不需要每次都自动运行
public static void main(String[] args) throws XMLStreamException {
StringReader sr = new StringReader(NORMAL_INFO);
XMLableReader xmlReader = XMLableReader.createXMLableReader(sr);
TemplateInfo templateInfo = TemplateInfo.newInstanceByRead(xmlReader);
boolean res = Reflect.on(SendHelper.class).call("sendSingleTemplateInfo", CONSUMING_URL, templateInfo.getConsumingMapJsonString()).get();
assertTrue(res);
boolean res2 = Reflect.on(SendHelper.class).call("sendSingleTemplateInfo", PROCESS_URL, templateInfo.getProcessMapJsonString()).get();
assertTrue(res2);
}
}
Loading…
Cancel
Save