From 6b10e567c5b78bb63fa790acc240bc259291ee4d Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 11 Oct 2013 11:42:31 -0400
Subject: [PATCH] Cleaned up CertEnrollmentRequest.

The CertEnrollmentRequest, ProfileInput, ProfileAttribute, and Descriptor
have been cleaned up to fix some bugs and minor formatting issues.
---
 .../src/com/netscape/cms/servlet/test/CATest.java  |   8 +-
 .../certsrv/cert/CertEnrollmentRequest.java        | 286 ++++++++++++---------
 .../netscape/certsrv/profile/ProfileAttribute.java |   6 +-
 .../com/netscape/certsrv/profile/ProfileInput.java |  98 +++++--
 .../com/netscape/certsrv/property/Descriptor.java  |   8 +-
 .../cmstools/cert/CertRequestSubmitCLI.java        |  28 +-
 .../com/netscape/cmstools/profile/ProfileCLI.java  |   6 +-
 .../netscape/cms/servlet/cert/CertProcessor.java   |   2 +-
 .../netscape/cms/servlet/cert/CertRequestDAO.java  |   2 +-
 .../servlet/cert/CertReviewResponseFactory.java    |   4 +-
 .../cms/servlet/cert/EnrollmentProcessor.java      |   2 +-
 .../cms/servlet/request/CertRequestService.java    |   2 +-
 12 files changed, 280 insertions(+), 172 deletions(-)

