11package wu.seal.jsontokotlin.statistics
22
3+ import com.google.gson.Gson
4+ import wu.seal.jsontokotlin.isTestModel
35import java.net.HttpURLConnection
46import java.net.URL
57
@@ -10,19 +12,23 @@ import java.net.URL
1012
1113const val actionInfoUrl = " http://jsontokotlin.sealwu.com:8008/sendActionInfo"
1214const val exceptionLogUrl = " http://jsontokotlin.sealwu.com:8008/sendExceptionInfo"
15+ const val configLogUrl = " http://jsontokotlin.sealwu.com:8008/sendConfigInfo"
16+ // const val actionInfoUrl = "http://localhost:8008/sendActionInfo"
17+ // const val exceptionLogUrl = "http://localhost:8008/sendExceptionInfo"
18+ // const val configLogUrl = "http://localhost:8008/sendConfigInfo"
1319
1420fun sendExceptionLog (log : String ) {
1521 try {
1622 val connection = URL (exceptionLogUrl).openConnection() as HttpURLConnection
1723 connection.doOutput = true
18- connection.doInput= true
19- connection.addRequestProperty(" Content-Type" ," application/text" )
24+ connection.doInput = true
25+ connection.addRequestProperty(" Content-Type" , " application/text" )
2026 val outputStream = connection.outputStream
2127 val writer = outputStream.writer()
2228 writer.write(log)
2329 writer.flush()
2430 if (connection.responseCode != 200 ) {
25- println (connection.responseMessage+ " \n " + connection.errorStream.reader().readText())
31+ println (connection.responseMessage + " \n " + connection.errorStream.reader().readText())
2632 }
2733 } catch (e: Exception ) {
2834 e.printStackTrace()
@@ -36,14 +42,14 @@ fun sendActionInfo(actionInfo: String) {
3642 val connection = URL (actionInfoUrl).openConnection() as HttpURLConnection
3743 connection.doOutput = true
3844 connection.requestMethod = " POST"
39- connection.addRequestProperty(" Content-Type" ," application/json;charset=UTF-8" )
45+ connection.addRequestProperty(" Content-Type" , " application/json;charset=UTF-8" )
4046
4147 val outputStream = connection.getOutputStream()
4248 val writer = outputStream.writer()
4349 writer.write(actionInfo)
4450 writer.flush()
4551 if (connection.responseCode != 200 ) {
46- println (connection.responseMessage+ " \n " + connection.errorStream.reader().readText())
52+ println (connection.responseMessage + " \n " + connection.errorStream.reader().readText())
4753 }
4854 } catch (e: Exception ) {
4955 e.printStackTrace()
@@ -71,10 +77,31 @@ fun sendHistoryActionInfo() {
7177 PersistCache .deleteAllActionInfo()
7278}
7379
80+ fun sendConfigInfo () {
81+ try {
82+ val connection = URL (configLogUrl).openConnection() as HttpURLConnection
83+ connection.doOutput = true
84+ connection.requestMethod = " POST"
85+ connection.addRequestProperty(" Content-Type" , " application/json;charset=UTF-8" )
86+
87+ val outputStream = connection.getOutputStream()
88+ val writer = outputStream.writer()
89+ writer.write(Gson ().toJson(ConfigInfo ()))
90+ writer.flush()
91+ if (connection.responseCode != 200 ) {
92+ println (connection.responseMessage + " \n " + connection.errorStream.reader().readText())
93+ }
94+ } catch (e: Exception ) {
95+ e.printStackTrace()
96+ }
97+ }
7498
7599fun main (args : Array <String >) {
76- val demeoActionInfo = """ {"id":0,"uuid":"214fdsafsafafsdf","pluginVersion":"1.2.1","actionType":"start","time":"1234231434124324","daytime":"2017-09-27"} """
100+ isTestModel = true
77101
102+ val demeoActionInfo = """ {"id":0,"uuid":"214fdsafsafafsdf","pluginVersion":"1.2.1","actionType":"start","time":"1234231434124324","daytime":"2017-09-27"}"""
78103 sendExceptionLog(" hello,I am exception" )
79104 sendActionInfo(demeoActionInfo)
105+
106+ sendConfigInfo()
80107}
0 commit comments