From a3ac7300633956f919cf4ad7820614090e648252 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 14:31:12 -0500
Subject: [PATCH] Updated REST interface for self tests.

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

Ticket #554
---
 .../src/com/netscape/certsrv/selftests/SelfTestClient.java  | 11 ++++++++---
 .../com/netscape/certsrv/selftests/SelfTestResource.java    | 12 +++++++++---
 .../src/com/netscape/cmscore/selftests/SelfTestService.java | 13 ++++++++-----
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
index e9a081bb479223b835f49a4a40b6c0f81fce35d1..a48698bfa26a5d0e392ece7d8e238791b0d3d29b 100644
--- a/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
+++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
@@ -19,6 +19,8 @@ package com.netscape.certsrv.selftests;
 
 import java.net.URISyntaxException;
 
+import javax.ws.rs.core.Response;
+
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.PKIClient;
 
@@ -39,14 +41,17 @@ public class SelfTestClient extends Client {
     }
 
     public SelfTestCollection findSelfTests(Integer start, Integer size) {
-        return resource.findSelfTests(start, size);
+        Response response = resource.findSelfTests(start, size);
+        return client.getEntity(response, SelfTestCollection.class);
     }
 
     public void executeSelfTests(String action) {
-        resource.executeSelfTests(action);
+        Response response = resource.executeSelfTests(action);
+        client.getEntity(response, Void.class);
     }
 
     public SelfTestData getSelfTest(String selfTestID) {
-        return resource.getSelfTest(selfTestID);
+        Response response = resource.getSelfTest(selfTestID);
+        return client.getEntity(response, SelfTestData.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
index 30be4a1d3e6fab596f3b3bba5517c7e3db9b700a..35c322d86b054280806ead7e77f737f05690e596 100644
--- a/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
+++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
@@ -24,6 +24,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;
 
 import com.netscape.certsrv.acls.ACLMapping;
 import com.netscape.certsrv.authentication.AuthMethodMapping;
@@ -38,18 +41,21 @@ import com.netscape.certsrv.authentication.AuthMethodMapping;
 public interface SelfTestResource {
 
     @GET
+    @ClientResponseType(entityType=SelfTestCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public SelfTestCollection findSelfTests(
+    public Response findSelfTests(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @POST
+    @ClientResponseType(entityType=Void.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
     @ACLMapping("selftests.execute")
-    public void executeSelfTests(@QueryParam("action") String action);
+    public Response executeSelfTests(@QueryParam("action") String action);
 
     @GET
     @Path("{selfTestID}")
+    @ClientResponseType(entityType=SelfTestData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public SelfTestData getSelfTest(@PathParam("selfTestID") String selfTestID);
+    public Response getSelfTest(@PathParam("selfTestID") String selfTestID);
 }
diff --git a/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestService.java b/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestService.java
index bd02b6752a70c2ba72b6245c94e6c9294b9de27a..bc632fee112bb697dae47e9e9de5da049e978b8b 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestService.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestService.java
@@ -28,6 +28,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.jboss.resteasy.plugins.providers.atom.Link;
@@ -93,7 +94,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
     }
 
     @Override
-    public SelfTestCollection findSelfTests(Integer start, Integer size) {
+    public Response findSelfTests(Integer start, Integer size) {
 
         CMS.debug("SelfTestService.findSelfTests()");
 
@@ -130,7 +131,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -139,7 +140,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
     }
 
     @Override
-    public SelfTestData getSelfTest(String selfTestID) {
+    public Response getSelfTest(String selfTestID) {
 
         if (selfTestID == null) throw new BadRequestException("Self test ID is null.");
 
@@ -147,7 +148,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
 
         try {
             ISelfTestSubsystem subsystem = (ISelfTestSubsystem)CMS.getSubsystem(ISelfTestSubsystem.ID);
-            return createSelfTestData(subsystem, selfTestID);
+            return createOKResponse(createSelfTestData(subsystem, selfTestID));
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -156,7 +157,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
     }
 
     @Override
-    public void executeSelfTests(String action) {
+    public Response executeSelfTests(String action) {
 
         if (action == null) throw new BadRequestException("Action is null.");
 
@@ -174,5 +175,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
             e.printStackTrace();
             throw new PKIException(e.getMessage());
         }
+
+        return createNoContentResponse();
     }
 }
-- 
1.8.4.2