diff --git a/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java b/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java
index 904e60c627cf6ab488a193ceada1b50e10704d3d..d50bfedf3111cf1adbc047718aced75fb244d483 100644
--- a/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java
+++ b/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java
@@ -317,7 +317,7 @@ public class CATest {
     private static CertEnrollmentRequest createUserCertEnrollment() {
         CertEnrollmentRequest data = new CertEnrollmentRequest();
         data.setProfileId("caUserCert");
-        data.setIsRenewal(false);
+        data.setRenewal(false);
 
         //Simulate a "caUserCert" Profile enrollment
 
@@ -348,7 +348,7 @@ public class CATest {
     private static CertEnrollmentRequest createRAUserCertEnrollment() {
         CertEnrollmentRequest data = new CertEnrollmentRequest();
         data.setProfileId("caDualRAuserCert");
-        data.setIsRenewal(false);
+        data.setRenewal(false);
 
         //Simulate a "caUserCert" Profile enrollment
 
@@ -373,7 +373,7 @@ public class CATest {
     private static CertEnrollmentRequest createServerCertEnrollment() {
         CertEnrollmentRequest data = new CertEnrollmentRequest();
         data.setProfileId("caServerCert");
-        data.setIsRenewal(false);
+        data.setRenewal(false);
 
         //Simulate a "caUserCert" Profile enrollment
 
@@ -441,7 +441,7 @@ public class CATest {
         List<ProfileInput> inputs = info.getInputs();
         for (ProfileInput input : inputs) {
             log("Input Id: " + input.getId());
-            for (ProfileAttribute attr: input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 log("Input Attribute Name: " + attr.getName() + "\n");
                 log("Input Attribute Value: " + attr.getValue() + "\n");
             }
diff --git a/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java b/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java
index f5feda0fda0ade4d0675a7dec7d233f977eb9815..732efae0a638a2abd4a330881abef5c2c3b1655d 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java
@@ -21,11 +21,11 @@
  */
 package com.netscape.certsrv.cert;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 
 import javax.ws.rs.core.MultivaluedMap;
 import javax.xml.bind.JAXBContext;
@@ -54,26 +54,26 @@ public class CertEnrollmentRequest {
     private static final String RENEWAL = "renewal";
     private static final String SERIAL_NUM = "serial_num";
 
-    @XmlElement
+    @XmlElement(name="ProfileID")
     protected String profileId;
 
-    @XmlElement
-    protected boolean isRenewal;
+    @XmlElement(name="Renewal")
+    protected boolean renewal;
 
-    @XmlElement
+    @XmlElement(name="SerialNumber")
     protected String serialNum;   // used for one type of renewal
 
-    @XmlElement
+    @XmlElement(name="RemoteHost")
     protected String remoteHost;
 
-    @XmlElement
+    @XmlElement(name="RemoteAddress")
     protected String remoteAddr;
 
     @XmlElement(name = "Input")
-    protected List<ProfileInput> inputs = new ArrayList<ProfileInput>();
+    protected Collection<ProfileInput> inputs = new ArrayList<ProfileInput>();
 
     @XmlElement(name = "Output")
-    protected List<ProfileOutput> outputs = new ArrayList<ProfileOutput>();
+    protected Collection<ProfileOutput> outputs = new ArrayList<ProfileOutput>();
 
     public CertEnrollmentRequest() {
         // required for jaxb
@@ -83,7 +83,7 @@ public class CertEnrollmentRequest {
         profileId = form.getFirst(PROFILE_ID);
         String renewalStr = form.getFirst(RENEWAL);
         serialNum = form.getFirst(SERIAL_NUM);
-        isRenewal = new Boolean(renewalStr);
+        renewal = new Boolean(renewalStr);
     }
 
     /**
@@ -96,7 +96,6 @@ public class CertEnrollmentRequest {
     /**
      * @param profileId the profileId to set
      */
-
     public void setProfileId(String profileId) {
         this.profileId = profileId;
     }
@@ -104,23 +103,29 @@ public class CertEnrollmentRequest {
     /**
      * @return renewal
      */
+    public boolean isRenewal() {
+        return renewal;
+    }
 
-    public boolean getIsRenewal() {
-        return isRenewal;
+    /**
+     * @param renewal the renewal to set
+     */
+    public void setRenewal(boolean renewal) {
+        this.renewal = renewal;
     }
 
     public void addInput(ProfileInput input) {
         ProfileInput curInput = getInput(input.getName());
         if (curInput != null) {
-            getInputs().remove(curInput);
+            inputs.remove(curInput);
         }
-        getInputs().add(input);
+        inputs.add(input);
     }
 
     public void deleteInput(ProfileInput input) {
         ProfileInput curInput = getInput(input.getName());
         if (curInput != null) {
-            getInputs().remove(curInput);
+            inputs.remove(curInput);
         }
     }
 
@@ -134,61 +139,52 @@ public class CertEnrollmentRequest {
         ProfileInput newInput = new ProfileInput();
         newInput.setName(name);
 
-        getInputs().add(newInput);
+        inputs.add(newInput);
 
         return newInput;
     }
 
     public ProfileInput getInput(String name) {
-        ProfileInput input = null;
-        for (ProfileInput curInput: getInputs()) {
-            if (curInput != null && curInput.getName().equals(name))
-                break;
+        for (ProfileInput input : inputs) {
+            if (input.getName().equals(name))
+                return input;
         }
-        return input;
+        return null;
     }
 
     public void addOutput(ProfileOutput output) {
         ProfileOutput curOutput = getOutput(output.getName());
         if (curOutput != null) {
-            getOutputs().remove(curOutput);
+            outputs.remove(curOutput);
         }
-        getOutputs().add(output);
+        outputs.add(output);
     }
 
     public void deleteOutput(ProfileOutput output) {
         ProfileOutput curOutput = getOutput(output.getName());
         if (curOutput != null) {
-            getInputs().remove(curOutput);
+            outputs.remove(curOutput);
         }
     }
 
     public ProfileOutput getOutput(String name) {
-        ProfileOutput output = null;
-        for (ProfileOutput curOutput: getOutputs()) {
-            if (curOutput != null && curOutput.getName().equals(name))
-                break;
+        for (ProfileOutput output : outputs) {
+            if (output.getName().equals(name))
+                return output;
         }
-        return output;
-    }
-
-    /**
-     * @param renewal the renewal to set
-     */
-    public void setIsRenewal(boolean isRenewal) {
-        this.isRenewal = isRenewal;
+        return null;
     }
 
     public HashMap<String, String> toParams() {
         HashMap<String, String> ret = new HashMap<String, String>();
-        ret.put("isRenewal", Boolean.valueOf(isRenewal).toString());
+        ret.put("isRenewal", Boolean.valueOf(renewal).toString());
         if (profileId != null) ret.put(PROFILE_ID, profileId);
         if (serialNum != null) ret.put(SERIAL_NUM, serialNum);
         if (remoteHost != null) ret.put("remoteHost", remoteHost);
         if (remoteAddr != null) ret.put("remoteAddr", remoteAddr);
 
         for (ProfileInput input: inputs) {
-            for (ProfileAttribute attr:input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 ret.put(attr.getName(), attr.getValue());
             }
         }
@@ -196,21 +192,136 @@ public class CertEnrollmentRequest {
         return ret;
     }
 
+    public String getSerialNum() {
+        return serialNum;
+    }
+
+    public void setSerialNum(String serialNum) {
+        this.serialNum = serialNum;
+    }
+
+    public Collection<ProfileInput> getInputs() {
+        return inputs;
+    }
+
+    public void setInputs(Collection<ProfileInput> inputs) {
+        this.inputs.clear();
+        this.inputs.addAll(inputs);
+    }
+
+    public String getRemoteAddr() {
+        return remoteAddr;
+    }
+
+    public void setRemoteAddr(String remoteAddr) {
+        this.remoteAddr = remoteAddr;
+    }
+
+    public String getRemoteHost() {
+        return remoteHost;
+    }
+
+    public void setRemoteHost(String remoteHost) {
+        this.remoteHost = remoteHost;
+    }
+
+    public Collection<ProfileOutput> getOutputs() {
+        return outputs;
+    }
+
+    public void setOutputs(Collection<ProfileOutput> outputs) {
+        this.outputs.clear();
+        this.outputs.addAll(outputs);
+    }
+
+    public static CertEnrollmentRequest fromXML(String string) throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class);
+        Unmarshaller unmarshaller = context.createUnmarshaller();
+        return (CertEnrollmentRequest) unmarshaller.unmarshal(new StringReader(string));
+    }
+
+    public String toXML() throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class);
+        Marshaller marshaller = context.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        StringWriter sw = new StringWriter();
+        marshaller.marshal(this, sw);
+        return sw.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((inputs == null) ? 0 : inputs.hashCode());
+        result = prime * result + ((outputs == null) ? 0 : outputs.hashCode());
+        result = prime * result + ((profileId == null) ? 0 : profileId.hashCode());
+        result = prime * result + ((remoteAddr == null) ? 0 : remoteAddr.hashCode());
+        result = prime * result + ((remoteHost == null) ? 0 : remoteHost.hashCode());
+        result = prime * result + (renewal ? 1231 : 1237);
+        result = prime * result + ((serialNum == null) ? 0 : serialNum.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;
+        CertEnrollmentRequest other = (CertEnrollmentRequest) obj;
+        if (inputs == null) {
+            if (other.inputs != null)
+                return false;
+        } else if (!inputs.equals(other.inputs))
+            return false;
+        if (outputs == null) {
+            if (other.outputs != null)
+                return false;
+        } else if (!outputs.equals(other.outputs))
+            return false;
+        if (profileId == null) {
+            if (other.profileId != null)
+                return false;
+        } else if (!profileId.equals(other.profileId))
+            return false;
+        if (remoteAddr == null) {
+            if (other.remoteAddr != null)
+                return false;
+        } else if (!remoteAddr.equals(other.remoteAddr))
+            return false;
+        if (remoteHost == null) {
+            if (other.remoteHost != null)
+                return false;
+        } else if (!remoteHost.equals(other.remoteHost))
+            return false;
+        if (renewal != other.renewal)
+            return false;
+        if (serialNum == null) {
+            if (other.serialNum != null)
+                return false;
+        } else if (!serialNum.equals(other.serialNum))
+            return false;
+        return true;
+    }
+
     public static void main(String args[]) throws Exception {
-        CertEnrollmentRequest data = new CertEnrollmentRequest();
-        data.setProfileId("caUserCert");
-        data.setIsRenewal(false);
+        CertEnrollmentRequest before = new CertEnrollmentRequest();
+        before.setProfileId("caUserCert");
+        before.setRenewal(false);
 
         //Simulate a "caUserCert" Profile enrollment
 
-        ProfileInput certReq = data.createInput("KeyGenInput");
+        ProfileInput certReq = before.createInput("KeyGenInput");
         certReq.addAttribute(new ProfileAttribute("cert_request_type", "crmf", null));
         certReq.addAttribute(new ProfileAttribute(
                 "cert_request",
                 "MIIBozCCAZ8wggEFAgQBMQp8MIHHgAECpQ4wDDEKMAgGA1UEAxMBeKaBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2NgaPHp0jiohcP4M+ufrJOZEqH8GV+liu5JLbT8nWpkfhC+8EUBqT6g+n3qroSxIcNVGNdcsBEqs1utvpItzyslAbpdyat3WwQep1dWMzo6RHrPDuIoxNA0Yka1n3qEX4U//08cLQtUv2bYglYgN/hOCNQemLV6vZWAv0n7zelkCAwEAAakQMA4GA1UdDwEB/wQEAwIF4DAzMBUGCSsGAQUFBwUBAQwIcmVnVG9rZW4wGgYJKwYBBQUHBQECDA1hdXRoZW50aWNhdG9yoYGTMA0GCSqGSIb3DQEBBQUAA4GBAJ1VOQcaSEhdHa94s8kifVbSZ2WZeYE5//qxL6wVlEst20vq4ybj13CetnbN3+WT49Zkwp7Fg+6lALKgSk47suTg3EbbQDm+8yOrC0nc/q4PTRoHl0alMmUxIhirYc1t3xoCMqJewmjX1bNP8lpVIZAYFZo4eZCpZaiSkM5BeHhz",
                 null));
 
-        ProfileInput subjectName = data.createInput("SubjectNameInput");
+        ProfileInput subjectName = before.createInput("SubjectNameInput");
         subjectName.addAttribute(new ProfileAttribute("sn_uid", "jmagne", null));
         subjectName.addAttribute(new ProfileAttribute("sn_e", "jmagne@redhat.com", null));
         subjectName.addAttribute(new ProfileAttribute("sn_c", "US", null));
@@ -221,88 +332,17 @@ public class CertEnrollmentRequest {
         subjectName.addAttribute(new ProfileAttribute("sn_cn", "Common", null));
         subjectName.addAttribute(new ProfileAttribute("sn_o", "RedHat", null));
 
-        ProfileInput submitter = data.createInput("SubmitterInfoInput");
+        ProfileInput submitter = before.createInput("SubmitterInfoInput");
         submitter.addAttribute(new ProfileAttribute("requestor_name", "admin", null));
         submitter.addAttribute(new ProfileAttribute("requestor_email", "admin@redhat.com", null));
         submitter.addAttribute(new ProfileAttribute("requestor_phone", "650-555-5555", null));
 
-        try {
-            JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class);
-            Marshaller marshaller = context.createMarshaller();
-            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        String xml = before.toXML();
+        System.out.println(xml);
 
-            ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        CertEnrollmentRequest after = CertEnrollmentRequest.fromXML(xml);
+        System.out.println(after.toXML());
 
-            marshaller.marshal(data, stream);
-
-            System.out.println("Originally marshalled enrollment object. \n");
-
-            System.out.println(stream.toString());
-
-            //Try to unmarshall
-
-            Unmarshaller unmarshaller = context.createUnmarshaller();
-
-            ByteArrayInputStream bais = new ByteArrayInputStream(stream.toByteArray());
-            Object unmarshalled = unmarshaller.unmarshal(bais);
-
-            //Try re-marshalling, unmarshalled object to compare
-
-            stream.reset();
-
-            marshaller.marshal(unmarshalled, stream);
-
-            System.out.println("Remarshalled unmarshalled enrollment object. \n");
-
-            System.out.println(stream.toString());
-
-        } catch (JAXBException e) {
-            System.out.println(e.toString());
-        }
-    }
-
-    public String getSerialNum() {
-        return serialNum;
-    }
-
-    public void setSerialNum(String serialNum) {
-        this.serialNum = serialNum;
-    }
-
-    public List<ProfileInput> getInputs() {
-        return inputs;
+        System.out.println(before.equals(after));
     }
-
-    public void setInputs(List<ProfileInput> inputs) {
-        this.inputs = inputs;
-    }
-
-    public String getRemoteAddr() {
-        return remoteAddr;
-    }
-
-    public void setRemoteAddr(String remoteAddr) {
-        this.remoteAddr = remoteAddr;
-    }
-
-    public String getRemoteHost() {
-        return remoteHost;
-    }
-
-    public void setRemoteHost(String remoteHost) {
-        this.remoteHost = remoteHost;
-    }
-
-    public List<ProfileOutput> getOutputs() {
-        return outputs;
-    }
-
-    public void setOutputs(List<ProfileOutput> outputs) {
-        this.outputs = outputs;
-    }
-
-    public void setRenewal(boolean isRenewal) {
-        this.isRenewal = isRenewal;
-    }
-
 }
diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java
index c3549424c8468af4976d893b96db1f21a48d35a6..be91fd2e45b061676fd74dcf6cb0f731334ca693 100644
--- a/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java
+++ b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java
@@ -25,17 +25,17 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 import com.netscape.certsrv.property.Descriptor;
 
-@XmlRootElement
+@XmlRootElement(name="Attribute")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class ProfileAttribute {
 
     @XmlAttribute
     private String name;
 
-    @XmlElement
+    @XmlElement(name="Value")
     private String value;
 
-    @XmlElement
+    @XmlElement(name="Descriptor")
     private Descriptor descriptor;
 
     public ProfileAttribute() {
diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileInput.java b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java
index 2826f50d8bd7f36a1ad8cb3e6352984c1ef68a5f..b53630d9f6a3d86afe4953d29550dbcf585f8243 100644
--- a/base/common/src/com/netscape/certsrv/profile/ProfileInput.java
+++ b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java
@@ -17,32 +17,60 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.certsrv.profile;
 
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Locale;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+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;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 
 import com.netscape.certsrv.property.Descriptor;
 
+@XmlRootElement(name="Input")
+@XmlAccessorType(XmlAccessType.FIELD)
 public class ProfileInput {
+
+    @XmlAttribute(name="id")
     private String id;
+
+    @XmlElement(name="ClassID")
     private String classId;
+
+    @XmlElement(name="Name")
     private String name;
+
+    @XmlElement(name="Text")
     private String text;
+
+    @XmlElement(name = "Attribute")
     private List<ProfileAttribute> attrs = new ArrayList<ProfileAttribute>();
+
+    @XmlElement(name = "ConfigAttribute")
     private List<ProfileAttribute> configAttrs = new ArrayList<ProfileAttribute>();
 
     public ProfileInput() {
         // required for jaxb
     }
 
+    public ProfileInput(String id, String name, String classId) {
+        this.id = id;
+        this.name = name;
+        this.classId = classId;
+    }
+
     public ProfileInput(IProfileInput input, String id, String classId, Locale locale) {
-        this.name = input.getName(locale);
-        this.id = id;
-        this.classId = classId;
+        this(id, input.getName(locale), classId);
         Enumeration<String> names = input.getValueNames();
         while (names.hasMoreElements()) {
             String name = names.nextElement();
@@ -51,17 +79,14 @@ public class ProfileInput {
         }
     }
 
-    @XmlElement
     public String getClassId() {
         return classId;
     }
 
-    @XmlElement
     public String getName() {
         return name;
     }
 
-    @XmlElement
     public String getText() {
         return text;
     }
@@ -70,7 +95,6 @@ public class ProfileInput {
         this.classId = classId;
     }
 
-    @XmlAttribute
     public String getId() {
         return id;
     }
@@ -87,28 +111,34 @@ public class ProfileInput {
         this.text = text;
     }
 
-    @XmlElement(name = "attribute")
-    public List<ProfileAttribute> getAttrs() {
+    public Collection<ProfileAttribute> getAttributes() {
         return attrs;
     }
 
-    public void setAttrs(List<ProfileAttribute> attrs) {
-        this.attrs = attrs;
+    public void setAttributes(Collection<ProfileAttribute> attrs) {
+        this.attrs.clear();
+        this.attrs.addAll(attrs);
+    }
+
+    public ProfileAttribute getAttribute(String name) {
+        for (ProfileAttribute attr : attrs) {
+            if (attr.getName().equals(name)) return attr;
+        }
+        return null;
     }
 
     public void addAttribute(ProfileAttribute attr) {
         attrs.add(attr);
     }
 
-    public void removeAttribute(ProfileAttribute attr) {
-        attrs.remove(attr);
+    public void removeAttribute(String name) {
+        attrs.remove(name);
     }
 
     public void clearAttributes() {
         attrs.clear();
     }
 
-    @XmlElement(name = "config_attribute")
     public List<ProfileAttribute> getConfigAttrs() {
         return configAttrs;
     }
@@ -118,11 +148,11 @@ public class ProfileInput {
     }
 
     public void addConfigAttribute(ProfileAttribute configAttr) {
-        attrs.add(configAttr);
+        configAttrs.add(configAttr);
     }
 
     public void removeConfigAttribute(ProfileAttribute configAttr) {
-        attrs.remove(configAttr);
+        configAttrs.remove(configAttr);
     }
 
     public void clearConfigAttributes() {
@@ -184,4 +214,40 @@ public class ProfileInput {
         return true;
     }
 
+    public static ProfileInput fromXML(String string) throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(ProfileInput.class);
+        Unmarshaller unmarshaller = context.createUnmarshaller();
+        return (ProfileInput) unmarshaller.unmarshal(new StringReader(string));
+    }
+
+    public String toXML() throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(ProfileInput.class);
+        Marshaller marshaller = context.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        StringWriter sw = new StringWriter();
+        marshaller.marshal(this, sw);
+        return sw.toString();
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        ProfileInput before = new ProfileInput("i1", "SubjectNameInput", null);
+        before.addAttribute(new ProfileAttribute("sn_uid", "jmagne", null));
+        before.addAttribute(new ProfileAttribute("sn_e", "jmagne@redhat.com", null));
+        before.addAttribute(new ProfileAttribute("sn_c", "US", null));
+        before.addAttribute(new ProfileAttribute("sn_ou", "Development", null));
+        before.addAttribute(new ProfileAttribute("sn_ou1", "IPA", null));
+        before.addAttribute(new ProfileAttribute("sn_ou2", "Dogtag", null));
+        before.addAttribute(new ProfileAttribute("sn_ou3", "CA", null));
+        before.addAttribute(new ProfileAttribute("sn_cn", "Common", null));
+        before.addAttribute(new ProfileAttribute("sn_o", "RedHat", null));
+
+        String xml = before.toXML();
+        System.out.println(xml);
+
+        ProfileInput after = ProfileInput.fromXML(xml);
+        System.out.println(after.toXML());
+
+        System.out.println(before.equals(after));
+    }
 }
diff --git a/base/common/src/com/netscape/certsrv/property/Descriptor.java b/base/common/src/com/netscape/certsrv/property/Descriptor.java
index 63e1544669ec3853847c07b23ebecba825db47de..b6a9900b6a80172cee5883c661ad184d8c9ed7dc 100644
--- a/base/common/src/com/netscape/certsrv/property/Descriptor.java
+++ b/base/common/src/com/netscape/certsrv/property/Descriptor.java
@@ -35,16 +35,16 @@ import javax.xml.bind.annotation.XmlRootElement;
 @XmlAccessorType(XmlAccessType.FIELD)
 public class Descriptor implements IDescriptor {
 
-    @XmlElement(name = "syntax")
+    @XmlElement(name = "Syntax")
     protected String mSyntax = null;
 
-    @XmlElement(name = "constraint")
+    @XmlElement(name = "Constraint")
     protected String mConstraint = null;
 
-    @XmlElement(name = "description")
+    @XmlElement(name = "Description")
     protected String mDescription = null;
 
-    @XmlElement(name = "defaultValue")
+    @XmlElement(name = "DefaultValue")
     protected String mDef = null;
 
     public Descriptor() {
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
index 917a697b6dee5a15a69ca69dce0c9118b96fc228..d43763f112a102fa0cbe8f24747137649b3b1dec 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
@@ -1,12 +1,11 @@
 package com.netscape.cmstools.cert;
 
-import java.io.FileInputStream;
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.Collection;
+import java.util.Scanner;
 
-import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.ParseException;
@@ -50,16 +49,16 @@ public class CertRequestSubmitCLI extends CLI {
             System.exit(-1);
         }
 
-        CertEnrollmentRequest erd = null;
-
         try {
-            erd = getEnrollmentRequest(cLineArgs[0]);
+            CertEnrollmentRequest erd = getEnrollmentRequest(cLineArgs[0]);
             CertRequestInfos cri = certCLI.certClient.enrollRequest(erd);
             MainCLI.printMessage("Submitted certificate request");
             printRequestInformation(cri);
+
         } catch (FileNotFoundException e) {
             System.err.println("Error: " + e.getMessage());
             System.exit(-1);
+
         } catch (JAXBException e) {
             System.err.println("Error: " + e.getMessage());
             System.exit(-1);
@@ -67,19 +66,22 @@ public class CertRequestSubmitCLI extends CLI {
     }
 
     private CertEnrollmentRequest getEnrollmentRequest(String fileName) throws JAXBException, FileNotFoundException {
-        CertEnrollmentRequest erd = null;
-        JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class);
-        Unmarshaller unmarshaller = context.createUnmarshaller();
-        FileInputStream fis = new FileInputStream(fileName);
-        erd = (CertEnrollmentRequest) unmarshaller.unmarshal(fis);
-        return erd;
+        try (Scanner scanner = new Scanner(new File(fileName))) {
+            String xml = scanner.useDelimiter("\\A").next();
+            return CertEnrollmentRequest.fromXML(xml);
+        }
     }
 
     private void printRequestInformation(CertRequestInfos cri) {
         Collection<CertRequestInfo> allRequests = cri.getRequests();
+        boolean first = true;
         for (CertRequestInfo x : allRequests) {
+            if (first) {
+                first = false;
+            } else {
+                System.out.println();
+            }
             CertCLI.printCertRequestInfo(x);
         }
-        System.out.println();
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java b/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
index 77539828386122e587cb888bb858088dde1d2a81..732b597afd1dbb5b9440d451f34b2f39e20fb904 100644
--- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
@@ -82,7 +82,7 @@ public class ProfileCLI extends CLI {
             System.out.println("  Input ID: " + input.getId());
             System.out.println("  Name: " + input.getName());
             System.out.println("  Class: " + input.getClassId());
-            for (ProfileAttribute attr: input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 System.out.println();
                 System.out.println("    Attribute Name: " + attr.getName());
                 System.out.println("    Attribute Description: " +
@@ -144,14 +144,14 @@ public class ProfileCLI extends CLI {
 
     public static void printEnrollmentTemplate(CertEnrollmentRequest request) {
         System.out.println("  Profile ID: " +  request.getProfileId());
-        System.out.println("  Renewal: " + request.getIsRenewal());
+        System.out.println("  Renewal: " + request.isRenewal());
 
         for (ProfileInput input: request.getInputs()) {
             System.out.println();
             System.out.println("  Input ID: " + input.getId());
             System.out.println("  Name: " + input.getName());
             System.out.println("  Class: " + input.getClassId());
-            for (ProfileAttribute attr: input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 System.out.println();
                 System.out.println("    Attribute Name: " + attr.getName());
                 System.out.println("    Attribute Description: " +
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java
index 9e583a91c3bd2c355a5bd932dd20cc3a3dd67bb2..4cd54a25719bcd82728ef803f225bac481211584 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java
@@ -78,7 +78,7 @@ public class CertProcessor extends CAProcessor {
         // put profile inputs into a local map
         HashMap<String, String> dataInputs = new HashMap<String, String>();
         for (ProfileInput input : data.getInputs()) {
-            for (ProfileAttribute attr: input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 dataInputs.put(attr.getName(), attr.getValue());
             }
         }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
index 1ba6a083c6abb11bccc2e5475dad66ed192f7c92..70433339fbd17f084139aad4065a5911d56e26e6 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
@@ -168,7 +168,7 @@ public class CertRequestDAO extends CMSRequestDAO {
         CertRequestInfos ret = new CertRequestInfos();
 
         HashMap<String, Object> results = null;
-        if (data.getIsRenewal()) {
+        if (data.isRenewal()) {
             RenewalProcessor processor = new RenewalProcessor("caProfileSubmit", locale);
             results = processor.processRenewal(data, request);
         } else {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java
index 2066405757bbf373a2f8bd156649f9620d20e04e..cf0fafa51e397ac639ef6f4d163d807a4aa253fb 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java
@@ -51,9 +51,9 @@ public class CertReviewResponseFactory {
         CertReviewResponse ret = new CertReviewResponse();
 
         if (request.getRequestType().equals("renewal")) {
-            ret.setIsRenewal(true);
+            ret.setRenewal(true);
         } else {
-            ret.setIsRenewal(false);
+            ret.setRenewal(false);
         }
 
         ret.setRequestId(request.getRequestId());
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java
index 31b235d2aae81543c91cf2a27b729868b87cb3da..ee56f01399aa701c18fde4701e0c635772298d3c 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java
@@ -51,7 +51,7 @@ public class EnrollmentProcessor extends CertProcessor {
         // put profile inputs into a local map
         HashMap<String, String> dataInputs = new HashMap<String, String>();
         for (ProfileInput input : data.getInputs()) {
-            for (ProfileAttribute attr: input.getAttrs()) {
+            for (ProfileAttribute attr : input.getAttributes()) {
                 dataInputs.put(attr.getName(), attr.getValue());
             }
         }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
index dd3065427c811c980290d78a6cf4d3984d0d3161..620084208d325b1569d4d08b33582125fb9e9d76 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
@@ -319,7 +319,7 @@ public class CertRequestService extends PKIService implements CertRequestResourc
             String id = inputIds.nextElement();
             try {
                 ProfileInput input = ProfileService.createProfileInput(profile, id, getLocale(headers));
-                for (ProfileAttribute attr: input.getAttrs()) {
+                for (ProfileAttribute attr : input.getAttributes()) {
                     attr.setValue("");
                 }
                 request.addInput(input);
-- 
1.8.1.4

