summaryrefslogtreecommitdiffstats
path: root/base/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-02-03 17:12:03 +0100
committerEndi S. Dewata <edewata@redhat.com>2016-02-03 19:47:23 +0100
commit86a9bb86f36edc9922e864b3e0bdc76af8bb5812 (patch)
tree9c9eeee30753fdb82ad99c9cd54b955a6b9f187c /base/tps
parentce872456a09f5c5d146c6cb465b2466ad3ddc73d (diff)
downloadpki-86a9bb86f36edc9922e864b3e0bdc76af8bb5812.tar.gz
pki-86a9bb86f36edc9922e864b3e0bdc76af8bb5812.tar.xz
pki-86a9bb86f36edc9922e864b3e0bdc76af8bb5812.zip
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
Diffstat (limited to 'base/tps')
-rw-r--r--base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java73
1 files 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 a504d3c33..92ca882fd 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);
}
}
}