44import akka .actor .typed .ActorSystem ;
55import akka .http .javadsl .Http ;
66import akka .http .javadsl .ServerBinding ;
7- import akka .http .javadsl .model .HttpEntity ;
8- import akka .http .javadsl .model .StatusCodes ;
97import akka .http .javadsl .server .AllDirectives ;
10- import akka .http .javadsl .server .ExceptionHandler ;
11- import akka .http .javadsl .server .RejectionHandler ;
128import akka .http .javadsl .server .Route ;
139import ch .megard .akka .http .cors .javadsl .settings .CorsSettings ;
1410import org .apache .logging .log4j .LogManager ;
1713import org .jembi .jempi .backuprestoreapi .AppConfig ;
1814import org .jembi .jempi .backuprestoreapi .BackEnd ;
1915import org .jembi .jempi .backuprestoreapi .Routes ;
20- import org .jembi .jempi .shared .models .GlobalConstants ;
21-
2216import java .util .concurrent .CompletionStage ;
2317
2418import static ch .megard .akka .http .cors .javadsl .CorsDirectives .cors ;
@@ -43,10 +37,9 @@ public void open(
4337 final String httpServerHost ,
4438 final int httpPort ,
4539 final ActorSystem <Void > actorSystem ,
46- final ActorRef <BackEnd .Event > backEnd ,
47- final String jsonFields ) {
40+ final ActorRef <BackEnd .Event > backEnd ) {
4841 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 ));
5043 LOGGER .info ("BackupRestoreAPI Server online at http://{}:{}" , httpServerHost , httpPort );
5144 }
5245
@@ -57,31 +50,13 @@ public void close(final ActorSystem<Void> actorSystem) {
5750
5851 public Route createCorsRoutes (
5952 final ActorSystem <Void > actorSystem ,
60- final ActorRef <BackEnd .Event > backEnd ,
61- final String jsonFields ) {
53+ final ActorRef <BackEnd .Event > backEnd ) {
6254 final var settings = CorsSettings .create (AppConfig .CONFIG );
6355
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-
7856 return cors (settings ,
7957 () -> pathPrefix ("JeMPI" ,
8058 () -> concat (Routes .createCoreAPIRoutes (actorSystem ,
81- backEnd ),
82- path (GlobalConstants .SEGMENT_POST_FIELDS_CONFIG ,
83- () -> complete (StatusCodes .OK , jsonFields ))))).seal (rejectionHandler ,
84- exceptionHandler );
59+ backEnd ))));
8560 }
8661
8762}
0 commit comments