diff options
author | Endi S. Dewata <edewata@redhat.com> | 2014-02-14 16:43:23 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2014-02-18 11:35:55 -0500 |
commit | 4e6bd3661910eae5670f9e029fe370c7c9138d83 (patch) | |
tree | 7a56c752844d613735672352876a50452821958f | |
parent | 9c3f874fa00f71c75bd7f90537bcdd6aab1d70c6 (diff) | |
download | pki-4e6bd3661910eae5670f9e029fe370c7c9138d83.tar.gz pki-4e6bd3661910eae5670f9e029fe370c7c9138d83.tar.xz pki-4e6bd3661910eae5670f9e029fe370c7c9138d83.zip |
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
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 427cbf110..c9c7b83f3 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 1f9253144..452f8ea56 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 8a0277927..282ee4c0e 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; |