diff options
6 files changed, 69 insertions, 14 deletions
diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java index 64a53b209..eefd0660e 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java @@ -19,6 +19,8 @@ package com.netscape.certsrv.profile; import java.net.URISyntaxException; +import org.jboss.resteasy.client.ClientResponse; + import com.netscape.certsrv.client.Client; import com.netscape.certsrv.client.PKIClient; @@ -54,12 +56,18 @@ public class ProfileClient extends Client { profileClient.modifyProfileState(id, "disable"); } - public void createProfile(ProfileData data){ - profileClient.createProfile(data); + public ProfileData createProfile(ProfileData data) { + @SuppressWarnings("unchecked") + ClientResponse<ProfileData> response = + (ClientResponse<ProfileData>) profileClient.createProfile(data); + return client.getEntity(response); } - public void modifyProfile(ProfileData data){ - profileClient.modifyProfile(data.getId(), data); + public ProfileData modifyProfile(ProfileData data) { + @SuppressWarnings("unchecked") + ClientResponse<ProfileData> response = + (ClientResponse<ProfileData>) profileClient.modifyProfile(data.getId(), data); + return client.getEntity(response); } public void deleteProfile(String id) { diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileData.java b/base/common/src/com/netscape/certsrv/profile/ProfileData.java index 619a39e67..4b35fee2c 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileData.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileData.java @@ -27,6 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Vector; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -46,6 +49,19 @@ import org.jboss.resteasy.plugins.providers.atom.Link; @XmlAccessorType(XmlAccessType.FIELD) public class ProfileData { + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(ProfileData.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(ProfileData.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + @XmlAttribute protected String id; diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileResource.java b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java index b37b38f32..06dd785c3 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileResource.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java @@ -10,6 +10,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; @@ -30,10 +33,11 @@ public interface ProfileResource { public ProfileData retrieveProfile(@PathParam("id") String id); @POST + @ClientResponseType(entityType=ProfileData.class) @ACLMapping("profile.create") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public void createProfile(ProfileData data); + public Response createProfile(ProfileData data); @POST @Path("{id}") @@ -43,10 +47,11 @@ public interface ProfileResource { @PUT @Path("{id}") + @ClientResponseType(entityType=ProfileData.class) @ACLMapping("profile.modify") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public void modifyProfile(@PathParam("id") String id, ProfileData data); + public Response modifyProfile(@PathParam("id") String id, ProfileData data); @DELETE @Path("{id}") diff --git a/base/java-tools/src/com/netscape/cmstools/profile/ProfileAddCLI.java b/base/java-tools/src/com/netscape/cmstools/profile/ProfileAddCLI.java index 17f7998f9..8e95b832b 100644 --- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileAddCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileAddCLI.java @@ -51,8 +51,11 @@ public class ProfileAddCLI extends CLI { try { ProfileData data = ProfileCLI.readProfileFromFile(filename); - profileCLI.profileClient.createProfile(data); + data = profileCLI.profileClient.createProfile(data); + MainCLI.printMessage("Added profile " + data.getId()); + + ProfileCLI.printProfile(data, profileCLI.getClient().getConfig().getServerURI()); } catch (FileNotFoundException | JAXBException e) { System.err.println("Error: " + e.getMessage()); System.exit(-1); diff --git a/base/java-tools/src/com/netscape/cmstools/profile/ProfileModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/profile/ProfileModifyCLI.java index e1c543672..9fce7d288 100644 --- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileModifyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileModifyCLI.java @@ -51,8 +51,12 @@ public class ProfileModifyCLI extends CLI { try { ProfileData data = ProfileCLI.readProfileFromFile(filename); - profileCLI.profileClient.modifyProfile(data); + data = profileCLI.profileClient.modifyProfile(data); + MainCLI.printMessage("Modified profile " + data.getId()); + + ProfileCLI.printProfile(data, profileCLI.getClient().getConfig().getServerURI()); + } catch (FileNotFoundException | JAXBException e) { System.err.println("Error: " + e.getMessage()); System.exit(-1); 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 edb8b2248..7db0cddbe 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,9 @@ 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; import javax.ws.rs.core.UriInfo; @@ -400,7 +402,8 @@ public class ProfileService extends PKIService implements ProfileResource { } } - public void createProfile(ProfileData data) { + @Override + public Response createProfile(ProfileData data) { if (ps == null) { CMS.debug("createProfile: ps is null"); throw new PKIException("Error creating profile. Profile Service not available"); @@ -445,6 +448,17 @@ public class ProfileService extends PKIService implements ProfileResource { profileId, ILogger.SUCCESS, auditParams); + + changeProfileData(data, profile); + + ProfileData profileData = createProfileData(profileId); + + return Response + .created(profileData.getLink().getHref()) + .entity(profileData) + .type(MediaType.APPLICATION_XML) + .build(); + } catch (EBaseException | IOException e) { CMS.debug("createProfile: error in creating profile: " + e); e.printStackTrace(); @@ -458,11 +472,10 @@ public class ProfileService extends PKIService implements ProfileResource { throw new PKIException("Error in creating profile"); } - - changeProfileData(data, profile); } - public void modifyProfile(String profileId, ProfileData data) { + @Override + public Response modifyProfile(String profileId, ProfileData data) { if (ps == null) { CMS.debug("modifyProfile: ps is null"); throw new PKIException("Error modifying profile. Profile Service not available"); @@ -475,13 +488,19 @@ public class ProfileService extends PKIService implements ProfileResource { throw new ProfileNotFoundException("Cannot modify profile `" + profileId + "`. Profile not found"); } + + changeProfileData(data, profile); + + ProfileData profileData = createProfileData(profileId); + return Response + .ok(profileData) + .type(MediaType.APPLICATION_XML) + .build(); } catch (EBaseException e) { CMS.debug("modifyProfile: error obtaining profile `" + profileId + "`: " + e); e.printStackTrace(); throw new PKIException("Error modifying profile. Cannot obtain profile."); } - - changeProfileData(data, profile); } private void changeProfileData(ProfileData data, IProfile profile) { |