From ee37cbd4a371fa803c71d0b012c874cd734e54a9 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 21 Aug 2015 00:49:06 -0400 Subject: [PATCH] API: add support for generic entities --- .../src/com/netscape/certsrv/client/PKIClient.java | 5 ++++ .../com/netscape/certsrv/client/PKIConnection.java | 27 ++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/base/common/src/com/netscape/certsrv/client/PKIClient.java b/base/common/src/com/netscape/certsrv/client/PKIClient.java index 9015cfa38f76ac9b23e4baf7e79af06af6566888..5c13554fe87257bd4606c2a1e6e8828962a19d32 100644 --- a/base/common/src/com/netscape/certsrv/client/PKIClient.java +++ b/base/common/src/com/netscape/certsrv/client/PKIClient.java @@ -26,6 +26,7 @@ import java.security.cert.CertificateEncodingException; import java.util.Collection; import java.util.HashSet; +import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -112,6 +113,10 @@ public class PKIClient { return connection.getEntity(response, clazz); } + public T getEntity(Response response, GenericType clazz) { + return connection.getEntity(response, clazz); + } + public ClientConfig getConfig() { return config; } diff --git a/base/common/src/com/netscape/certsrv/client/PKIConnection.java b/base/common/src/com/netscape/certsrv/client/PKIConnection.java index 85b6c208227c0f079e69abfab3a24d953bb26716..fb7694615ed94aa21f3631ea39fbb243d63248a2 100644 --- a/base/common/src/com/netscape/certsrv/client/PKIConnection.java +++ b/base/common/src/com/netscape/certsrv/client/PKIConnection.java @@ -35,6 +35,7 @@ import java.util.Arrays; import java.util.List; import javax.ws.rs.client.Entity; +import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; @@ -408,15 +409,27 @@ public class PKIConnection { } public T getEntity(Response response, Class clazz) { + Family family = response.getStatusInfo().getFamily(); + if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) { + if (response.hasEntity()) return response.readEntity(clazz); + return null; + } + handleErrorResponse(response); + return null; + } - // handle HTTP status code 4xx and 5xx only + public T getEntity(Response response, GenericType clazz) { + Family family = response.getStatusInfo().getFamily(); + if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) { + if (response.hasEntity()) return response.readEntity(clazz); + return null; + } + handleErrorResponse(response); + return null; + } + + private void handleErrorResponse(Response response) { StatusType status = response.getStatusInfo(); - Family family = status.getFamily(); - if (!family.equals(Family.CLIENT_ERROR) && !family.equals(Family.SERVER_ERROR)) { - if (response.hasEntity()) return response.readEntity(clazz); - return null; - } - MediaType contentType = response.getMediaType(); if (!MediaType.APPLICATION_XML_TYPE.equals(contentType) -- 2.4.3