summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-12-10 20:10:06 -0500
committerEndi S. Dewata <edewata@redhat.com>2013-12-16 19:15:43 -0500
commit017e14f93e376f7cbc20066f052a39c4552860d9 (patch)
treee7707f6cf39db3052261794b66a6934173b6104c /base/common/src/com/netscape/certsrv/tps
parent5952a82975063c4ec27303091a44e586d1386933 (diff)
downloadpki-017e14f93e376f7cbc20066f052a39c4552860d9.tar.gz
pki-017e14f93e376f7cbc20066f052a39c4552860d9.tar.xz
pki-017e14f93e376f7cbc20066f052a39c4552860d9.zip
Using PATCH method for modify operations.
Some modify operations have been modified to use HTTP PATCH method since the request only contains changes to the resource, not the entire resource. To replace the entire resource, separate replace operations using HTTP PUT method will be used instead. The Backbone library is using the same convention by default. Ticket #654
Diffstat (limited to 'base/common/src/com/netscape/certsrv/tps')
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenClient.java2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java152
-rw-r--r--base/common/src/com/netscape/certsrv/tps/token/TokenResource.java7
3 files changed, 5 insertions, 156 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
index 602e8f966..e349acd1e 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
@@ -56,7 +56,7 @@ public class TokenClient extends Client {
public TokenData updateToken(String tokenID, TokenData tokenData) {
@SuppressWarnings("unchecked")
- ClientResponse<TokenData> response = (ClientResponse<TokenData>)resource.updateToken(tokenID, tokenData);
+ ClientResponse<TokenData> response = (ClientResponse<TokenData>)resource.replaceToken(tokenID, tokenData);
return client.getEntity(response);
}
diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java b/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java
deleted file mode 100644
index b4168261f..000000000
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2013 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-
-package com.netscape.certsrv.tps.token;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.jboss.resteasy.plugins.providers.atom.Link;
-
-/**
- * @author Endi S. Dewata
- */
-@XmlRootElement(name="TokenModifyRequest")
-public class TokenModifyRequest {
-
- public static Marshaller marshaller;
- public static Unmarshaller unmarshaller;
-
- static {
- try {
- marshaller = JAXBContext.newInstance(TokenModifyRequest.class).createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- unmarshaller = JAXBContext.newInstance(TokenModifyRequest.class).createUnmarshaller();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- String id;
- String userID;
-
- Link link;
-
- @XmlAttribute(name="id")
- public String getID() {
- return id;
- }
-
- public void setID(String id) {
- this.id = id;
- }
-
- @XmlElement(name="UserID")
- public String getUserID() {
- return userID;
- }
-
- public void setUserID(String userID) {
- this.userID = userID;
- }
-
- @XmlElement(name="Link")
- public Link getLink() {
- return link;
- }
-
- public void setLink(Link link) {
- this.link = link;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((link == null) ? 0 : link.hashCode());
- result = prime * result + ((userID == null) ? 0 : userID.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TokenModifyRequest other = (TokenModifyRequest) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- if (link == null) {
- if (other.link != null)
- return false;
- } else if (!link.equals(other.link))
- return false;
- if (userID == null) {
- if (other.userID != null)
- return false;
- } else if (!userID.equals(other.userID))
- return false;
- return true;
- }
-
- public String toString() {
- try {
- StringWriter sw = new StringWriter();
- marshaller.marshal(this, sw);
- return sw.toString();
-
- } catch (Exception e) {
- return super.toString();
- }
- }
-
- public static TokenModifyRequest valueOf(String string) throws Exception {
- try {
- return (TokenModifyRequest)unmarshaller.unmarshal(new StringReader(string));
- } catch (Exception e) {
- return null;
- }
- }
-
- public static void main(String args[]) throws Exception {
-
- TokenModifyRequest before = new TokenModifyRequest();
- before.setID("token1");
- before.setUserID("user1");
-
- String string = before.toString();
- System.out.println(string);
-
- TokenModifyRequest after = TokenModifyRequest.valueOf(string);
- System.out.println(before.equals(after));
- }
-}
diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
index 000853623..529efe8c0 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
@@ -33,6 +33,7 @@ import org.jboss.resteasy.annotations.ClientResponseType;
import com.netscape.certsrv.acls.ACLMapping;
import com.netscape.certsrv.authentication.AuthMethodMapping;
+import com.netscape.certsrv.base.PATCH;
/**
@@ -67,11 +68,11 @@ public interface TokenResource {
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ACLMapping("tokens.modify")
- public Response updateToken(
+ public Response replaceToken(
@PathParam("tokenID") String tokenID,
TokenData tokenData);
- @POST
+ @PATCH
@Path("{tokenID}")
@ClientResponseType(entityType=TokenData.class)
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@@ -79,7 +80,7 @@ public interface TokenResource {
@ACLMapping("tokens.modify")
public Response modifyToken(
@PathParam("tokenID") String tokenID,
- TokenModifyRequest request);
+ TokenData tokenData);
@DELETE
@Path("{tokenID}")