diff --git a/.gitignore b/.gitignore index 92aa655..2eb0cb2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,11 @@ .mtj.tmp/ # Package Files # -*.jar +#*.jar *.war *.ear # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -/bin/ \ No newline at end of file +/bin/ +/target/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..04c01e9 --- /dev/null +++ b/build.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..46d0ddd --- /dev/null +++ b/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + firRedirect + firRedirect + 0.0.1-SNAPSHOT + + + src + + + maven-compiler-plugin + 3.3 + + + + + + + + + + com.google.code.gson + gson + 2.6.2 + + + \ No newline at end of file diff --git a/src/pw/weidler/firRedirect/Main.java b/src/pw/weidler/firRedirect/Main.java index 742caa7..2ae4ff3 100644 --- a/src/pw/weidler/firRedirect/Main.java +++ b/src/pw/weidler/firRedirect/Main.java @@ -1,5 +1,66 @@ package pw.weidler.firRedirect; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import pw.weidler.firRedirect.dto.AlarmDTO; +import pw.weidler.firRedirect.dto.AlarmDataDTO; + public class Main { + public static void main(String[] args) throws IOException { + //File f = new File(System.getProperty("user.dir")+dat.getYear()+"-"+dat.getMonth()+"-"+dat.getDay()+"_"+dat.getHours()+"-"+dat.getMinutes()+"-"+dat.getSeconds()+"-"+dat.getTime()+".txt"); + + //f.createNewFile(); + + //PrintWriter pw = new PrintWriter(f); + + StringBuilder sbAufrufparameter = new StringBuilder(); + + for (String arg : args) { + sbAufrufparameter.append(arg + " "); + } + String strParams = sbAufrufparameter.toString().trim(); + String params[] = strParams.split("\\|"); + + String kodierung = params[0].trim().replace(System.getProperty("line.separator"), "%5Cn"); + String beschreibung = params[1].trim().replace(System.getProperty("line.separator"), "%5Cn"); + String alarmtext = params[2].trim().replace(System.getProperty("line.separator"), "%5Cn"); + AlarmDTO alarm = new AlarmDTO(alarmtext, "ALARM", "firRedirect", System.currentTimeMillis()+"", new AlarmDataDTO(kodierung, alarmtext, beschreibung)); + + Gson gson = new GsonBuilder().create(); + String json = gson.toJson(alarm); + + System.out.println(json); + //pw.println(json); + //pw.flush(); + //pw.close(); + + try { + Socket socket = new Socket("localhost", 5566); + OutputStream os = socket.getOutputStream(); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); + + bw.write(json); + bw.flush(); + + bw.close(); + os.close(); + socket.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + } diff --git a/src/pw/weidler/firRedirect/dto/AlarmDTO.java b/src/pw/weidler/firRedirect/dto/AlarmDTO.java new file mode 100644 index 0000000..038ad83 --- /dev/null +++ b/src/pw/weidler/firRedirect/dto/AlarmDTO.java @@ -0,0 +1,60 @@ +package pw.weidler.firRedirect.dto; + +public class AlarmDTO { + private String message; + private String type; + private String sender; + + private AlarmDataDTO data; + private String timestamp; + + public AlarmDTO(String message, String type, String sender, String timestamp, AlarmDataDTO data) { + super(); + this.message = message; + this.type = type; + this.sender = sender; + this.timestamp = timestamp; + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getSender() { + return sender; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public AlarmDataDTO getData() { + return data; + } + + public void setData(AlarmDataDTO data) { + this.data = data; + } + +} diff --git a/src/pw/weidler/firRedirect/dto/AlarmDataDTO.java b/src/pw/weidler/firRedirect/dto/AlarmDataDTO.java new file mode 100644 index 0000000..3e1443c --- /dev/null +++ b/src/pw/weidler/firRedirect/dto/AlarmDataDTO.java @@ -0,0 +1,38 @@ +package pw.weidler.firRedirect.dto; + +public class AlarmDataDTO{ + private String address; + private String alarmtext; + private String beschreibung; + + public AlarmDataDTO(String address, String alarmtext, String beschreibung) { + super(); + this.address = address; + this.alarmtext = alarmtext; + this.beschreibung = beschreibung; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAlarmtext() { + return alarmtext; + } + + public void setAlarmtext(String alarmtext) { + this.alarmtext = alarmtext; + } + + public String getBeschreibung() { + return beschreibung; + } + + public void setBeschreibung(String beschreibung) { + this.beschreibung = beschreibung; + } +}