Compare commits
No commits in common. "456e55a66e88e8b348bf21ac2537a85234d8d347" and "4a97fee7e7bb01bd61a18a543b9f349c609c2c0f" have entirely different histories.
456e55a66e
...
4a97fee7e7
5
pom.xml
5
pom.xml
@ -38,11 +38,6 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>2.10.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -5,12 +5,9 @@ import java.util.ArrayList;
|
|||||||
public class Kind {
|
public class Kind {
|
||||||
|
|
||||||
// region Felder
|
// region Felder
|
||||||
|
|
||||||
private transient int id;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String vorname;
|
private String vorname;
|
||||||
private int bid;
|
private int id;
|
||||||
|
|
||||||
// TODO Zutat implementieren!
|
// TODO Zutat implementieren!
|
||||||
// private ArrayList<Zutat> filter;
|
// private ArrayList<Zutat> filter;
|
||||||
// endregion
|
// endregion
|
||||||
@ -40,14 +37,6 @@ public class Kind {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBid() {
|
|
||||||
return bid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBid(int bid) {
|
|
||||||
this.bid = bid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Zutat implementieren!
|
// TODO Zutat implementieren!
|
||||||
/*
|
/*
|
||||||
public ArrayList<Zutat> getFilter() {
|
public ArrayList<Zutat> getFilter() {
|
||||||
@ -61,12 +50,10 @@ public class Kind {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Konstruktoren
|
// region Konstruktoren
|
||||||
public Kind(String name, String vorname, int bid) {
|
public Kind(String name, String vorname) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.vorname = vorname;
|
this.vorname = vorname;
|
||||||
this.bid = bid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @author Samuel Wolff
|
||||||
|
* noch nicht getestet
|
||||||
|
* TODO FERTIG MACHEN
|
||||||
|
*/
|
||||||
|
|
||||||
package RestAPISchnittstelle;
|
package RestAPISchnittstelle;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -5,38 +11,22 @@ import java.net.http.HttpClient;
|
|||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.WatchEvent;
|
|
||||||
|
|
||||||
import Logik.Kind;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* noch nicht getestet
|
|
||||||
* TODO FERTIG MACHEN
|
|
||||||
* @author Samuel Wolff
|
|
||||||
*/
|
|
||||||
public class RestApiClient implements IRestAPI{
|
public class RestApiClient implements IRestAPI{
|
||||||
|
|
||||||
private final String urlBase = "https://pbg2h22awo.web.pb.bib.de/VPR_Schnittstelle/VPR_Schnittstelle/restAPI.php";
|
private final String urlBase = "https://pbg2h22awo.web.pb.bib.de/VPR_Schnittstelle/VPR_Schnittstelle/restAPI.php";
|
||||||
|
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
|
|
||||||
private final Gson gson;
|
|
||||||
|
|
||||||
public RestApiClient(){
|
public RestApiClient(){
|
||||||
client = HttpClient.newHttpClient();
|
client = HttpClient.newHttpClient();
|
||||||
gson = new Gson();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
|
|
||||||
Kind kind = new Kind("Klein", "Kevin", 2);
|
new RestApiClient().get("Kind", 2);
|
||||||
|
|
||||||
String json = new Gson().toJson(kind);
|
|
||||||
|
|
||||||
new RestApiClient().post("Kind", json);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,11 +46,9 @@ public class RestApiClient implements IRestAPI{
|
|||||||
// Send the request and get the response
|
// Send the request and get the response
|
||||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
Kind test = gson.fromJson(httpResponse.body(), Kind.class);
|
|
||||||
|
|
||||||
// Print the response status code and body
|
// Print the response status code and body
|
||||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
System.out.println("Status Code: " + httpResponse.statusCode());
|
||||||
System.out.println("Response Body: " + test.getName());
|
System.out.println("Response Body: " + httpResponse.body());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -83,14 +71,9 @@ public class RestApiClient implements IRestAPI{
|
|||||||
// Send the request and get the response
|
// Send the request and get the response
|
||||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
Kind[] test = gson.fromJson(httpResponse.body(), Kind[].class);
|
|
||||||
|
|
||||||
// Print the response status code and body
|
// Print the response status code and body
|
||||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
System.out.println("Status Code: " + httpResponse.statusCode());
|
||||||
for(Kind i : test){
|
System.out.println("Response Body: " + httpResponse.body());
|
||||||
System.out.println(i.getVorname());
|
|
||||||
}
|
|
||||||
//System.out.println("Response Body: " + test);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -154,26 +137,7 @@ public class RestApiClient implements IRestAPI{
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void post(String controllerName, String jsonData) {
|
public void post(String controllerName, String jsonData) {
|
||||||
URI apiUri = URI.create(String.format("%s/%s", urlBase,controllerName));
|
|
||||||
|
|
||||||
System.out.println(apiUri);
|
|
||||||
|
|
||||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
||||||
.uri(apiUri)
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(jsonData, StandardCharsets.UTF_8))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Send the request and get the response
|
|
||||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
||||||
|
|
||||||
// Print the response status code and body
|
|
||||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
|
||||||
System.out.println("Response Body: " + httpResponse.body());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,10 +2,8 @@ module de.subway_surfers.vpr_app {
|
|||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
requires java.net.http;
|
requires java.net.http;
|
||||||
requires com.google.gson;
|
|
||||||
|
|
||||||
|
|
||||||
opens de.subway_surfers.vpr_app to javafx.fxml, com.google.gson;
|
opens de.subway_surfers.vpr_app to javafx.fxml;
|
||||||
opens Logik to com.google.gson;
|
|
||||||
exports de.subway_surfers.vpr_app;
|
exports de.subway_surfers.vpr_app;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user