1111import java .util .Map ;
1212import java .util .stream .Collectors ;
1313
14- import in .erail .common .FrameworkConstants ;
14+ import static in .erail .common .FrameworkConstants . RoutingContext . Json ;
1515import in .erail .glue .annotation .StartService ;
1616import io .netty .handler .codec .http .HttpHeaderNames ;
1717import io .netty .handler .codec .http .HttpResponseStatus ;
2424import io .vertx .reactivex .ext .web .RoutingContext ;
2525import io .vertx .reactivex .ext .web .api .contract .openapi3 .OpenAPI3RouterFactory ;
2626import in .erail .service .RESTService ;
27+ import io .vertx .core .json .JsonArray ;
2728import io .vertx .reactivex .core .buffer .Buffer ;
29+ import io .vertx .reactivex .ext .web .Cookie ;
30+ import java .util .ArrayList ;
2831import java .util .Arrays ;
2932import java .util .HashMap ;
33+ import java .util .Iterator ;
34+ import java .util .List ;
3035import java .util .Optional ;
3136
3237/**
@@ -113,19 +118,19 @@ public JsonObject serialiseRoutingContext(RoutingContext pContext) {
113118 JsonObject result = new JsonObject ();
114119
115120 if (pContext .request ().method () == HttpMethod .POST ) {
116- result .put (FrameworkConstants . RoutingContext . Json .BODY , pContext .getBody ().getDelegate ().getBytes ());
121+ result .put (Json .BODY , pContext .getBody ().getDelegate ().getBytes ());
117122 } else {
118- result .put (FrameworkConstants . RoutingContext . Json .BODY , new byte []{});
123+ result .put (Json .BODY , new byte []{});
119124 }
120125
121126 JsonObject headers = new JsonObject (convertMultiMapIntoMap (pContext .request ().headers ()));
122- result .put (FrameworkConstants . RoutingContext . Json .HEADERS , headers );
127+ result .put (Json .HEADERS , headers );
123128
124129 JsonObject query = new JsonObject (convertMultiMapIntoMap (pContext .queryParams ()));
125- result .put (FrameworkConstants . RoutingContext . Json .QUERY_STRING_PARAM , query );
130+ result .put (Json .QUERY_STRING_PARAM , query );
126131
127132 JsonObject params = new JsonObject (convertMultiMapIntoMap (pContext .request ().params ()));
128- result .put (FrameworkConstants . RoutingContext . Json .PATH_PARAM , params );
133+ result .put (Json .PATH_PARAM , params );
129134
130135 getLog ().debug (() -> "Context to JSON:" + result .toString ());
131136
@@ -141,8 +146,8 @@ public JsonObject serialiseRoutingContext(RoutingContext pContext) {
141146 */
142147 public HttpServerResponse buildResponseFromReply (JsonObject pReplyResponse , RoutingContext pContext ) {
143148
144- JsonObject headers = pReplyResponse .getJsonObject (FrameworkConstants . RoutingContext . Json .HEADERS , new JsonObject ());
145- String statusCode = pReplyResponse .getString (FrameworkConstants . RoutingContext . Json .STATUS_CODE , HttpResponseStatus .OK .codeAsText ().toString ());
149+ JsonObject headers = pReplyResponse .getJsonObject (Json .HEADERS , new JsonObject ());
150+ String statusCode = pReplyResponse .getString (Json .STATUS_CODE , HttpResponseStatus .OK .codeAsText ().toString ());
146151
147152 if (!headers .containsKey (HttpHeaders .CONTENT_TYPE )) {
148153 headers .put (HttpHeaders .CONTENT_TYPE , MediaType .OCTET_STREAM .toString ());
@@ -157,7 +162,26 @@ public HttpServerResponse buildResponseFromReply(JsonObject pReplyResponse, Rout
157162
158163 pContext .response ().setStatusCode (HttpResponseStatus .parseLine (statusCode ).code ());
159164
160- Optional <byte []> body = Optional .ofNullable (pReplyResponse .getBinary (FrameworkConstants .RoutingContext .Json .BODY ));
165+ Optional <JsonArray > cookies = Optional .ofNullable (pReplyResponse .getJsonArray (Json .COOKIES ));
166+
167+ cookies .ifPresent ((cooky ) -> {
168+ for (Iterator <Object > iterator = cooky .iterator (); iterator .hasNext ();) {
169+ JsonObject next = (JsonObject ) iterator .next ();
170+ Optional cookieName = Optional .ofNullable (next .getString (Json .Cookie .NAME ));
171+ if (cookieName .isPresent ()) {
172+ Cookie c = Cookie .cookie ((String ) cookieName .get (), "" );
173+ Optional .ofNullable (next .getString (Json .Cookie .VALUE )).ifPresent (t -> c .setValue (t ));
174+ Optional .ofNullable (next .getString (Json .Cookie .PATH )).ifPresent (t -> c .setPath (t ));
175+ Optional .ofNullable (next .getDouble (Json .Cookie .MAX_AGE )).ifPresent (t -> c .setMaxAge (t .longValue ()));
176+ Optional .ofNullable (next .getString (Json .Cookie .DOMAIN )).ifPresent (t -> c .setDomain (t ));
177+ Optional .ofNullable (next .getBoolean (Json .Cookie .SECURE )).ifPresent (t -> c .setSecure (t ));
178+ Optional .ofNullable (next .getBoolean (Json .Cookie .HTTP_ONLY )).ifPresent (t -> c .setHttpOnly (t ));
179+ pContext .addCookie (c );
180+ }
181+ }
182+ });
183+
184+ Optional <byte []> body = Optional .ofNullable (pReplyResponse .getBinary (Json .BODY ));
161185
162186 body .ifPresent ((t ) -> {
163187 pContext .response ().putHeader (HttpHeaderNames .CONTENT_LENGTH .toString (), Integer .toString (t .length ));
0 commit comments