>From 4171c6f8d8b1ed0bff247b5bf1a8bf0ee0f0fd51 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Thu, 24 Jan 2013 14:16:11 -0500
Subject: [PATCH 115/117] move updateNumberRange to admin interface

---
 base/ca/shared/webapps/ca/WEB-INF/web.xml          |   4 +-
 .../cms/servlet/csadmin/ConfigurationUtils.java    | 104 +++++++++++----------
 base/kra/shared/webapps/kra/WEB-INF/web.xml        |   4 +-
 3 files changed, 61 insertions(+), 51 deletions(-)

diff --git a/base/ca/shared/webapps/ca/WEB-INF/web.xml b/base/ca/shared/webapps/ca/WEB-INF/web.xml
index a875fee18056a225c36d5342d9c7438b21fec9c6..b922b3d9896ebbae3bb93a8dfb34a660111e452c 100644
--- a/base/ca/shared/webapps/ca/WEB-INF/web.xml
+++ b/base/ca/shared/webapps/ca/WEB-INF/web.xml
@@ -201,7 +201,7 @@
              <init-param><param-name>  ID          </param-name>
                          <param-value> caUpdateNumberRange </param-value> </init-param>
              <init-param><param-name>  interface   </param-name>
-                         <param-value> ee          </param-value> </init-param>
+                         <param-value> admin          </param-value> </init-param>
              <init-param><param-name>  AuthMgr     </param-name>
                          <param-value> TokenAuth </param-value> </init-param>
              <init-param><param-name>  AuthzMgr    </param-name>
@@ -1884,7 +1884,7 @@
 
    <servlet-mapping>     
       <servlet-name>  caUpdateNumberRange </servlet-name>
-      <url-pattern>   /ee/ca/updateNumberRange  </url-pattern>
+      <url-pattern>   /admin/ca/updateNumberRange  </url-pattern>
    </servlet-mapping>
 
    <servlet-mapping>
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
index a7ec566ce38b02750e140299de9b96a38c38fc89..782e0ec08af24b69a065f9a014c8cc955fe03313 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
@@ -562,24 +562,21 @@ public class ConfigurationUtils {
         cstype = cstype.toLowerCase();
 
         String session_id = CMS.getConfigSDSessionId();
-        String master_hostname = "";
-        int master_port = -1;
-        int master_ee_port = -1;
-        master_hostname = config.getString("preop.master.hostname", "");
-        master_port = config.getInteger("preop.master.httpsadminport", -1);
-        master_ee_port = config.getInteger("preop.master.httpsport", -1);
+        String master_hostname = config.getString("preop.master.hostname", "");
+        int master_port = config.getInteger("preop.master.httpsadminport", -1);
+        int master_ee_port = config.getInteger("preop.master.httpsport", -1);
 
         String content = "";
         if (cstype.equals("ca") || cstype.equals("kra")) {
             content = "type=request&xmlOutput=true&sessionID=" + session_id;
             CMS.debug("http content=" + content);
-            updateNumberRange(master_hostname, master_ee_port, true, content, "request");
+            updateNumberRange(master_hostname, master_ee_port, master_port, true, content, "request");
 
             content = "type=serialNo&xmlOutput=true&sessionID=" + session_id;
-            updateNumberRange(master_hostname, master_ee_port, true, content, "serialNo");
+            updateNumberRange(master_hostname, master_ee_port, master_port, true, content, "serialNo");
 
             content = "type=replicaId&xmlOutput=true&sessionID=" + session_id;
-            updateNumberRange(master_hostname, master_ee_port, true, content, "replicaId");
+            updateNumberRange(master_hostname, master_ee_port, master_port, true, content, "replicaId");
         }
 
         String list = "";
@@ -637,51 +634,64 @@ public class ConfigurationUtils {
 
     }
 
-    public static void updateNumberRange(String hostname, int port, boolean https, String content, String type)
-            throws IOException, EBaseException, SAXException, ParserConfigurationException {
-        CMS.debug("updateNumberRange start host=" + hostname + " port=" + port);
+    public static void updateNumberRange(String hostname, int eePort, int adminPort, boolean https, String content,
+            String type) throws IOException, EBaseException, SAXException, ParserConfigurationException {
+        CMS.debug("updateNumberRange start host=" + hostname + " adminPort=" + adminPort + " eePort=" + eePort);
         IConfigStore cs = CMS.getConfigStore();
 
         String cstype = "";
         cstype = cs.getString("cs.type", "");
         cstype = cstype.toLowerCase();
 
-        String serverPath = "/" + cstype + "/ee/" + cstype + "/updateNumberRange";
-        String c = getHttpResponse(hostname, port, https, serverPath, content, null, null);
-        if (c == null || c.equals("")) {
-            CMS.debug("updateNumberRange: content is null.");
-            throw new IOException("The server you want to contact is not available");
+        String serverPath = "/" + cstype + "/admin/" + cstype + "/updateNumberRange";
+        String c = null;
+        try {
+            c = getHttpResponse(hostname, adminPort, https, serverPath, content, null, null);
+            if (c == null || c.equals("")) {
+                CMS.debug("updateNumberRange: content is null.");
+                throw new IOException("The server you want to contact is not available");
+            }
+        } catch (Exception e) {
+            // for backward compatibility, try the old ee interface too
+            CMS.debug("updateNumberRange: Failed to contact master using admin port" + e);
+            CMS.debug("updateNumberRange: Attempting to contact master using EE port");
+            serverPath = "/" + cstype + "/ee/" + cstype + "/updateNumberRange";
+            c = getHttpResponse(hostname, eePort, https, serverPath, content, null, null);
+            if (c == null || c.equals("")) {
+                CMS.debug("updateNumberRange: content is null.");
+                throw new IOException("The server you want to contact is not available");
+            }
+        }
+
+        CMS.debug("content=" + c);
+        ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
+        XMLObject parser = null;
+        parser = new XMLObject(bis);
+        String status = parser.getValue("Status");
+
+        CMS.debug("updateNumberRange(): status=" + status);
+        if (status.equals(SUCCESS)) {
+            String beginNum = parser.getValue("beginNumber");
+            String endNum = parser.getValue("endNumber");
+            if (type.equals("request")) {
+                cs.putString("dbs.beginRequestNumber", beginNum);
+                cs.putString("dbs.endRequestNumber", endNum);
+            } else if (type.equals("serialNo")) {
+                cs.putString("dbs.beginSerialNumber", beginNum);
+                cs.putString("dbs.endSerialNumber", endNum);
+            } else if (type.equals("replicaId")) {
+                cs.putString("dbs.beginReplicaNumber", beginNum);
+                cs.putString("dbs.endReplicaNumber", endNum);
+            }
+            // enable serial number management in clone
+            cs.putString("dbs.enableSerialManagement", "true");
+            cs.commit(false);
+            return;
+        } else if (status.equals(AUTH_FAILURE)) {
+            throw new EAuthException(AUTH_FAILURE);
         } else {
-            CMS.debug("content=" + c);
-            ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
-            XMLObject parser = null;
-            parser = new XMLObject(bis);
-            String status = parser.getValue("Status");
-
-            CMS.debug("updateNumberRange(): status=" + status);
-            if (status.equals(SUCCESS)) {
-                String beginNum = parser.getValue("beginNumber");
-                String endNum = parser.getValue("endNumber");
-                if (type.equals("request")) {
-                    cs.putString("dbs.beginRequestNumber", beginNum);
-                    cs.putString("dbs.endRequestNumber", endNum);
-                } else if (type.equals("serialNo")) {
-                    cs.putString("dbs.beginSerialNumber", beginNum);
-                    cs.putString("dbs.endSerialNumber", endNum);
-                } else if (type.equals("replicaId")) {
-                    cs.putString("dbs.beginReplicaNumber", beginNum);
-                    cs.putString("dbs.endReplicaNumber", endNum);
-                }
-                // enable serial number management in clone
-                cs.putString("dbs.enableSerialManagement", "true");
-                cs.commit(false);
-                return;
-            } else if (status.equals(AUTH_FAILURE)) {
-                throw new EAuthException(AUTH_FAILURE);
-            } else {
-                String error = parser.getValue("Error");
-                throw new IOException(error);
-            }
+            String error = parser.getValue("Error");
+            throw new IOException(error);
         }
     }
 
diff --git a/base/kra/shared/webapps/kra/WEB-INF/web.xml b/base/kra/shared/webapps/kra/WEB-INF/web.xml
index c278bcbadaf113ef971fae594b750809b0a767ef..5ef28fc3183bfa4786e4489c5135df544f6e044f 100644
--- a/base/kra/shared/webapps/kra/WEB-INF/web.xml
+++ b/base/kra/shared/webapps/kra/WEB-INF/web.xml
@@ -652,7 +652,7 @@
              <init-param><param-name>  ID          </param-name>
                          <param-value> kraUpdateNumberRange </param-value> </init-param>
              <init-param><param-name>  interface   </param-name>
-                         <param-value> ee          </param-value> </init-param>
+                         <param-value> admin       </param-value> </init-param>
              <init-param><param-name>  AuthMgr     </param-name>
                          <param-value> TokenAuth </param-value> </init-param>
              <init-param><param-name>  AuthzMgr    </param-name>
@@ -918,7 +918,7 @@
 
    <servlet-mapping>
       <servlet-name>  kraUpdateNumberRange </servlet-name>
-      <url-pattern>   /ee/kra/updateNumberRange  </url-pattern>
+      <url-pattern>   /admin/kra/updateNumberRange  </url-pattern>
    </servlet-mapping>
 
    <servlet-mapping>
-- 
1.7.11.7

