Skip to content

Commit

Permalink
Erste lauffähige Testversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Weidler committed May 25, 2016
1 parent 2d56901 commit 7208c2c
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
/bin/
/target/
19 changes: 19 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project firRedirect">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="${dir.buildfile}/.."/>
<property name="dir.jarfile" value="${dir.buildfile}/jar"/>
<target name="create_run_jar">
<jar destfile="${dir.jarfile}/firRedirect.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="pw.weidler.firRedirect.Main"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${dir.buildfile}/target/classes"/>
<zipfileset excludes="META-INF/*.SF" src="C:/Users/dweid/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar"/>
</jar>
</target>
</project>
Empty file added log.txt
Empty file.
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>firRedirect</groupId>
<artifactId>firRedirect</artifactId>
<version>0.0.1-SNAPSHOT</version>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source/>
<target/>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
</project>
61 changes: 61 additions & 0 deletions src/pw/weidler/firRedirect/Main.java
Original file line number Diff line number Diff line change
@@ -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) {
}
}

}
60 changes: 60 additions & 0 deletions src/pw/weidler/firRedirect/dto/AlarmDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
38 changes: 38 additions & 0 deletions src/pw/weidler/firRedirect/dto/AlarmDataDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7208c2c

Please sign in to comment.