From f9da72c3408500c092f81d29870f28ff96e63d7b Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 17:04:42 -0500
Subject: [PATCH] Updated REST interface for TPS certificates.

The REST interface for TPS certificates has been modified to return
Response objects to allow better handling of server responses.

Ticket #554
---
 base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java | 8 ++++++--
 .../src/com/netscape/certsrv/tps/cert/TPSCertResource.java       | 9 +++++++--
 .../src/org/dogtagpki/server/tps/cert/TPSCertService.java        | 9 +++++----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
index 810c64758c7ed7eea10033ebae9b3022389df648..e1e192557eb092c6a509dead33292f30d46ce5f6 100644
--- a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
@@ -19,6 +19,8 @@ package com.netscape.certsrv.tps.cert;
 
 import java.net.URISyntaxException;
 
+import javax.ws.rs.core.Response;
+
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.PKIClient;
 
@@ -39,10 +41,12 @@ public class TPSCertClient extends Client {
     }
 
     public TPSCertCollection findCerts(Integer start, Integer size) {
-        return resource.findCerts(start, size);
+        Response response = resource.findCerts(start, size);
+        return client.getEntity(response, TPSCertCollection.class);
     }
 
     public TPSCertData getCert(String tokenID) {
-        return resource.getCert(tokenID);
+        Response response = resource.getCert(tokenID);
+        return client.getEntity(response, TPSCertData.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
index d56cd4669fcdccd7544631f6c9c54e86013f3b26..2ea24eed8e05d73c05c85962273caeb0c0b9f688 100644
--- a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
@@ -23,6 +23,9 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
 
 
 /**
@@ -32,13 +35,15 @@ import javax.ws.rs.core.MediaType;
 public interface TPSCertResource {
 
     @GET
+    @ClientResponseType(entityType=TPSCertCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public TPSCertCollection findCerts(
+    public Response findCerts(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @GET
     @Path("{certID}")
+    @ClientResponseType(entityType=TPSCertData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public TPSCertData getCert(@PathParam("certID") String certID);
+    public Response getCert(@PathParam("certID") String certID);
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
index cc05a11ec1a6a292c0bd9b7aee5a41959553c833..0397f5cc193750ee7effdf513ddd175044653a59 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.dogtagpki.server.tps.TPSSubsystem;
@@ -107,7 +108,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
     }
 
     @Override
-    public TPSCertCollection findCerts(Integer start, Integer size) {
+    public Response findCerts(Integer start, Integer size) {
 
         System.out.println("TPSCertService.findCerts()");
 
@@ -145,7 +146,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -154,7 +155,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
     }
 
     @Override
-    public TPSCertData getCert(String certID) {
+    public Response getCert(String certID) {
 
         if (certID == null) throw new BadRequestException("Certificate ID is null.");
 
@@ -164,7 +165,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TPSCertDatabase database = subsystem.getCertDatabase();
 
-            return createCertData(database.getRecord(certID));
+            return createOKResponse(createCertData(database.getRecord(certID)));
 
         } catch (Exception e) {
             e.printStackTrace();
-- 
1.8.4.2

