From d02448197e18610a6ee1ec6215a29e723d61957b Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 7 Feb 2014 12:12:59 -0500
Subject: [PATCH] Removed hard-coded response type.

Previously some methods were hard-coded to return XML responses.
The code has been removed to allow clients to request a different
format.

Ticket #554
---
 base/common/src/com/netscape/certsrv/base/PKIException.java      | 9 ++++++---
 .../src/com/netscape/cms/servlet/admin/GroupMemberProcessor.java | 2 --
 .../cms/src/com/netscape/cms/servlet/admin/GroupService.java     | 3 ---
 .../cms/src/com/netscape/cms/servlet/admin/UserService.java      | 6 ------
 .../cms/src/com/netscape/cms/servlet/profile/ProfileService.java | 3 ---
 .../src/com/netscape/cms/servlet/request/KeyRequestService.java  | 4 ----
 .../src/com/netscape/cms/servlet/tks/TPSConnectorService.java    | 3 ---
 .../cmscore/src/com/netscape/cmscore/logging/AuditService.java   | 2 --
 .../dogtagpki/server/tps/authenticator/AuthenticatorService.java | 4 ----
 .../src/org/dogtagpki/server/tps/config/ConfigService.java       | 2 --
 .../org/dogtagpki/server/tps/connection/ConnectionService.java   | 4 ----
 .../org/dogtagpki/server/tps/profile/ProfileMappingService.java  | 4 ----
 .../src/org/dogtagpki/server/tps/profile/ProfileService.java     | 4 ----
 .../src/org/dogtagpki/server/tps/token/TokenService.java         | 4 ----
 14 files changed, 6 insertions(+), 48 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/base/PKIException.java b/base/common/src/com/netscape/certsrv/base/PKIException.java
index f1f37735273c9fbae2cb5da5e2eaef705d4385c9..74e13c747d7c9202cada36bbe4773bcd4c16d857 100644
--- a/base/common/src/com/netscape/certsrv/base/PKIException.java
+++ b/base/common/src/com/netscape/certsrv/base/PKIException.java
@@ -17,7 +17,11 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.certsrv.base;
 
