|
|
@@ -34,18 +34,18 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
gson = new Gson();
|
|
|
|
gson = new Gson();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args){
|
|
|
|
// public static void main(String[] args){
|
|
|
|
|
|
|
|
//
|
|
|
|
RestApiClient client1 = new RestApiClient();
|
|
|
|
// RestApiClient client1 = new RestApiClient();
|
|
|
|
|
|
|
|
//
|
|
|
|
client1.delete("Kind", 15);
|
|
|
|
// client1.delete("Kind", 15);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
Tagesplan t = client1.getGerichteOnTag("2023-12-17");
|
|
|
|
// Tagesplan t = client1.getGerichteOnTag("2023-12-17");
|
|
|
|
|
|
|
|
//
|
|
|
|
for(Mahlzeit m : t.getGerichte())
|
|
|
|
// for(Mahlzeit m : t.getGerichte())
|
|
|
|
System.out.println(m);
|
|
|
|
// System.out.println(m);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Methode für einen Get-Aufruf. Ruft alle Elemente einer Tabelle auf.
|
|
|
|
* Methode für einen Get-Aufruf. Ruft alle Elemente einer Tabelle auf.
|
|
|
@@ -68,8 +68,8 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
return httpResponse.body();
|
|
|
|
return httpResponse.body();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ConnectException conex){
|
|
|
|
catch(ConnectException conex){
|
|
|
@@ -106,7 +106,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
|
|
|
|
|
|
|
// Print the response status code and body
|
|
|
|
// Print the response status code and body
|
|
|
|
System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
|
|
|
// System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
return httpResponse.body();
|
|
|
|
return httpResponse.body();
|
|
|
|
|
|
|
|
|
|
|
@@ -149,8 +149,8 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
return httpResponse.body();
|
|
|
|
return httpResponse.body();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ConnectException conex){
|
|
|
|
catch(ConnectException conex){
|
|
|
@@ -191,8 +191,8 @@ 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());
|
|
|
|
|
|
|
|
|
|
|
|
// Print the response status code and body
|
|
|
|
// // Print the response status code and body
|
|
|
|
System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
|
|
|
// System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
return httpResponse.body();
|
|
|
|
return httpResponse.body();
|
|
|
|
|
|
|
|
|
|
|
@@ -234,9 +234,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ConnectException conex){
|
|
|
|
catch(ConnectException conex){
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
@@ -259,7 +259,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
public void post(String controllerName, String jsonData) {
|
|
|
|
public void post(String controllerName, String jsonData) {
|
|
|
|
URI apiUri = URI.create(String.format("%s/%s", urlBase,controllerName));
|
|
|
|
URI apiUri = URI.create(String.format("%s/%s", urlBase,controllerName));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
@@ -272,9 +272,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ConnectException conex){
|
|
|
|
catch(ConnectException conex){
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
@@ -297,7 +297,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
public void delete(String controllerName, int id) {
|
|
|
|
public void delete(String controllerName, int id) {
|
|
|
|
URI apiUri = URI.create(String.format("%s/%s/%d", urlBase,controllerName, id));
|
|
|
|
URI apiUri = URI.create(String.format("%s/%s/%d", urlBase,controllerName, id));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
@@ -310,9 +310,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ConnectException conex){
|
|
|
|
catch(ConnectException conex){
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
@@ -343,9 +343,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
|
|
|
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
|
|
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
|
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
|
@@ -384,7 +384,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
passwort = passwort.substring(1, passwort.length()-1);
|
|
|
|
passwort = passwort.substring(1, passwort.length()-1);
|
|
|
|
|
|
|
|
|
|
|
|
URI apiUri = URI.create(String.format("%s/Benutzer/anmeldeVersuch?Benutzername=%s&passwort=%s", urlBase, benutzer, passwort));
|
|
|
|
URI apiUri = URI.create(String.format("%s/Benutzer/anmeldeVersuch?Benutzername=%s&passwort=%s", urlBase, benutzer, passwort));
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.uri(apiUri)
|
|
|
|
.uri(apiUri)
|
|
|
@@ -396,9 +396,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
if(httpResponse.body().equals("true"))
|
|
|
|
if(httpResponse.body().equals("true"))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
else{
|
|
|
|
else{
|
|
|
@@ -434,7 +434,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
public Tagesplan getGerichteOnTag(String datum){
|
|
|
|
public Tagesplan getGerichteOnTag(String datum){
|
|
|
|
|
|
|
|
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/getGerichteOnTag?datum=%s", urlBase, datum));
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/getGerichteOnTag?datum=%s", urlBase, datum));
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.timeout(Duration.ofSeconds(timeout))
|
|
|
|
.uri(apiUri)
|
|
|
|
.uri(apiUri)
|
|
|
@@ -446,9 +446,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
Tagesplan t = new Tagesplan(datum);
|
|
|
|
Tagesplan t = new Tagesplan(datum);
|
|
|
|
|
|
|
|
|
|
|
@@ -492,7 +492,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
public int getGerichtIdOnTag(String name, String datum){
|
|
|
|
public int getGerichtIdOnTag(String name, String datum){
|
|
|
|
|
|
|
|
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/getGerichtIdOnTag?name=%s&datum=%s", urlBase, name, datum));
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/getGerichtIdOnTag?name=%s&datum=%s", urlBase, name, datum));
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.uri(apiUri)
|
|
|
|
.uri(apiUri)
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
@@ -503,9 +503,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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: " + httpResponse.body());
|
|
|
|
// System.out.println("Response Body: " + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
|
|
|
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
@@ -528,7 +528,7 @@ public class RestApiClient implements IRestAPI{
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void deleteGericht(int id){
|
|
|
|
public void deleteGericht(int id){
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/%d", urlBase, id));
|
|
|
|
URI apiUri = URI.create(String.format("%s/Tagesplan/%d", urlBase, id));
|
|
|
|
System.out.println(apiUri);
|
|
|
|
//System.out.println(apiUri);
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
|
.uri(apiUri)
|
|
|
|
.uri(apiUri)
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
@@ -539,9 +539,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());
|
|
|
|
|
|
|
|
|
|
|
|
// 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("Delete Gericht: Response Body: " + httpResponse.body());
|
|
|
|
// System.out.println("Delete Gericht: Response Body: " + httpResponse.body());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|