Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-03-25 19:56:05 +0000
committerRyan D. Brooks2014-03-25 19:56:05 +0000
commit045c0f2cf983ffc9d0521cd2b58565afda14c921 (patch)
tree9f831a4757edd77ab43ec84a42ca56efff2d14ab /plugins/org.eclipse.osee.rest.admin
parent7b074a7cdf827167bde163da271d99b1056be553 (diff)
downloadorg.eclipse.osee-045c0f2cf983ffc9d0521cd2b58565afda14c921.tar.gz
org.eclipse.osee-045c0f2cf983ffc9d0521cd2b58565afda14c921.tar.xz
org.eclipse.osee-045c0f2cf983ffc9d0521cd2b58565afda14c921.zip
bug: Fix NPE in REST exception handling
When status code is not defined in javax.ws.core.Response.Status, conversion from int status code to Status type returns null. We should map the code to a new StatusType so we don't throw NPE. Change-Id: Ica11792d811c06cb3bc778776fe774912559c32c
Diffstat (limited to 'plugins/org.eclipse.osee.rest.admin')
-rw-r--r--plugins/org.eclipse.osee.rest.admin/src/org/eclipse/osee/rest/admin/internal/GenericExceptionMapper.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.rest.admin/src/org/eclipse/osee/rest/admin/internal/GenericExceptionMapper.java b/plugins/org.eclipse.osee.rest.admin/src/org/eclipse/osee/rest/admin/internal/GenericExceptionMapper.java
index 271e38da10c..e374f773ca0 100644
--- a/plugins/org.eclipse.osee.rest.admin/src/org/eclipse/osee/rest/admin/internal/GenericExceptionMapper.java
+++ b/plugins/org.eclipse.osee.rest.admin/src/org/eclipse/osee/rest/admin/internal/GenericExceptionMapper.java
@@ -13,6 +13,7 @@ package org.eclipse.osee.rest.admin.internal;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.eclipse.osee.logger.Log;
@@ -25,6 +26,7 @@ import org.eclipse.osee.rest.model.OseeWebApplicationException;
@Provider
public class GenericExceptionMapper implements ExceptionMapper<Throwable> {
+ private static final String SEE_HTTP_STATUS_CODES = "See HTTP Status codes";
private static final String INTERNAL_SERVER_ERROR_TYPE = "Internal Server Error";
private static final String APPLICATION_EXCEPTION_TYPE = "Web Application Exception";
private static final String OSEE_APPLICATION_EXCEPTION_TYPE = "Osee Web Application Exception";
@@ -51,7 +53,12 @@ public class GenericExceptionMapper implements ExceptionMapper<Throwable> {
Response response = webAppException.getResponse();
int statusCode = response.getStatus();
String message = webAppException.getMessage();
- exception = new OseeWebApplicationException(throwable, Status.fromStatusCode(statusCode), message);
+
+ javax.ws.rs.core.Response.StatusType status = Status.fromStatusCode(statusCode);
+ if (status == null) {
+ status = newStatusType(statusCode, Family.SERVER_ERROR, SEE_HTTP_STATUS_CODES);
+ }
+ exception = new OseeWebApplicationException(throwable, status, message);
} else {
isError = true;
logMessage = INTERNAL_SERVER_ERROR_TYPE;
@@ -67,4 +74,24 @@ public class GenericExceptionMapper implements ExceptionMapper<Throwable> {
return exception.getResponse();
}
+ private javax.ws.rs.core.Response.StatusType newStatusType(final int code, final Family family, final String reason) {
+ return new javax.ws.rs.core.Response.StatusType() {
+
+ @Override
+ public int getStatusCode() {
+ return code;
+ }
+
+ @Override
+ public Family getFamily() {
+ return family;
+ }
+
+ @Override
+ public String getReasonPhrase() {
+ return reason;
+ }
+
+ };
+ }
}

Back to the top