ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject [2/3] incubator-ranger git commit: RANGER-538: fix - error messages shown in ranger-admin lack details
Date Wed, 10 Jun 2015 18:17:13 GMT
RANGER-538: fix - error messages shown in ranger-admin lack details


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/43841b7a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/43841b7a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/43841b7a

Branch: refs/heads/ranger-0.5
Commit: 43841b7a546fd7857a24dea8dad3bdfe7c84a0fa
Parents: 08990c5
Author: Madhan Neethiraj <madhan@apache.org>
Authored: Mon Jun 8 15:50:44 2015 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Tue Jun 9 18:56:24 2015 -0700

----------------------------------------------------------------------
 .../org/apache/ranger/common/RESTErrorUtil.java |   9 +
 .../org/apache/ranger/common/ServiceUtil.java   |   2 +-
 .../java/org/apache/ranger/rest/AssetREST.java  |  25 +--
 .../org/apache/ranger/rest/ServiceREST.java     | 164 ++++++++++++-------
 .../org/apache/ranger/rest/TestServiceREST.java |  16 +-
 5 files changed, 134 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/43841b7a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
index a17da9b..c46964c 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
@@ -289,6 +289,15 @@ public class RESTErrorUtil {
 		return webAppEx;
 	}
 
+	public WebApplicationException createRESTException(String errorMessage) {
+		VXResponse gjResponse = new VXResponse();
+		gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
+		gjResponse.setMsgDesc(errorMessage);
+		WebApplicationException webAppEx = createRESTException(gjResponse);
+		logger.info("Operation error. response=" + gjResponse, webAppEx);
+		return webAppEx;
+	}
+
 	public WebApplicationException createRESTException(String errorMessage,
 			MessageEnums messageEnum) {
 		List<VXMessage> messageList = new ArrayList<VXMessage>();

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/43841b7a/security-admin/src/main/java/org/apache/ranger/common/ServiceUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/ServiceUtil.java b/security-admin/src/main/java/org/apache/ranger/common/ServiceUtil.java
index 7c2bbdc..8a637a0 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/ServiceUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/ServiceUtil.java
@@ -378,7 +378,7 @@ public class ServiceUtil {
 	private Map<String, RangerPolicy.RangerPolicyResource> toRangerResourceList(String
resourceString, String resourceType, Boolean isExcludes, Boolean isRecursive, Map<String,
RangerPolicy.RangerPolicyResource> resources) {
 		Map<String, RangerPolicy.RangerPolicyResource> ret = resources == null ? new HashMap<String,
RangerPolicy.RangerPolicyResource>() : resources;
 
-		if(resourceString != null) {
+		if(StringUtils.isNotBlank(resourceString)) {
 			RangerPolicy.RangerPolicyResource resource = ret.get(resourceType);
 
 			if(resource == null) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/43841b7a/security-admin/src/main/java/org/apache/ranger/rest/AssetREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/AssetREST.java b/security-admin/src/main/java/org/apache/ranger/rest/AssetREST.java
index 16528bd..e5de160 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/AssetREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/AssetREST.java
@@ -34,6 +34,7 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -650,13 +651,15 @@ public class AssetREST {
 			GrantRevokeRequest grantRevokeRequest = serviceUtil.toGrantRevokeRequest(vXPolicy);
 			try {
 				ret = serviceREST.grantAccess(serviceName, grantRevokeRequest, request);
-			} catch (Exception e) {
-				  logger.error( HttpServletResponse.SC_BAD_REQUEST + "Grant Access Failed for the request
" + vXPolicy ); 
-				  throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, "Grant
Access Failed for the request " + e.getMessage(), true);
+			} catch(WebApplicationException excp) {
+				throw excp;
+			} catch (Throwable e) {
+				  logger.error( HttpServletResponse.SC_BAD_REQUEST + "Grant Access Failed for the request
" + vXPolicy, e);
+				  throw restErrorUtil.createRESTException("Grant Access Failed for the request: " + vXPolicy
+ ". " + e.getMessage());
 			}
 		} else {
-			 logger.error( HttpServletResponse.SC_BAD_REQUEST + "Bad Request parameter " + vXPolicy
); 
-			 throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, "Bad Request
parameter " , true);
+			 logger.error( HttpServletResponse.SC_BAD_REQUEST + "Bad Request parameter");
+			 throw restErrorUtil.createRESTException("Bad Request parameter");
 		}
 		
 		if(logger.isDebugEnabled()) {
@@ -683,13 +686,15 @@ public class AssetREST {
 			GrantRevokeRequest grantRevokeRequest = serviceUtil.toGrantRevokeRequest(vXPolicy);
 			try {
 				 ret = serviceREST.revokeAccess(serviceName, grantRevokeRequest, request);
-			} catch (Exception e) {
-				  logger.error( HttpServletResponse.SC_BAD_REQUEST + "Revoke Access Failed for the request
" + vXPolicy ); 
-				  throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, "Grant
Access Failed for the request " + e.getMessage(), true);
+			} catch(WebApplicationException excp) {
+				throw excp;
+			} catch (Throwable e) {
+				  logger.error( HttpServletResponse.SC_BAD_REQUEST + "Revoke Access Failed for the request
" + vXPolicy, e);
+				  throw restErrorUtil.createRESTException("Revoke Access Failed for the request: " +
vXPolicy + ". " + e.getMessage());
 			}
 		} else {
-			 logger.error( HttpServletResponse.SC_BAD_REQUEST + "Bad Request parameter " + vXPolicy
); 
-			 throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, "Bad Request
parameter " , true);
+			 logger.error( HttpServletResponse.SC_BAD_REQUEST + "Bad Request parameter");
+			 throw restErrorUtil.createRESTException("Bad Request parameter");
 		}
 		
 		if(logger.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/43841b7a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index f9464ec..3d2e8b0 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -171,10 +171,12 @@ public class ServiceREST {
 			bizUtil.hasKMSPermissions("Service-Def", serviceDef.getImplClass());
 
 			ret = svcStore.createServiceDef(serviceDef);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("createServiceDef(" + serviceDef + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -203,10 +205,12 @@ public class ServiceREST {
 			bizUtil.hasKMSPermissions("Service-Def", serviceDef.getImplClass());
 
 			ret = svcStore.updateServiceDef(serviceDef);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("updateServiceDef(" + serviceDef + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -240,10 +244,12 @@ public class ServiceREST {
 			}
 			
 			svcStore.deleteServiceDef(id, forceDelete);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("deleteServiceDef(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -270,10 +276,12 @@ public class ServiceREST {
 			}
 
 			ret = svcStore.getServiceDef(id);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getServiceDef(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(ret == null) {
@@ -308,10 +316,12 @@ public class ServiceREST {
 			}
 
 			ret = svcStore.getServiceDefByName(name);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getServiceDefByName(" + name + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(ret == null) {
@@ -339,10 +349,12 @@ public class ServiceREST {
 
 		try {
 			ret = svcStore.getPaginatedServiceDefs(filter);
-		} catch (Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
 			LOG.error("getServiceDefs() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if (LOG.isDebugEnabled()) {
@@ -375,10 +387,12 @@ public class ServiceREST {
 			bizUtil.hasKMSPermissions("Service", xxServiceDef.getImplclassname());
 
 			ret = svcStore.createService(service);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("createService(" + service + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -412,10 +426,12 @@ public class ServiceREST {
 			bizUtil.hasKMSPermissions("Service", xxServiceDef.getImplclassname());
 
 			ret = svcStore.updateService(service);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("updateService(" + service + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -448,10 +464,12 @@ public class ServiceREST {
 			bizUtil.hasKMSPermissions("Service", xxServiceDef.getImplclassname());
 
 			svcStore.deleteService(id);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("deleteService(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -471,10 +489,12 @@ public class ServiceREST {
 
 		try {
 			ret = svcStore.getService(id);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getService(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(ret == null) {
@@ -500,10 +520,12 @@ public class ServiceREST {
 
 		try {
 			ret = svcStore.getServiceByName(name);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getServiceByName(" + name + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(ret == null) {
@@ -531,10 +553,12 @@ public class ServiceREST {
 
 		try {
 			ret = svcStore.getPaginatedServices(filter);
-		} catch (Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
 			LOG.error("getServices() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if (LOG.isDebugEnabled()) {
@@ -552,10 +576,12 @@ public class ServiceREST {
 
 		try {
 			ret = svcStore.getServices(filter);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getServices() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -580,10 +606,12 @@ public class ServiceREST {
 			List<RangerService> services = getServices(request).getServices();
 			
 			ret = new Long(services == null ? 0 : services.size());
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("countServices() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -605,10 +633,12 @@ public class ServiceREST {
 
 		try {
 			ret = serviceMgr.validateConfig(service, svcStore);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("validateConfig(" + service + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -630,10 +660,12 @@ public class ServiceREST {
 
 		try {
 			ret = serviceMgr.lookupResource(serviceName,context, svcStore);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("lookupResource(" + serviceName + ", " + context + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -779,10 +811,10 @@ public class ServiceREST {
 				}
 			} catch(WebApplicationException excp) {
 				throw excp;
-			} catch(Exception excp) {
+			} catch(Throwable excp) {
 				LOG.error("grantAccess(" + serviceName + ", " + grantRequest + ") failed", excp);
 	
-				throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+				throw restErrorUtil.createRESTException(excp.getMessage());
 			}
 	
 			ret.setStatusCode(RESTResponse.STATUS_SUCCESS);
@@ -876,10 +908,10 @@ public class ServiceREST {
 				}
 			} catch(WebApplicationException excp) {
 				throw excp;
-			} catch(Exception excp) {
+			} catch(Throwable excp) {
 				LOG.error("revokeAccess(" + serviceName + ", " + revokeRequest + ") failed", excp);
 	
-				throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+				throw restErrorUtil.createRESTException(excp.getMessage());
 			}
 	
 			ret.setStatusCode(RESTResponse.STATUS_SUCCESS);
@@ -926,14 +958,12 @@ public class ServiceREST {
 			ensureAdminAccess(policy.getService(), policy.getResources());
 
 			ret = svcStore.createPolicy(policy);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("createPolicy(" + policy + ") failed", excp);
 
-			if(excp instanceof WebApplicationException) {
-				throw (WebApplicationException)excp;
-			}
-
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -960,10 +990,12 @@ public class ServiceREST {
 			ensureAdminAccess(policy.getService(), policy.getResources());
 
 			ret = svcStore.updatePolicy(policy);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("updatePolicy(" + policy + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -990,10 +1022,12 @@ public class ServiceREST {
 			ensureAdminAccess(policy.getService(), policy.getResources());
 
 			svcStore.deletePolicy(id);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("deletePolicy(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -1017,10 +1051,12 @@ public class ServiceREST {
 			if(ret != null) {
 				ensureAdminAccess(ret.getService(), ret.getResources());
 			}
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getPolicy(" + id + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(ret == null) {
@@ -1050,10 +1086,12 @@ public class ServiceREST {
 			ret = svcStore.getPaginatedPolicies(filter);
 
 			applyAdminAccessFilter(ret);
-		} catch (Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
 			LOG.error("getPolicies() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if (LOG.isDebugEnabled()) {
@@ -1073,10 +1111,12 @@ public class ServiceREST {
 			ret = svcStore.getPolicies(filter);
 
 			applyAdminAccessFilter(ret);
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("getPolicies() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -1102,10 +1142,12 @@ public class ServiceREST {
 			applyAdminAccessFilter(policies);
 			
 			ret = new Long(policies == null ? 0 : policies.size());
-		} catch(Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch(Throwable excp) {
 			LOG.error("countPolicies() failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if(LOG.isDebugEnabled()) {
@@ -1132,10 +1174,12 @@ public class ServiceREST {
 			ret = svcStore.getPaginatedServicePolicies(serviceId, filter);
 
 			applyAdminAccessFilter(ret);
-		} catch (Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
 			LOG.error("getServicePolicies(" + serviceId + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if (ret == null) {
@@ -1166,10 +1210,12 @@ public class ServiceREST {
 			ret = svcStore.getPaginatedServicePolicies(serviceName, filter);
 
 			applyAdminAccessFilter(ret);
-		} catch (Exception excp) {
+		} catch(WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
 			LOG.error("getServicePolicies(" + serviceName + ") failed", excp);
 
-			throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(),
true);
+			throw restErrorUtil.createRESTException(excp.getMessage());
 		}
 
 		if (ret == null) {
@@ -1211,7 +1257,7 @@ public class ServiceREST {
 					httpCode = HttpServletResponse.SC_OK;
 					logMsg   = "Returning " + (ret.getPolicies() != null ? ret.getPolicies().size() : 0)
+ " policies. Policy version=" + ret.getPolicyVersion();
 				}
-			} catch(Exception excp) {
+			} catch(Throwable excp) {
 				LOG.error("getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ")
failed", excp);
 	
 				httpCode = HttpServletResponse.SC_BAD_REQUEST;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/43841b7a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
index f024b99..e7324a1 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
@@ -742,9 +742,7 @@ public class TestServiceREST {
 		Mockito.when(userMgr.getGroupsForUser(userName)).thenReturn(
 				userGroupsList);
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						HttpServletResponse.SC_BAD_REQUEST, null, true))
+		Mockito.when(restErrorUtil.createRESTException((String)null))
 				.thenThrow(new WebApplicationException());
 		thrown.expect(WebApplicationException.class);
 
@@ -780,9 +778,7 @@ public class TestServiceREST {
 		Mockito.when(userMgr.getGroupsForUser(userName)).thenReturn(
 				userGroupsList);
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						HttpServletResponse.SC_BAD_REQUEST, null, true))
+		Mockito.when(restErrorUtil.createRESTException((String)null))
 				.thenThrow(new WebApplicationException());
 		thrown.expect(WebApplicationException.class);
 		RangerPolicy dbRangerPolicy = serviceREST.updatePolicy(rangerPolicy);
@@ -815,9 +811,7 @@ public class TestServiceREST {
 		Mockito.when(userMgr.getGroupsForUser(userName)).thenReturn(
 				userGroupsList);
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						HttpServletResponse.SC_BAD_REQUEST, null, true))
+		Mockito.when(restErrorUtil.createRESTException((String)null))
 				.thenThrow(new WebApplicationException());
 		thrown.expect(WebApplicationException.class);
 		serviceREST.deletePolicy(rangerPolicy.getId());
@@ -848,9 +842,7 @@ public class TestServiceREST {
 		Mockito.when(userMgr.getGroupsForUser(userName)).thenReturn(
 				userGroupsList);
 
-		Mockito.when(
-				restErrorUtil.createRESTException(
-						HttpServletResponse.SC_BAD_REQUEST, null, true))
+		Mockito.when(restErrorUtil.createRESTException((String)null))
 				.thenThrow(new WebApplicationException());
 		thrown.expect(WebApplicationException.class);
 		RangerPolicy dbRangerPolicy = serviceREST.getPolicy(rangerPolicy


Mime
View raw message