[Pki-devel] [PATCH] 674 Fixed error handling in TokenService.
Endi Sukma Dewata
edewata at redhat.com
Wed Feb 3 16:43:14 UTC 2016
The TokenService has been modified to re-throw the original
PKIException. This way on invalid token state transition the
client will receive the original BadRequestException. Other
types of exception will be wrapped with PKIException.
https://fedorahosted.org/pki/ticket/1684
--
Endi S. Dewata
-------------- next part --------------
From b7b9e87c2f4a0a516763f7d8fe714029a7b33bdb Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata at redhat.com>
Date: Wed, 3 Feb 2016 17:12:03 +0100
Subject: [PATCH] Fixed error handling in TokenService.
The TokenService has been modified to re-throw the original
PKIException. This way on invalid token state transition the
client will receive the original BadRequestException. Other
types of exception will be wrapped with PKIException.
https://fedorahosted.org/pki/ticket/1684
---
.../dogtagpki/server/tps/rest/TokenService.java | 73 +++++++++++++++-------
1 file changed, 52 insertions(+), 21 deletions(-)
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
index a504d3c33b317127647078387694a8eed19ea5b1..92ca882fd5c49a33c9fd3be28834db7dc1571f37 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
@@ -209,8 +209,8 @@ public class TokenService extends PKIService implements TokenResource {
try {
tokenID = URLEncoder.encode(tokenID, "UTF-8");
} catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- throw new PKIException(e.getMessage());
+ CMS.debug(e);
+ throw new PKIException(e);
}
URI uri = uriInfo.getBaseUriBuilder().path(TokenResource.class).path("{tokenID}").build(tokenID);
@@ -280,9 +280,12 @@ public class TokenService extends PKIService implements TokenResource {
return createOKResponse(response);
+ } catch (PKIException e) {
+ throw e;
+
} catch (Exception e) {
- e.printStackTrace();
- throw new PKIException(e.getMessage());
+ CMS.debug(e);
+ throw new PKIException(e);
}
}
@@ -299,9 +302,12 @@ public class TokenService extends PKIService implements TokenResource {
return createOKResponse(createTokenData(database.getRecord(tokenID)));
+ } catch (PKIException e) {
+ throw e;
+
} catch (Exception e) {
- e.printStackTrace();
- throw new PKIException(e.getMessage());
+ CMS.debug(e);
+ throw new PKIException(e);
}
}
@@ -336,12 +342,17 @@ public class TokenService extends PKIService implements TokenResource {
return createCreatedResponse(tokenData, tokenData.getLink().getHref());
} catch (Exception e) {
- e.printStackTrace();
+ CMS.debug(e);
+
+ msg = msg + ": " + e.getMessage();
subsystem.tdb.tdbActivity(ActivityDatabase.OP_ADD, tokenRecord,
ipAddress, msg, "failure", remoteUser);
- msg = msg + ":" + e;
- throw new PKIException(msg);
+ if (e instanceof PKIException) {
+ throw (PKIException)e;
+ }
+
+ throw new PKIException(e);
}
}
@@ -377,13 +388,18 @@ public class TokenService extends PKIService implements TokenResource {
return createOKResponse(tokenData);
} catch (Exception e) {
- e.printStackTrace();
+ CMS.debug(e);
+
+ msg = msg + ": " + e.getMessage();
subsystem.tdb.tdbActivity(ActivityDatabase.OP_DO_TOKEN, tokenRecord,
ipAddress, msg, "failure",
remoteUser);
- msg = msg + ":" + e;
- throw new PKIException(msg);
+ if (e instanceof PKIException) {
+ throw (PKIException)e;
+ }
+
+ throw new PKIException(e);
}
}
@@ -466,13 +482,18 @@ public class TokenService extends PKIService implements TokenResource {
return createOKResponse(tokenData);
} catch (Exception e) {
- e.printStackTrace();
+ CMS.debug(e);
+
+ msg = msg + ": " + e.getMessage();
subsystem.tdb.tdbActivity(ActivityDatabase.OP_DO_TOKEN, tokenRecord,
ipAddress, msg, "failure",
remoteUser);
- msg = msg + ":" + e;
- throw new PKIException(msg);
+ if (e instanceof PKIException) {
+ throw (PKIException)e;
+ }
+
+ throw new PKIException(e);
}
}
@@ -518,13 +539,18 @@ public class TokenService extends PKIService implements TokenResource {
return createOKResponse(tokenData);
} catch (Exception e) {
- e.printStackTrace();
- msg = msg + ": " + e;
+ CMS.debug(e);
+
+ msg = msg + ": " + e.getMessage();
subsystem.tdb.tdbActivity(ActivityDatabase.OP_DO_TOKEN, tokenRecord,
ipAddress, msg, "failure",
remoteUser);
- throw new PKIException(msg);
+ if (e instanceof PKIException) {
+ throw (PKIException)e;
+ }
+
+ throw new PKIException(e);
}
}
@@ -556,13 +582,18 @@ public class TokenService extends PKIService implements TokenResource {
return createNoContentResponse();
} catch (Exception e) {
- e.printStackTrace();
+ CMS.debug(e);
+
+ msg = msg + ": " + e.getMessage();
subsystem.tdb.tdbActivity(ActivityDatabase.OP_DELETE, tokenRecord,
ipAddress, msg, "failure",
remoteUser);
- msg = msg + ":" + e;
- throw new PKIException(msg);
+ if (e instanceof PKIException) {
+ throw (PKIException)e;
+ }
+
+ throw new PKIException(e);
}
}
}
--
2.4.3
More information about the Pki-devel
mailing list