diff options
author | Nelson, Thomas (arthurdent3) <nelson24@att.com> | 2019-05-28 04:18:08 +0000 |
---|---|---|
committer | Nelson, Thomas (arthurdent3) <nelson24@att.com> | 2019-05-28 04:18:08 +0000 |
commit | 9943f1e32b2db7f40ec77243ea235c889eded8f9 (patch) | |
tree | f9b69bb030e63c17d6472bd654c8a9275a2072d7 /src/main | |
parent | 641255c612fae09ff8840124eb7dcf5046083dd0 (diff) |
Bug Fix for Empty Body.
Updated a few missing checks for this.
Update api name, add properties to be more forgiving for lock type
Change-Id: I4743110bdc654e4346052bd0e045270fd4925417
Issue-ID: MUSIC-398
Signed-off-by: Nelson, Thomas (arthurdent3) <nelson24@att.com>
Diffstat (limited to 'src/main')
4 files changed, 55 insertions, 35 deletions
diff --git a/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java index 83bb1b8a..c31fcf73 100644 --- a/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java +++ b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java @@ -37,18 +37,20 @@ public class MusicExceptionMapper implements ExceptionMapper<Exception> { public Response toResponse(Exception exception) { if(exception instanceof UnrecognizedPropertyException) { return Response.status(Response.Status.BAD_REQUEST). - entity(new JsonResponse(ResultType.FAILURE).setError("Unknown field :"+((UnrecognizedPropertyException) exception).getUnrecognizedPropertyName()).toMap()). - build(); - } - else if(exception instanceof EOFException) { + entity(new JsonResponse(ResultType.FAILURE).setError("Unknown field :"+((UnrecognizedPropertyException) exception).getUnrecognizedPropertyName()).toMap()). + build(); + } else if(exception instanceof EOFException) { return Response.status(Response.Status.BAD_REQUEST). - entity(new JsonResponse(ResultType.FAILURE).setError("Request body cannot be empty").toMap()). - build(); - } - else { + entity(new JsonResponse(ResultType.FAILURE).setError("Request body cannot be empty").toMap()). + build(); + } else if(exception instanceof NullPointerException) { + return Response.status(Response.Status.BAD_REQUEST). + entity(new JsonResponse(ResultType.FAILURE).setError("NullPointerException - Please check to make sure all inputs are valid.").toMap()). + build(); + } else { return Response.status(Response.Status.BAD_REQUEST). - entity(new JsonResponse(ResultType.FAILURE).setError(exception.getMessage()).toMap()). - build(); + entity(new JsonResponse(ResultType.FAILURE).setError(exception.getMessage()).toMap()). + build(); } } } diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index 09898c79..219e713c 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -145,9 +145,9 @@ public class RestMusicDataAPI { @ApiParam(value = "Major Version",required = true) @PathParam("version") String version, @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, - @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns, + @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns, JsonKeySpace kspObject, @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) { try { @@ -231,9 +231,9 @@ public class RestMusicDataAPI { @ApiParam(value = "Major Version",required = true) @PathParam("version") String version, @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, - @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns, + @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) throws Exception { try { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); @@ -282,14 +282,18 @@ public class RestMusicDataAPI { @ApiParam(value = "Major Version",required = true) @PathParam("version") String version, @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, - @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns, + @ApiParam(value = "AID", required = false,hidden = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, JsonTable tableObj, @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace, @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception { try { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); + if ( null == tableObj ) { + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) + .setError(ResultType.BODYMISSING.getResult()).toMap()).build(); + } if(keyspace == null || keyspace.isEmpty() || tablename == null || tablename.isEmpty()){ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) .setError("One or more path parameters are not set, please check and try again." @@ -562,8 +566,8 @@ public class RestMusicDataAPI { @ApiParam(value = "Major Version",required = true) @PathParam("version") String version, @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, - @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, JsonInsert insObj, @ApiParam(value = "Keyspace Name", @@ -572,10 +576,14 @@ public class RestMusicDataAPI { required = true) @PathParam("tablename") String tablename) { try { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); - if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){ + if ( null == insObj ) { return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) - .setError("one or more path parameters are not set, please check and try again") - .toMap()).build(); + .setError(ResultType.BODYMISSING.getResult()).toMap()).build(); + } + if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){ + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) + .setError("one or more path parameters are not set, please check and try again") + .toMap()).build(); } EELFLoggerDelegate.mdcPut("keyspace","(" + keyspace + ")"); PreparedQueryObject queryObject = new PreparedQueryObject(); @@ -766,9 +774,9 @@ public class RestMusicDataAPI { required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version", required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Application namespace", - required = true) @HeaderParam(NS) String ns, + required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, JsonUpdate updateObj, @ApiParam(value = "Keyspace Name", @@ -778,6 +786,10 @@ public class RestMusicDataAPI { @Context UriInfo info) throws MusicQueryException, MusicServiceException { try { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); + if ( null == updateObj ) { + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) + .setError(ResultType.BODYMISSING.getResult()).toMap()).build(); + } if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) .setError("one or more path parameters are not set, please check and try again") @@ -985,9 +997,9 @@ public class RestMusicDataAPI { required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version", required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Application namespace", - required = true) @HeaderParam(NS) String ns, + required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, JsonDelete delObj, @ApiParam(value = "Keyspace Name", @@ -1004,8 +1016,8 @@ public class RestMusicDataAPI { } EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) "); if(delObj == null) { - logger.error(EELFLoggerDelegate.errorLogger,"Required HTTP Request body is missing.", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR); - return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap()).build(); + logger.error(EELFLoggerDelegate.errorLogger,ResultType.BODYMISSING.getResult(), AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR); + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build(); } PreparedQueryObject queryObject = new PreparedQueryObject(); StringBuilder columnString = new StringBuilder(); @@ -1130,9 +1142,9 @@ public class RestMusicDataAPI { required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version", required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false,hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Application namespace", - required = true) @HeaderParam(NS) String ns, + required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, @ApiParam(value = "Keyspace Name", required = true) @PathParam("keyspace") String keyspace, @@ -1181,9 +1193,9 @@ public class RestMusicDataAPI { required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version", required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Application namespace", - required = true) @HeaderParam(NS) String ns, + required = false, hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, JsonInsert selObj, @ApiParam(value = "Keyspace Name", @@ -1198,6 +1210,11 @@ public class RestMusicDataAPI { .setError("one or more path parameters are not set, please check and try again") .toMap()).build(); } + if(selObj == null) { + logger.error(EELFLoggerDelegate.errorLogger,ResultType.BODYMISSING.getResult(), AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR); + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build(); + } + EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) "); String lockId = selObj.getConsistencyInfo().get("lockId"); PreparedQueryObject queryObject = new PreparedQueryObject(); @@ -1259,9 +1276,9 @@ public class RestMusicDataAPI { required = false) @HeaderParam(XMINORVERSION) String minorVersion, @ApiParam(value = "Patch Version", required = false) @HeaderParam(XPATCHVERSION) String patchVersion, - @ApiParam(value = "AID", required = false) @HeaderParam("aid") String aid, + @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid, @ApiParam(value = "Application namespace", - required = true) @HeaderParam(NS) String ns, + required = false,hidden = true) @HeaderParam(NS) String ns, @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization, @ApiParam(value = "Keyspace Name", required = true) @PathParam("keyspace") String keyspace, diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java index e27c08ee..079fe97c 100644 --- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java @@ -263,7 +263,7 @@ public class RestMusicLocksAPI { } @GET - @Path("/getCurrentLockHolders/{lockname}") + @Path("/holders/{lockname}") @ApiOperation(value = "Get Lock Holders", notes = "Gets the current Lock Holders", response = Map.class) @@ -335,7 +335,7 @@ public class RestMusicLocksAPI { String who = MusicCore.whoseTurnIsIt(lockName); ResultType status = ResultType.SUCCESS; String error = ""; - if ( who == null ) { + if ( who == null ) { status = ResultType.FAILURE; error = "There was a problem getting the lock holder"; logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b905be6..6fbe6326 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,3 +6,4 @@ server.ssl.key-store-password=changeit server.ssl.key-store-provider=SUN server.ssl.key-store-type=JKS httpPort=8081 +spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS=true |