-import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
@@ -97,11 +101,10 @@ public class PKIException extends RuntimeException {
     public static class Mapper implements ExceptionMapper<PKIException> {
 
         public Response toResponse(PKIException exception) {
-            // convert PKIException into HTTP response with XML content
+            // convert PKIException into HTTP response
             return Response
                     .status(exception.getCode())
                     .entity(exception.getData())
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         }
     }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupMemberProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupMemberProcessor.java
index b38277dd03c1f3fd905ab429d552e65245b8a3df..429fbea17880fcc0543f3898eb592237b28a1c9b 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupMemberProcessor.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupMemberProcessor.java
@@ -23,7 +23,6 @@ import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Map;
 
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
@@ -245,7 +244,6 @@ public class GroupMemberProcessor extends Processor {
             return Response
                     .created(groupMemberData.getLink().getHref())
                     .entity(groupMemberData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
index 722979d7966ca76425ee53aca006cddc6d75c89c..4998212d566f1ac61b4334e1466e3e5dd0e0dd97 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
@@ -26,7 +26,6 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -223,7 +222,6 @@ public class GroupService extends PKIService implements GroupResource {
             return Response
                     .created(groupData.getLink().getHref())
                     .entity(groupData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -286,7 +284,6 @@ public class GroupService extends PKIService implements GroupResource {
 
             return Response
                     .ok(groupData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java b/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
index 265fe3e1bdef2e4c04f4796dbddc1beda0fe042f..130103a87bd467f92b45c755047dec77aba1b974 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
@@ -35,7 +35,6 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -366,7 +365,6 @@ public class UserService extends PKIService implements UserResource {
             return Response
                     .created(userData.getLink().getHref())
                     .entity(userData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -445,7 +443,6 @@ public class UserService extends PKIService implements UserResource {
 
             return Response
                     .ok(userData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -537,7 +534,6 @@ public class UserService extends PKIService implements UserResource {
 
             return Response
                     .ok(userData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -927,7 +923,6 @@ public class UserService extends PKIService implements UserResource {
                 return Response
                         .created(userCertData.getLink().getHref())
                         .entity(userCertData)
-                        .type(MediaType.APPLICATION_XML)
                         .build();
 
             } catch (CertificateExpiredException e) {
@@ -1117,7 +1112,6 @@ public class UserService extends PKIService implements UserResource {
             return Response
                     .created(userMembershipData.getLink().getHref())
                     .entity(userMembershipData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
index 02840451c4ae772f6721180c06e700db1a1e407e..fe80892d7885b6f1d00339cf5ead79695d7cb1ad 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
@@ -34,7 +34,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
@@ -504,7 +503,6 @@ public class ProfileService extends PKIService implements ProfileResource {
             return Response
                     .created(profileData.getLink().getHref())
                     .entity(profileData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (EBaseException | IOException e) {
@@ -551,7 +549,6 @@ public class ProfileService extends PKIService implements ProfileResource {
             ProfileData profileData = createProfileData(profileId);
             return Response
                     .ok(profileData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException e) {
             CMS.debug("modifyProfile: error obtaining profile `" + profileId + "`: " + e);
diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java b/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
index 19f053d0e394308b599dc0bd3191a1370f6d17d5..708f464397bfd55f058c0c2136b041ba9aa59e5a 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
@@ -29,7 +29,6 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
@@ -184,7 +183,6 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
             return Response
                     .created(new URI(info.getRequestURL()))
                     .entity(info)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
             e.printStackTrace();
@@ -219,7 +217,6 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
             return Response
                     .created(new URI(info.getRequestURL()))
                     .entity(info)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
             e.printStackTrace();
@@ -455,7 +452,6 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
             return Response
                     .created(new URI(info.getRequestURL()))
                     .entity(info)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
             e.printStackTrace();
diff --git a/base/server/cms/src/com/netscape/cms/servlet/tks/TPSConnectorService.java b/base/server/cms/src/com/netscape/cms/servlet/tks/TPSConnectorService.java
index 28e3dbb7dd77700f0152e661335ef1fa94e703e4..197fbb8f9f3c949a10fbcb7da9b8f6af6c0008fc 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/tks/TPSConnectorService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/tks/TPSConnectorService.java
@@ -13,7 +13,6 @@ import java.util.TreeSet;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
@@ -170,7 +169,6 @@ public class TPSConnectorService implements TPSConnectorResource {
             return Response
                     .created(newData.getLink().getHref())
                     .entity(newData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (EBaseException e) {
@@ -211,7 +209,6 @@ public class TPSConnectorService implements TPSConnectorResource {
             return Response
                     .ok(curData.getLink().getHref())
                     .entity(curData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException e) {
             CMS.debug("Unable to modify TPS Connector: " + e);
diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java
index 1d07114b1a2120c23f71d415f52a92678cfc218a..e34bbfc78310d4b3f86a4610cd25dcfdb4a58ab5 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java
@@ -26,7 +26,6 @@ import java.util.LinkedHashSet;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -166,7 +165,6 @@ public class AuditService extends PKIService implements AuditResource {
 
             return Response
                     .ok(auditConfig)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
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 47edf23205b8f0cfe9030af5a02afe82b4fd20ff..8a02779279e588bda96f7734cf349909572a0b90 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
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -182,7 +181,6 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
             return Response
                     .created(authenticatorData.getLink().getHref())
                     .entity(authenticatorData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -231,7 +229,6 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
 
             return Response
                     .ok(authenticatorData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -292,7 +289,6 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
 
             return Response
                     .ok(authenticatorData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigService.java
index b470cf87906ce0151c9fa89f15c1f18df1967fb2..9b10bbc8edd6f404d06a094d87ac121b54e31e45 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigService.java
@@ -25,7 +25,6 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -122,7 +121,6 @@ public class ConfigService extends PKIService implements ConfigResource {
 
             return Response
                     .ok(configData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
index 85c64f31dd75f341dc70b4fe87e17e44a0d2ecec..93187a775db3fa25c4ed8c7055a517d2ad8cfe27 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -182,7 +181,6 @@ public class ConnectionService extends PKIService implements ConnectionResource
             return Response
                     .created(connectionData.getLink().getHref())
                     .entity(connectionData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -231,7 +229,6 @@ public class ConnectionService extends PKIService implements ConnectionResource
 
             return Response
                     .ok(connectionData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -292,7 +289,6 @@ public class ConnectionService extends PKIService implements ConnectionResource
 
             return Response
                     .ok(connectionData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
index e9ff801b057497691d7b113f6e1aece98e425127..cd43bb9c39b155d562cfa4f3a398a939e4ee6ae6 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -178,7 +177,6 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
             return Response
                     .created(profileMappingData.getLink().getHref())
                     .entity(profileMappingData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -224,7 +222,6 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
 
             return Response
                     .ok(profileMappingData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -285,7 +282,6 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
 
             return Response
                     .ok(profileMappingData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
index 5ecd1c82cf3e42f1ab2b3e95da2550967ee08a2a..543efb400b63ee1c39a1968b0ca6e04faba84761 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -183,7 +182,6 @@ public class ProfileService extends PKIService implements ProfileResource {
             return Response
                     .created(profileData.getLink().getHref())
                     .entity(profileData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -232,7 +230,6 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             return Response
                     .ok(profileData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
@@ -293,7 +290,6 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             return Response
                     .ok(profileData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (PKIException e) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
index 27291cf7f4e30605834e1c15d444f03f793e1794..361fc29ecdc1c2444be752747c5f65c9442236e9 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
@@ -26,7 +26,6 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -191,7 +190,6 @@ public class TokenService extends PKIService implements TokenResource {
             return Response
                     .created(tokenData.getLink().getHref())
                     .entity(tokenData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (Exception e) {
@@ -220,7 +218,6 @@ public class TokenService extends PKIService implements TokenResource {
 
             return Response
                     .ok(tokenData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (Exception e) {
@@ -254,7 +251,6 @@ public class TokenService extends PKIService implements TokenResource {
 
             return Response
                     .ok(tokenData)
-                    .type(MediaType.APPLICATION_XML)
                     .build();
 
         } catch (Exception e) {
-- 
1.8.4.2

