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

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

Ticket #554
---
 base/common/src/com/netscape/certsrv/logging/ActivityClient.java | 8 ++++++--
 .../src/com/netscape/certsrv/logging/ActivityResource.java       | 9 +++++++--
 .../src/org/dogtagpki/server/tps/logging/ActivityService.java    | 9 +++++----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityClient.java b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
index 48ecdd5c4c99e1603c845994fa0d92e36a626132..eae2f6f4829c82ca5d1c89cfbf2d389f13e43cae 100644
--- a/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
@@ -19,6 +19,8 @@ package com.netscape.certsrv.logging;
 
 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 ActivityClient extends Client {
     }
 
     public ActivityCollection findActivities(Integer start, Integer size) {
-        return resource.findActivities(start, size);
+        Response response = resource.findActivities(start, size);
+        return client.getEntity(response, ActivityCollection.class);
     }
 
     public ActivityData getActivity(String tokenID) {
-        return resource.getActivity(tokenID);
+        Response response = resource.getActivity(tokenID);
+        return client.getEntity(response, ActivityData.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityResource.java b/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
index 6ecf41dd247c6c47fcb39b133f42a94bf885252e..715233e63028cc9d53c17f3875c6c19d7fab8e7b 100644
--- a/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityResource.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 ActivityResource {
 
     @GET
+    @ClientResponseType(entityType=ActivityCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ActivityCollection findActivities(
+    public Response findActivities(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @GET
     @Path("{activityID}")
+    @ClientResponseType(entityType=ActivityData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ActivityData getActivity(@PathParam("activityID") String activityID);
+    public Response getActivity(@PathParam("activityID") String activityID);
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java
index a97a4775c3463be61705d127f809234f7f5c7f9e..0bed20311c05ab29fe969df55abf2982a4259c25 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.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;
@@ -97,7 +98,7 @@ public class ActivityService extends PKIService implements ActivityResource {
     }
 
     @Override
-    public ActivityCollection findActivities(Integer start, Integer size) {
+    public Response findActivities(Integer start, Integer size) {
 
         CMS.debug("ActivityService.findActivities()");
 
@@ -135,7 +136,7 @@ public class ActivityService extends PKIService implements ActivityResource {
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -144,7 +145,7 @@ public class ActivityService extends PKIService implements ActivityResource {
     }
 
     @Override
-    public ActivityData getActivity(String activityID) {
+    public Response getActivity(String activityID) {
 
         if (activityID == null) throw new BadRequestException("Activity ID is null.");
 
@@ -154,7 +155,7 @@ public class ActivityService extends PKIService implements ActivityResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ActivityDatabase database = subsystem.getActivityDatabase();
 
-            return createActivityData(database.getRecord(activityID));
+            return createOKResponse(createActivityData(database.getRecord(activityID)));
 
         } catch (Exception e) {
             e.printStackTrace();
-- 
1.8.4.2

