4
4
import akka .actor .typed .ActorSystem ;
5
5
import akka .http .javadsl .Http ;
6
6
import akka .http .javadsl .ServerBinding ;
7
- import akka .http .javadsl .model .HttpEntity ;
8
- import akka .http .javadsl .model .StatusCodes ;
9
7
import akka .http .javadsl .server .AllDirectives ;
10
- import akka .http .javadsl .server .ExceptionHandler ;
11
- import akka .http .javadsl .server .RejectionHandler ;
12
8
import akka .http .javadsl .server .Route ;
13
9
import ch .megard .akka .http .cors .javadsl .settings .CorsSettings ;
14
10
import org .apache .logging .log4j .LogManager ;
17
13
import org .jembi .jempi .backuprestoreapi .AppConfig ;
18
14
import org .jembi .jempi .backuprestoreapi .BackEnd ;
19
15
import org .jembi .jempi .backuprestoreapi .Routes ;
20
- import org .jembi .jempi .shared .models .GlobalConstants ;
21
-
22
16
import java .util .concurrent .CompletionStage ;
23
17
24
18
import static ch .megard .akka .http .cors .javadsl .CorsDirectives .cors ;
@@ -43,10 +37,9 @@ public void open(
43
37
final String httpServerHost ,
44
38
final int httpPort ,
45
39
final ActorSystem <Void > actorSystem ,
46
- final ActorRef <BackEnd .Event > backEnd ,
47
- final String jsonFields ) {
40
+ final ActorRef <BackEnd .Event > backEnd ) {
48
41
http = Http .get (actorSystem );
49
- binding = http .newServerAt (httpServerHost , httpPort ).bind (this .createCorsRoutes (actorSystem , backEnd , jsonFields ));
42
+ binding = http .newServerAt (httpServerHost , httpPort ).bind (this .createCorsRoutes (actorSystem , backEnd ));
50
43
LOGGER .info ("BackupRestoreAPI Server online at http://{}:{}" , httpServerHost , httpPort );
51
44
}
52
45
@@ -57,31 +50,13 @@ public void close(final ActorSystem<Void> actorSystem) {
57
50
58
51
public Route createCorsRoutes (
59
52
final ActorSystem <Void > actorSystem ,
60
- final ActorRef <BackEnd .Event > backEnd ,
61
- final String jsonFields ) {
53
+ final ActorRef <BackEnd .Event > backEnd ) {
62
54
final var settings = CorsSettings .create (AppConfig .CONFIG );
63
55
64
- final RejectionHandler rejectionHandler = RejectionHandler .defaultHandler ().mapRejectionResponse (response -> {
65
- if (response .entity () instanceof HttpEntity .Strict ) {
66
- String message = ((HttpEntity .Strict ) response .entity ()).getData ().utf8String ();
67
- LOGGER .warn (String .format ("Request was rejected. Reason: %s" , message ));
68
- }
69
-
70
- return response ;
71
- });
72
-
73
- final ExceptionHandler exceptionHandler = ExceptionHandler .newBuilder ().match (Exception .class , x -> {
74
- LOGGER .error ("An exception occurred while executing the Route" , x );
75
- return complete (StatusCodes .INTERNAL_SERVER_ERROR , "An exception occurred, see server logs for details" );
76
- }).build ();
77
-
78
56
return cors (settings ,
79
57
() -> pathPrefix ("JeMPI" ,
80
58
() -> concat (Routes .createCoreAPIRoutes (actorSystem ,
81
- backEnd ),
82
- path (GlobalConstants .SEGMENT_POST_FIELDS_CONFIG ,
83
- () -> complete (StatusCodes .OK , jsonFields ))))).seal (rejectionHandler ,
84
- exceptionHandler );
59
+ backEnd ))));
85
60
}
86
61
87
62
}
0 commit comments