diff --git a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/util/rest/RestUtil.java b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/util/rest/RestUtil.java index 7a868a0c..43cb5a0a 100644 --- a/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/util/rest/RestUtil.java +++ b/jasamedika-sdm/src/main/java/com/jasamedika/medifirst2000/util/rest/RestUtil.java @@ -20,7 +20,6 @@ import com.google.gson.Gson; public class RestUtil { private static final String CONTENT_TYPE = "Content-Type"; - private static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; /** * get JSON response from Object @@ -33,7 +32,6 @@ public class RestUtil { public static ResponseEntity getJsonResponse(T src) { HttpHeaders headers = new HttpHeaders(); - //headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity(src, headers, HttpStatus.OK); } @@ -42,16 +40,17 @@ public class RestUtil { * get JSON response from Object with HTTP status * * @param src + * @param status * @param * source class * @return @ResponseEntity */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static ResponseEntity getJsonResponse(T src, HttpStatus status) { - + HttpHeaders headers = new HttpHeaders(); -// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - Map map=new HashMap(); + Map map = new HashMap(); map.put("data", src); return new ResponseEntity(map, headers, status); } @@ -64,9 +63,9 @@ public class RestUtil { * @param * @return */ - public static ResponseEntity getJsonResponse(T src, - HttpStatus status, Map mapHeaderMessage) { - + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static ResponseEntity getJsonResponse(T src, HttpStatus status, + Map mapHeaderMessage) { HttpHeaders headers = new HttpHeaders(); @@ -76,14 +75,30 @@ public class RestUtil { } } - Map map=new HashMap(); + Map map = new HashMap(); map.put("messages", mapHeaderMessage); map.put("data", src); - //headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity(map, headers, status); } + /** + * + * @param status + * @param mapHeaderMessage + * @return + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static ResponseEntity getJsonResponse(HttpStatus status, Map mapHeaderMessage) { + HttpHeaders headers = new HttpHeaders(); + headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); + + Map map = new HashMap(); + map.put("messages", mapHeaderMessage); + + return new ResponseEntity(map, headers, status); + } + /** * get JSON response from HTTP status only * @@ -96,11 +111,8 @@ public class RestUtil { return new ResponseEntity(status); } - - - public static ResponseEntity getJsonHttptatus(HttpStatus status, - Map mapHeaderMessage) { + public static ResponseEntity getJsonHttptatus(HttpStatus status, Map mapHeaderMessage) { HttpHeaders headers = new HttpHeaders(); @@ -114,7 +126,7 @@ public class RestUtil { return new ResponseEntity(headers, status); } - + /** * get JSON response from Set Object * @@ -126,11 +138,10 @@ public class RestUtil { public static ResponseEntity> defaultJsonResponse(Set src) { HttpHeaders headers = new HttpHeaders(); -// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity>(src, headers, HttpStatus.OK); } - + /** * get JSON response from Set Object with custom header * @@ -143,16 +154,16 @@ public class RestUtil { public static ResponseEntity> defaultJsonResponse(Set src, Map mapHeaderMessage) { HttpHeaders headers = new HttpHeaders(); - + if (null != mapHeaderMessage) { for (String key : mapHeaderMessage.keySet()) { headers.add(key, mapHeaderMessage.get(key)); } - }// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + } headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity>(src, headers, HttpStatus.OK); } - + /** * get JSON response from List Object with custom header * @@ -164,19 +175,17 @@ public class RestUtil { */ public static ResponseEntity> defaultJsonResponse(List src, Map mapHeaderMessage) { HttpHeaders headers = new HttpHeaders(); - + if (null != mapHeaderMessage) { for (String key : mapHeaderMessage.keySet()) { headers.add(key, mapHeaderMessage.get(key)); } } - -// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity>(src, headers, HttpStatus.OK); } - /** * get JSON response from List Object * @@ -188,7 +197,6 @@ public class RestUtil { public static ResponseEntity> defaultJsonResponse(List src) { HttpHeaders headers = new HttpHeaders(); -// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity>(src, headers, HttpStatus.OK); } @@ -204,10 +212,8 @@ public class RestUtil { Gson gson = new Gson(); HttpHeaders headers = new HttpHeaders(); -// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - return new ResponseEntity(gson.toJson(src), headers, - HttpStatus.OK); + return new ResponseEntity(gson.toJson(src), headers, HttpStatus.OK); } /**