Skip to content
Snippets Groups Projects
Commit bc232f56 authored by Jordine Tobias Dr.'s avatar Jordine Tobias Dr.
Browse files

Vorbereitung Schnittstellen

parent b90aa288
No related branches found
No related tags found
No related merge requests found
Pipeline #32209 passed
# Übungen Software-Entwicklung 3: Schnittstellen (Vorläufig)
## Ausgangslage
Nachdem wir besprochen haben, wie Sie Ihre Programmdaten persistent speichern können, können Sie nun Ihrem Projekt Schnittstellen hinzufügen, sodass Sie Daten nach "außen" zur Verfügung stellen bzw. von dort empfangen können.
## Aufgabe
* Entscheiden Sie sich, welche Schnittstellenart (synchron/asynchron) für Ihr Projekt am besten geeignet ist.
* Erstellen Sie eine Komponente, die für die Außenschnittstelle Ihrer Anwendung zuständig ist.
* Welche Daten werden bereitgestellt?
* Welche Daten können modifiziert werden?
* Welche Daten können gesendet werden?
* Erstellen Sie die geeigneten `CRUD`-Operationen für Ihre Schnittstelle.
* Sofern Sie sich für eine REST-Schnittstelle entscheiden: Denken Sie an die korrekte Wahl der [HTTP-Verben](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) und [HTTP-Status-Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
## Tipps
* Für REST-APIs: Die Verwendung eines REST-Clients (z.B. Browser-Extensions, [Postman](https://www.postman.com), [Swagger Editor](https://editor.swagger.io), [IntelliJ](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html#converting-curl-requests)) macht das Testen der Schnittstelle einfacher.
## Ziele
* Ihr Projekt verfügt über eine gekapselte Schnittstellenschicht, mit der von außen auf Ihr Programm zugegriffen werden kann.
\ No newline at end of file
No preview for this file type
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<li><a href="maven-testing.html" target="_blank">Maven & Testing</a></li> <li><a href="maven-testing.html" target="_blank">Maven & Testing</a></li>
<li><a href="container-ci-cd.html" target="_blank">Container & CI/CD</a></li> <li><a href="container-ci-cd.html" target="_blank">Container & CI/CD</a></li>
<li><a href="sql-nosql.html" target="_blank">SQL, NoSQL</a></li> <li><a href="sql-nosql.html" target="_blank">SQL, NoSQL</a></li>
<li><a href="schnittstellen.html" target="_blank">Schnittstellen</a></li>
</ul> </ul>
<h3>Vorlesungnotizen</h3> <h3>Vorlesungnotizen</h3>
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220411.md" target="_blank">Vorlesungsnotizen - 11.04.2022</a></li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220411.md" target="_blank">Vorlesungsnotizen - 11.04.2022</a></li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220509.md" target="_blank">Vorlesungsnotizen - 09.05.2022</a></li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220509.md" target="_blank">Vorlesungsnotizen - 09.05.2022</a></li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220516.md" target="_blank">Vorlesungsnotizen - 16.05.2022</a></li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220516.md" target="_blank">Vorlesungsnotizen - 16.05.2022</a></li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/lecturenotes/20220523.md" target="_blank">Vorlesungsnotizen - 23.05.2022</a></li>
</ul> </ul>
<h3>Projekt</h3> <h3>Projekt</h3>
...@@ -42,6 +44,7 @@ ...@@ -42,6 +44,7 @@
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/Maven-Testing.md" target="_blank">Übung: Build Management & Testing</a> </li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/Maven-Testing.md" target="_blank">Übung: Build Management & Testing</a> </li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/Container-CI_CD.md" target="_blank">Übung: Container & CI/CD</a> </li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/Container-CI_CD.md" target="_blank">Übung: Container & CI/CD</a> </li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/sql-nosql.md" target="_blank">Übung: SQL, NoSQL</a> </li> <li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/sql-nosql.md" target="_blank">Übung: SQL, NoSQL</a> </li>
<li><a href="https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022vorlesung/-/blob/main/website/assignments/Schnittstellen.md" target="_blank">Übung: Schnittstellen</a> </li>
</ul> </ul>
<h3>Organisatorisches</h3> <h3>Organisatorisches</h3>
......
# Vorlesungsnotizen - 23.05.2022
## SQL
## NoSQL
## Schnittstellen
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Schnittstellen</title>
<meta charset="utf-8">
<link href="css/hdm.css" rel="stylesheet"></link>
<style>
/* yanone-kaffeesatz-regular - latin */
@font-face {
font-family: 'Yanone Kaffeesatz';
font-style: normal;
font-weight: 400;
src: url('fonts/yanone-kaffeesatz-v22-latin-regular.eot'); /* IE9 Compat Modes */
src: local(''),
url('fonts/yanone-kaffeesatz-v22-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/yanone-kaffeesatz-v22-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/yanone-kaffeesatz-v22-latin-regular.woff') format('woff'), /* Modern Browsers */
url('fonts/yanone-kaffeesatz-v22-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/yanone-kaffeesatz-v22-latin-regular.svg#YanoneKaffeesatz') format('svg'); /* Legacy iOS */
}
/* noto-serif-regular - latin */
@font-face {
font-family: 'Noto Serif';
font-style: normal;
font-weight: 400;
src: url('fonts/noto-serif-v20-latin-regular.eot'); /* IE9 Compat Modes */
src: local(''),
url('fonts/noto-serif-v20-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/noto-serif-v20-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/noto-serif-v20-latin-regular.woff') format('woff'), /* Modern Browsers */
url('fonts/noto-serif-v20-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/noto-serif-v20-latin-regular.svg#NotoSerif') format('svg'); /* Legacy iOS */
}
/* ubuntu-mono-regular - latin */
@font-face {
font-family: 'Ubuntu Mono';
font-style: normal;
font-weight: 400;
src: url('fonts/ubuntu-mono-v14-latin-regular.eot'); /* IE9 Compat Modes */
src: local(''),
url('fonts/ubuntu-mono-v14-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/ubuntu-mono-v14-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-regular.woff') format('woff'), /* Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/ubuntu-mono-v14-latin-regular.svg#UbuntuMono') format('svg'); /* Legacy iOS */
}
/* ubuntu-mono-italic - latin */
@font-face {
font-family: 'Ubuntu Mono';
font-style: italic;
font-weight: 400;
src: url('fonts/ubuntu-mono-v14-latin-italic.eot'); /* IE9 Compat Modes */
src: local(''),
url('fonts/ubuntu-mono-v14-latin-italic.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/ubuntu-mono-v14-latin-italic.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-italic.woff') format('woff'), /* Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-italic.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/ubuntu-mono-v14-latin-italic.svg#UbuntuMono') format('svg'); /* Legacy iOS */
}
/* ubuntu-mono-700 - latin */
@font-face {
font-family: 'Ubuntu Mono';
font-style: normal;
font-weight: 700;
src: url('fonts/ubuntu-mono-v14-latin-700.eot'); /* IE9 Compat Modes */
src: local(''),
url('fonts/ubuntu-mono-v14-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/ubuntu-mono-v14-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-700.woff') format('woff'), /* Modern Browsers */
url('fonts/ubuntu-mono-v14-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/ubuntu-mono-v14-latin-700.svg#UbuntuMono') format('svg'); /* Legacy iOS */
}
body { font-family: 'Noto Serif'; }
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
</style>
</head>
<body>
<textarea id="source">
class: center, middle, first
# Software-Entwicklung 3
## Schnittstellen
---
# Agenda
1. Recap
2. Synchrone Schnittstellen
3. Asynchrone Schnittstellen
---
# Recap: Was haben wir in der letzten Vorlesung besprochen?
* SQL
* NoSQL
> Blick ins [Repository](https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022projekt)
---
class: center, middle
# Welche Formen der Kommunikationsbeziehungen kennen Sie in der (objektorientierten) Programmierung?
---
# Kommunikationsbeziehungen
Beispiele:
* lokale Schnittstellen
* API (lokal)
* Remote Schnittstellen
* RPC
* RESTful-APIs
* SOAP-APIs
* Messaging-APIs/Event-based APIs
---
# Gruppierung der Schnittstellenarten
## Synchrone Schnittstellen
## Asynchrone Schnittstellen
---
# Ablauf synchrone Schnittstelle (vereinfacht)
## Sender
1. Verfassen einer Nachricht
2. Verpacken der Nachricht (_Marshalling_)
3. Absenden der Nachricht
4. _Warten auf Antwort_
5. Empfangen der Antwort-Nachricht
6. Auspacken der Antwort-Nachricht
7. Verarbeiten der Antwort-Nachricht
---
# Ablauf synchrone Schnittstelle (vereinfacht)
## Empfänger
1. _Warten auf eingehende Nachrichten_
2. Empfangen der Nachricht
3. Auspacken der Nachricht
4. Verarbeiten der Nachricht
5. Verfassen der Antwort-Nachricht
6. Verpacken der Antwort-Nachricht
7. Verschicken der Antwort-Nachricht
---
# Beispiele für synchrone Kommunikation
* HTTP
* SOAP
* GraphQL
* RPC (z.B. RMI, gRPC)
* REST
---
# Was ist REST?
> REST: Representational State Transfer
Softwarearchitekturstil
---
# Grundprinzipien
_nach [Wikipedia, 2022](https://de.wikipedia.org/wiki/Representational_State_Transfer)_
* Client/Server
* Zustandslosigkeit
* Caching
* Einheitliche Schnittstelle
* Adressierbarkeit von Ressourcen
* Repräsentationen zur Veränderung von Ressourcen
* Selbstbeschreibende Nachrichten
* „Hypermedia as the Engine of Application State“ (HATEOAS)
* Mehrschichtige Systeme
* Code on Demand (optional)
---
# REST-URIs
> URI: Uniform Resource Identifier
Mögliche URI-Muster:
* `<protocol>://<service-name>/<resource-type>/<resource-id>`
* `<resource-type>/<resource-id>`
* `<protocol>://<service-name>/<resource-type>/<resource-id>/<resource-details>`
* `<protocol>://<service-name>/<api-version>/<resource-type>/<resource-id>`
Beispiele:
* `https://music-mamager.app/songs/112233`
* `https://music-mamager.app/songs/112233/play`
* `https://music-mamager.app/songs/112233/artist`
* `/v3/songs/112233/artist/json`
---
# REST im Einsatz
* Verwendung auf Basis von HTTP/HTTPS
* Nutzen der [HTTP-Verben](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
* `POST`
* `GET`
* `DELETE`
* `PUT` (entspricht einem Update)
* ...
* Nutzen der HTTP-Status-Codes für Antworten
* [Übersicht der HTTP-Status-Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
---
# REST-APIs mit OpenAPI 3/Swagger
* API-Spezifikation
* API-Dokumentation
* API-Generierung
* Testumgebung
[Petstore Demo Projekt](https://petstore.swagger.io/)
---
# REST mit Spring Boot (I)
* Alternative zu `JAX-WS`
* Maven-Dependency hinzufügen (`spring-boot-starter-web`)
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.0</version>
</dependency>
```
* Erstellen einer Klasse, die mit `@RestController` annotiert wird
* Annotieren der Methoden mit geeigneter HTTP-Verb Annotation (z.B. `@GetMapping`) und zuweisen des Resource-Pfads (z.B. `/songs`)
* Mapping der URL-Parameter zu Java-Parametern mit der `@RequestParam(value = "name", defaultValue = "Song 2")`
---
# REST mit Spring Boot (II)
Start der Anwendung:
```java
@SpringBootApplication
public class RestServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RestServiceApplication.class, args);
}
}
```
---
# REST mit Spring Boot (III)
_Quelle: [spring.io, "Building a RESTful Web Service", 2022](https://spring.io/guides/gs/rest-service/)_
```java
package com.example.restservice;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
```
---
# REST mit Spring Boot (IV)
```java
package com.example.restservice;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}
```
---
# REST-Demo im Projekt
> Blick ins [Repository](https://gitlab.mi.hdm-stuttgart.de/jordine/se3sose2022projekt)
---
class: center, middle
# Asynchrone Kommunikationsbeziehungen
</textarea>
<script src="js/remark.min.js">
</script>
<script>
var slideshow = remark.create();
</script>
</body>
</html>
\ No newline at end of file
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