Skip to content
Snippets Groups Projects
Commit bb984ff2 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Anpassungen auf Java Konventionen

Dependencys für Unittest hinzugefügt
parent dc0a785a
No related branches found
No related tags found
No related merge requests found
...@@ -31,12 +31,6 @@ ...@@ -31,12 +31,6 @@
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.28.0</version> <version>3.28.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
...@@ -49,6 +43,13 @@ ...@@ -49,6 +43,13 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20190722</version> <version>20190722</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -18,9 +18,15 @@ package Enigma.model; ...@@ -18,9 +18,15 @@ package Enigma.model;
*/ */
public class Codebuch { public class Codebuch {
private int tag; private int tag;
private String[] Walzenlage = new String[3]; private String[] Walzenlage;
private String[] Ringstellung = new String[3]; private String[] Ringstellung;
private String[] Steckverbindung = new String[10]; private String[] Steckverbindung;
Codebuch() {
this.Walzenlage = new String[3];
this.Ringstellung = new String[3];
this.Steckverbindung = new String[10];
}
/** /**
* Gibt die aktuelle Instanz des Codebuches als String zurück. * Gibt die aktuelle Instanz des Codebuches als String zurück.
......
package Enigma.model; package Enigma.model;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
...@@ -12,6 +13,7 @@ import org.json.JSONObject; ...@@ -12,6 +13,7 @@ import org.json.JSONObject;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -31,7 +33,7 @@ public class Funkraum { ...@@ -31,7 +33,7 @@ public class Funkraum {
* *
* @param kenngruppe : String : Kenngruppe dieser Engiam * @param kenngruppe : String : Kenngruppe dieser Engiam
* @return String[] : String Array wobei Index 0 dem Empfangstag entspricht und index 1 der empfangenen Nachricht * @return String[] : String Array wobei Index 0 dem Empfangstag entspricht und index 1 der empfangenen Nachricht
* @throws IOException * @throws IOException : Exception : wenn keine Verbindung zum Funker aufgebaut werden konnte.
*/ */
public String[] empfangeFunkspruch(String kenngruppe) throws IOException { public String[] empfangeFunkspruch(String kenngruppe) throws IOException {
String[] funkspruch = new String[2]; String[] funkspruch = new String[2];
...@@ -40,7 +42,7 @@ public class Funkraum { ...@@ -40,7 +42,7 @@ public class Funkraum {
HttpPost httppost = new HttpPost("https://enigma.itstall.de/"); HttpPost httppost = new HttpPost("https://enigma.itstall.de/");
// Anfrage Parameter und Encoding setzen // Anfrage Parameter und Encoding setzen
List<NameValuePair> params = new ArrayList<NameValuePair>(2); List<NameValuePair> params = new ArrayList<>(2);
params.add(new BasicNameValuePair("k", kenngruppe)); params.add(new BasicNameValuePair("k", kenngruppe));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
...@@ -75,16 +77,14 @@ public class Funkraum { ...@@ -75,16 +77,14 @@ public class Funkraum {
* *
* @param funkspruch : String : Der zu sendede Funkspruch * @param funkspruch : String : Der zu sendede Funkspruch
* @param kenngruppe : String : Die Kenngruppe dieser Engima * @param kenngruppe : String : Die Kenngruppe dieser Engima
* @return boolean : War das senden erfolgreich? True wenn ja, false wenn nicht erfolgreich * @throws IOException : Exception : Funkspruch konnte nicht gesendet werden
* @throws IOException
*/ */
public boolean sendeFunkspruch(String funkspruch, String kenngruppe) throws IOException { public void sendeFunkspruch(String funkspruch, String kenngruppe) throws HttpException, IOException {
boolean boolReturn = false;
HttpClient httpclient = HttpClients.createDefault(); HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("https://enigma.itstall.de/"); HttpPost httppost = new HttpPost("https://enigma.itstall.de/");
// Anfrage Parameter und Encoding setzen // Anfrage Parameter und Encoding setzen
List<NameValuePair> params = new ArrayList<NameValuePair>(2); List<NameValuePair> params = new ArrayList<>(2);
params.add(new BasicNameValuePair("k", kenngruppe)); params.add(new BasicNameValuePair("k", kenngruppe));
params.add(new BasicNameValuePair("m", funkspruch)); params.add(new BasicNameValuePair("m", funkspruch));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
...@@ -96,11 +96,10 @@ public class Funkraum { ...@@ -96,11 +96,10 @@ public class Funkraum {
if (entity != null) { if (entity != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
JSONObject result = new JSONObject(reader.readLine()); JSONObject result = new JSONObject(reader.readLine());
if(result.getInt("result") == 200) { if(result.getInt("result") != 200) {
boolReturn = true; throw new HttpException("Der andere Funker mag deine Nachricht nicht. Rüge ihn wenn du ihn wieder siehst...");
} }
} }
return boolReturn;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment