Falschen Status-Code bei start/stop-Fehler korrigiert
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
1 package de.juplo.kafka;
2
3 import lombok.RequiredArgsConstructor;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.web.bind.annotation.ExceptionHandler;
6 import org.springframework.web.bind.annotation.PostMapping;
7 import org.springframework.web.bind.annotation.ResponseStatus;
8 import org.springframework.web.bind.annotation.RestController;
9
10 import java.util.concurrent.ExecutionException;
11
12
13 @RestController
14 @RequiredArgsConstructor
15 public class DriverController
16 {
17   private final EndlessProducer producer;
18
19
20   @PostMapping("start")
21   public void start()
22   {
23     producer.start();
24   }
25
26   @PostMapping("stop")
27   public void stop() throws ExecutionException, InterruptedException
28   {
29     producer.stop();
30   }
31
32   @ExceptionHandler
33   @ResponseStatus(HttpStatus.BAD_REQUEST)
34   public ErrorResponse illegalStateException(IllegalStateException e)
35   {
36     return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
37   }
38 }