diff options
Diffstat (limited to 'base/common/src/com/netscape/certsrv')
5 files changed, 61 insertions, 15 deletions
diff --git a/base/common/src/com/netscape/certsrv/dbs/certdb/CertIdAdapter.java b/base/common/src/com/netscape/certsrv/dbs/certdb/CertIdAdapter.java index cfafff064..f6e46cad5 100644 --- a/base/common/src/com/netscape/certsrv/dbs/certdb/CertIdAdapter.java +++ b/base/common/src/com/netscape/certsrv/dbs/certdb/CertIdAdapter.java @@ -19,19 +19,20 @@ package com.netscape.certsrv.dbs.certdb; import javax.xml.bind.annotation.adapters.XmlAdapter; +import org.apache.commons.lang.StringUtils; + /** * The CertIdAdapter class provides custom marshaling for CertId. * * @author Endi S. Dewata - * @version $Revision$ $Date$ */ public class CertIdAdapter extends XmlAdapter<String, CertId> { public CertId unmarshal(String value) throws Exception { - return new CertId(value); + return StringUtils.isEmpty(value) ? null : new CertId(value); } public String marshal(CertId value) throws Exception { - return value.toString(); + return value == null ? null : value.toHexString(); } } diff --git a/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java index 3232999fd..0f0c43c82 100644 --- a/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java +++ b/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java @@ -19,19 +19,20 @@ package com.netscape.certsrv.dbs.keydb; import javax.xml.bind.annotation.adapters.XmlAdapter; +import org.apache.commons.lang.StringUtils; + /** * The KeyIdAdapter class provides custom marshaling for KeyId. * * @author Endi S. Dewata - * @version $Revision$ $Date$ */ public class KeyIdAdapter extends XmlAdapter<String, KeyId> { public KeyId unmarshal(String value) throws Exception { - return new KeyId(value); + return StringUtils.isEmpty(value) ? null : new KeyId(value); } public String marshal(KeyId value) throws Exception { - return value.toString(); + return value == null ? null : value.toString(); } } diff --git a/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java b/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java index 1780bc337..a6051fa8d 100644 --- a/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java +++ b/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java @@ -19,19 +19,20 @@ package com.netscape.certsrv.request; import javax.xml.bind.annotation.adapters.XmlAdapter; +import org.apache.commons.lang.StringUtils; + /** * The RequestIdAdapter class provides custom marshaling for RequestId. * * @author Endi S. Dewata - * @version $Revision$ $Date$ */ public class RequestIdAdapter extends XmlAdapter<String, RequestId> { public RequestId unmarshal(String value) throws Exception { - return new RequestId(value); + return StringUtils.isEmpty(value) ? null : new RequestId(value); } public String marshal(RequestId value) throws Exception { - return value.toString(); + return value == null ? null : value.toString(); } }
\ No newline at end of file diff --git a/base/common/src/com/netscape/certsrv/user/UserCertData.java b/base/common/src/com/netscape/certsrv/user/UserCertData.java index d77e1dc8b..708d03430 100644 --- a/base/common/src/com/netscape/certsrv/user/UserCertData.java +++ b/base/common/src/com/netscape/certsrv/user/UserCertData.java @@ -21,7 +21,6 @@ package com.netscape.certsrv.user; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; -import java.math.BigInteger; import java.util.StringTokenizer; import javax.ws.rs.FormParam; @@ -31,10 +30,13 @@ import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.jboss.resteasy.plugins.providers.atom.Link; import com.netscape.certsrv.common.Constants; +import com.netscape.certsrv.dbs.certdb.CertId; +import com.netscape.certsrv.dbs.certdb.CertIdAdapter; /** * @author Endi S. Dewata @@ -56,7 +58,7 @@ public class UserCertData { } Integer version; - BigInteger serialNumber; + CertId serialNumber; String issuerDN; String subjectDN; String prettyPrint; @@ -76,7 +78,7 @@ public class UserCertData { public void setID(String id) { StringTokenizer st = new StringTokenizer(id, ";"); version = Integer.valueOf(st.nextToken()); - serialNumber = new BigInteger(st.nextToken()); + serialNumber = new CertId(st.nextToken()); issuerDN = st.nextToken(); subjectDN = st.nextToken(); } @@ -91,11 +93,12 @@ public class UserCertData { } @XmlElement(name="SerialNumber") - public BigInteger getSerialNumber() { + @XmlJavaTypeAdapter(CertIdAdapter.class) + public CertId getSerialNumber() { return serialNumber; } - public void setSerialNumber(BigInteger serialNumber) { + public void setSerialNumber(CertId serialNumber) { this.serialNumber = serialNumber; } @@ -240,7 +243,7 @@ public class UserCertData { UserCertData before = new UserCertData(); before.setVersion(1); - before.setSerialNumber(new BigInteger("12512514865863765114")); + before.setSerialNumber(new CertId("12512514865863765114")); before.setIssuerDN("CN=Test User,UID=testuser,O=EXAMPLE-COM"); before.setSubjectDN("CN=Test User,UID=testuser,O=EXAMPLE-COM"); before.setEncoded(sw.toString()); diff --git a/base/common/src/com/netscape/certsrv/util/DateAdapter.java b/base/common/src/com/netscape/certsrv/util/DateAdapter.java new file mode 100644 index 000000000..e01f2d98a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/util/DateAdapter.java @@ -0,0 +1,40 @@ +// --- 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) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.util; + +import java.util.Date; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.apache.commons.lang.StringUtils; + +/** + * The DateAdapter class provides custom marshaling for Date. + * + * @author Endi S. Dewata + */ +public class DateAdapter extends XmlAdapter<String, Date> { + + public Date unmarshal(String value) throws Exception { + return StringUtils.isEmpty(value) ? null : new Date(Long.parseLong(value)); + } + + public String marshal(Date value) throws Exception { + return value == null ? null : Long.toString(value.getTime()); + } +} |