From 79347d7a1c39f5f724a1f73e5600bfab81afd8e6 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 16:43:23 -0500
Subject: [PATCH] Updated REST interface for TPS authenticators.

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

Ticket #554
---
 .../tps/authenticator/AuthenticatorClient.java     |  9 +++++---
 .../tps/authenticator/AuthenticatorResource.java   |  9 +++++---
 .../tps/authenticator/AuthenticatorService.java    | 25 +++++++++-------------
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
index 427cbf1107bcde3146284398d127bb33473a363e..c9c7b83f3573033fb06913b1fa0430ed9a9e434d 100644
--- a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
@@ -41,11 +41,13 @@ public class AuthenticatorClient extends Client {
     }
 
     public AuthenticatorCollection findAuthenticators(Integer start, Integer size) {
-        return resource.findAuthenticators(start, size);
+        Response response = resource.findAuthenticators(start, size);
+        return client.getEntity(response, AuthenticatorCollection.class);
     }
 
     public AuthenticatorData getAuthenticator(String authenticatorID) {
-        return resource.getAuthenticator(authenticatorID);
+        Response response = resource.getAuthenticator(authenticatorID);
+        return client.getEntity(response, AuthenticatorData.class);
     }
 
     public AuthenticatorData addAuthenticator(AuthenticatorData authenticatorData) {
@@ -64,6 +66,7 @@ public class AuthenticatorClient extends Client {
     }
 
     public void removeAuthenticator(String authenticatorID) {
-        resource.removeAuthenticator(authenticatorID);
+        Response response = resource.removeAuthenticator(authenticatorID);
+        client.getEntity(response, Void.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
index 1f925314468c15ff2a1c7583d712f99089d17f1c..452f8ea56f7e4d213b7561ea7110cf878d7c6ee1 100644
--- a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
@@ -44,15 +44,17 @@ import com.netscape.certsrv.authentication.AuthMethodMapping;
 public interface AuthenticatorResource {
 
     @GET
+    @ClientResponseType(entityType=AuthenticatorCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public AuthenticatorCollection findAuthenticators(
+    public Response findAuthenticators(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @GET
     @Path("{authenticatorID}")
+    @ClientResponseType(entityType=AuthenticatorData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public AuthenticatorData getAuthenticator(@PathParam("authenticatorID") String authenticatorID);
+    public Response getAuthenticator(@PathParam("authenticatorID") String authenticatorID);
 
     @POST
     @ACLMapping("authenticators.add")
@@ -83,7 +85,8 @@ public interface AuthenticatorResource {
 
     @DELETE
     @Path("{authenticatorID}")
+    @ClientResponseType(entityType=Void.class)
     @ACLMapping("authenticators.remove")
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public void removeAuthenticator(@PathParam("authenticatorID") String authenticatorID);
+    public Response removeAuthenticator(@PathParam("authenticatorID") String authenticatorID);
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
index 8a02779279e588bda96f7734cf349909572a0b90..282ee4c0e44bde505e1d513ba68afd74242ba2bf 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
@@ -93,7 +93,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
     }
 
     @Override
-    public AuthenticatorCollection findAuthenticators(Integer start, Integer size) {
+    public Response findAuthenticators(Integer start, Integer size) {
 
         CMS.debug("AuthenticatorService.findAuthenticators()");
 
@@ -131,7 +131,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (PKIException e) {
             throw e;
@@ -143,7 +143,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
     }
 
     @Override
-    public AuthenticatorData getAuthenticator(String authenticatorID) {
+    public Response getAuthenticator(String authenticatorID) {
 
         if (authenticatorID == null) throw new BadRequestException("Authenticator ID is null.");
 
@@ -153,7 +153,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
-            return createAuthenticatorData(database.getRecord(authenticatorID));
+            return createOKResponse(createAuthenticatorData(database.getRecord(authenticatorID)));
 
         } catch (PKIException e) {
             throw e;
@@ -178,10 +178,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
             database.addRecord(authenticatorData.getID(), createAuthenticatorRecord(authenticatorData));
             authenticatorData = createAuthenticatorData(database.getRecord(authenticatorData.getID()));
 
-            return Response
-                    .created(authenticatorData.getLink().getHref())
-                    .entity(authenticatorData)
-                    .build();
+            return createCreatedResponse(authenticatorData, authenticatorData.getLink().getHref());
 
         } catch (PKIException e) {
             throw e;
@@ -227,9 +224,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
 
             authenticatorData = createAuthenticatorData(database.getRecord(authenticatorID));
 
-            return Response
-                    .ok(authenticatorData)
-                    .build();
+            return createOKResponse(authenticatorData);
 
         } catch (PKIException e) {
             throw e;
@@ -287,9 +282,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
 
             AuthenticatorData authenticatorData = createAuthenticatorData(database.getRecord(authenticatorID));
 
-            return Response
-                    .ok(authenticatorData)
-                    .build();
+            return createOKResponse(authenticatorData);
 
         } catch (PKIException e) {
             throw e;
@@ -301,7 +294,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
     }
 
     @Override
-    public void removeAuthenticator(String authenticatorID) {
+    public Response removeAuthenticator(String authenticatorID) {
 
         if (authenticatorID == null) throw new BadRequestException("Authenticator ID is null.");
 
@@ -320,6 +313,8 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
 
             database.removeRecord(authenticatorID);
 
+            return createNoContentResponse();
+
         } catch (PKIException e) {
             throw e;
 
-- 
1.8.4.2

