Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2013-08-15 20:05:39 +0000
committerGerrit Code Review @ Eclipse.org2013-08-21 20:29:24 +0000
commit6b7b7d0e67c7e3f7059a041704167fcb38ce0834 (patch)
tree9a9a827d75a909606796cfd8006691481bf115be
parenta464fef91967e654a0a85079f2f23e18f290ad66 (diff)
downloadorg.eclipse.osee-6b7b7d0e67c7e3f7059a041704167fcb38ce0834.tar.gz
org.eclipse.osee-6b7b7d0e67c7e3f7059a041704167fcb38ce0834.tar.xz
org.eclipse.osee-6b7b7d0e67c7e3f7059a041704167fcb38ce0834.zip
bug: ORCS rest client fails to report exception
ORCS rest API can only convert OseeCoreException to ExceptionEntity. Therefore, when other exceptions are thrown by server side code such as NPE, the client fails to properly report the exception. Added a throwable exception mapper so all exceptions are mapped to ExceptionEntity and properly reported by the client. Change-Id: Iaeb321523622987b1d6583473ec73d3c0907e887
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/mappers/ThrowableExceptionMapper.java35
2 files changed, 37 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
index 880e4d87cc2..38a835a398f 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
@@ -15,6 +15,7 @@ import java.util.Set;
import javax.ws.rs.core.Application;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.rest.internal.mappers.OseeCoreExceptionMapper;
+import org.eclipse.osee.orcs.rest.internal.mappers.ThrowableExceptionMapper;
/**
* Get application.wadl at this context to get rest documentation
@@ -38,6 +39,7 @@ public class OrcsApplication extends Application {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(BranchesResource.class);
classes.add(OseeCoreExceptionMapper.class);
+ classes.add(ThrowableExceptionMapper.class);
return classes;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/mappers/ThrowableExceptionMapper.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/mappers/ThrowableExceptionMapper.java
new file mode 100644
index 00000000000..8317c8cf2cb
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/mappers/ThrowableExceptionMapper.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.mappers;
+
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.orcs.rest.model.ExceptionEntity;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Provider
+public class ThrowableExceptionMapper implements ExceptionMapper<Throwable> {
+
+ @Override
+ public Response toResponse(Throwable exception) {
+ ExceptionEntity entity = new ExceptionEntity(Lib.exceptionToString(exception));
+ GenericEntity<ExceptionEntity> ge = new GenericEntity<ExceptionEntity>(entity, ExceptionEntity.class);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON_TYPE).entity(ge).build();
+ }
+
+}

Back to the top