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 .AppConfig ;
18
14
import org .jembi .jempi .libapi .BackEnd ;
19
15
import org .jembi .jempi .libapi .Routes ;
20
- import org .jembi .jempi .shared .models .GlobalConstants ;
21
16
22
17
import java .util .concurrent .CompletionStage ;
23
18
@@ -43,10 +38,9 @@ public void open(
43
38
final String httpServerHost ,
44
39
final int httpPort ,
45
40
final ActorSystem <Void > actorSystem ,
46
- final ActorRef <BackEnd .Event > backEnd ,
47
- final String jsonFields ) {
41
+ final ActorRef <BackEnd .Event > backEnd ) {
48
42
http = Http .get (actorSystem );
49
- binding = http .newServerAt (httpServerHost , httpPort ).bind (this .createCorsRoutes (actorSystem , backEnd , jsonFields ));
43
+ binding = http .newServerAt (httpServerHost , httpPort ).bind (this .createCorsRoutes (actorSystem , backEnd ));
50
44
LOGGER .info ("Server online at http://{}:{}" , httpServerHost , httpPort );
51
45
}
52
46
@@ -57,37 +51,18 @@ public void close(final ActorSystem<Void> actorSystem) {
57
51
58
52
public Route createCorsRoutes (
59
53
final ActorSystem <Void > actorSystem ,
60
- final ActorRef <BackEnd .Event > backEnd ,
61
- final String jsonFields ) {
54
+ final ActorRef <BackEnd .Event > backEnd ) {
62
55
final var settings = CorsSettings .create (AppConfig .CONFIG );
63
56
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 ("Request was rejected. Reason: %s" .formatted (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
57
return cors (settings ,
79
58
() -> pathPrefix ("JeMPI" ,
80
59
() -> concat (Routes .createCoreAPIRoutes (actorSystem ,
81
60
backEnd ,
82
- jsonFields ,
83
61
AppConfig .LINKER_IP ,
84
62
AppConfig .LINKER_HTTP_PORT ,
85
63
AppConfig .CONTROLLER_IP ,
86
64
AppConfig .CONTROLLER_HTTP_PORT ,
87
- http ),
88
- path (GlobalConstants .SEGMENT_POST_FIELDS_CONFIG ,
89
- () -> complete (StatusCodes .OK , jsonFields ))))).seal (rejectionHandler ,
90
- exceptionHandler );
65
+ http ))));
91
66
}
92
67
93
68
}
0 commit comments