summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/certsrv/util
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/certsrv/util')
-rw-r--r--pki/base/common/src/com/netscape/certsrv/util/HttpInput.java197
-rw-r--r--pki/base/common/src/com/netscape/certsrv/util/IStatsSubsystem.java7
-rw-r--r--pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java309
3 files changed, 231 insertions, 282 deletions
diff --git a/pki/base/common/src/com/netscape/certsrv/util/HttpInput.java b/pki/base/common/src/com/netscape/certsrv/util/HttpInput.java
index 4f68bf635..9b7eec1d2 100644
--- a/pki/base/common/src/com/netscape/certsrv/util/HttpInput.java
+++ b/pki/base/common/src/com/netscape/certsrv/util/HttpInput.java
@@ -26,19 +26,16 @@ import javax.servlet.http.HttpServletRequest;
import netscape.ldap.LDAPDN;
-public class HttpInput
-{
- public static int getPortNumberInInt(HttpServletRequest request, String name)
- throws IOException
- {
+public class HttpInput {
+ public static int getPortNumberInInt(HttpServletRequest request, String name)
+ throws IOException {
String val = request.getParameter(name);
int p = Integer.parseInt(val);
return p;
}
-
+
public static String getBoolean(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String val = request.getParameter(name);
if (val.equals("true") || val.equals("false")) {
return val;
@@ -47,8 +44,7 @@ public class HttpInput
}
public static String getCheckbox(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String val = request.getParameter(name);
if (val == null || val.equals("")) {
return "off";
@@ -59,8 +55,7 @@ public class HttpInput
}
public static String getInteger(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String val = request.getParameter(name);
int p = 0;
try {
@@ -75,9 +70,8 @@ public class HttpInput
return val;
}
- public static String getInteger(HttpServletRequest request, String name,
- int min, int max) throws IOException
- {
+ public static String getInteger(HttpServletRequest request, String name,
+ int min, int max) throws IOException {
String val = getInteger(request, name);
int p = Integer.parseInt(val);
if (p < min || p > max) {
@@ -85,41 +79,36 @@ public class HttpInput
}
return val;
}
-
+
public static String getPortNumber(HttpServletRequest request, String name)
- throws IOException
- {
- String v = getInteger(request, name);
+ throws IOException {
+ String v = getInteger(request, name);
return v;
}
-
+
public static String getString(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String val = request.getParameter(name);
return val;
}
public static String getString(HttpServletRequest request, String name,
- int minlen, int maxlen) throws IOException
- {
+ int minlen, int maxlen) throws IOException {
String val = request.getParameter(name);
if (val.length() < minlen || val.length() > maxlen) {
- throw new IOException("String length of '" + val +
- "' is out of range");
+ throw new IOException("String length of '" + val +
+ "' is out of range");
}
return val;
}
-
+
public static String getLdapDatabase(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getURL(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String v = getString(request, name);
try {
URL u = new URL(v);
@@ -128,163 +117,145 @@ public class HttpInput
}
return v;
}
-
+
public static String getUID(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getPassword(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
public static String getKeyType(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String v = getString(request, name);
if (v.equals("rsa")) {
- return v;
+ return v;
}
if (v.equals("ecc")) {
- return v;
+ return v;
}
throw new IOException("Invalid key type '" + v + "' not supported.");
}
-
+
public static String getKeySize(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String i = getInteger(request, name);
if (i.equals("256") || i.equals("512") || i.equals("1024") ||
- i.equals("2048") || i.equals("4096")) {
- return i;
+ i.equals("2048") || i.equals("4096")) {
+ return i;
}
throw new IOException("Invalid key length '" + i + "'. Currently supported key lengths are 256, 512, 1024, 2048, 4096.");
}
public static String getKeySize(HttpServletRequest request, String name, String keyType)
- throws IOException
- {
+ throws IOException {
String i = getInteger(request, name);
if (keyType.equals("rsa")) {
- if (i.equals("256") || i.equals("512") || i.equals("1024") ||
- i.equals("2048") || i.equals("4096")) {
- return i;
- } else {
- throw new IOException("Invalid key length '" + i + "'. Currently supported RSA key lengths are 256, 512, 1024, 2048, 4096.");
- }
+ if (i.equals("256") || i.equals("512") || i.equals("1024") ||
+ i.equals("2048") || i.equals("4096")) {
+ return i;
+ } else {
+ throw new IOException("Invalid key length '" + i + "'. Currently supported RSA key lengths are 256, 512, 1024, 2048, 4096.");
+ }
}
if (keyType.equals("ecc")) {
- int p = 0;
- try {
- p = Integer.parseInt(i);
- } catch (NumberFormatException e) {
- throw new IOException("Input '" + i + "' is not an integer");
- }
- if ((p >= 112) && (p <= 571))
- return i;
- else {
- throw new IOException("Invalid key length '" + i + "'. Please consult your security officer for a proper length, or take the default value. Here are examples of some commonly used key lengths: 256, 384, 521.");
- }
-/*
+ int p = 0;
+ try {
+ p = Integer.parseInt(i);
+ } catch (NumberFormatException e) {
+ throw new IOException("Input '" + i + "' is not an integer");
+ }
+ if ((p >= 112) && (p <= 571))
+ return i;
+ else {
+ throw new IOException("Invalid key length '" + i + "'. Please consult your security officer for a proper length, or take the default value. Here are examples of some commonly used key lengths: 256, 384, 521.");
+ }
+ /*
- if (i.equals("256") || i.equals("384") || i.equals("521")) {
- return i;
- } else {
- throw new IOException("Invalid key length '" + i + "'. Currently supported ECC key lengths are 256, 384, 521.");
- }
-*/
+ if (i.equals("256") || i.equals("384") || i.equals("521")) {
+ return i;
+ } else {
+ throw new IOException("Invalid key length '" + i + "'. Currently supported ECC key lengths are 256, 384, 521.");
+ }
+ */
}
throw new IOException("Invalid key type '" + keyType + "'");
}
-
+
public static String getDN(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String v = getString(request, name);
String dn[] = LDAPDN.explodeDN(v, true);
if (dn == null || dn.length <= 0) {
- throw new IOException("Invalid DN " + v + " in " + name);
+ throw new IOException("Invalid DN " + v + " in " + name);
}
return v;
}
-
+
public static String getID(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getName(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getCertRequest(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getCertChain(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getCert(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
public static String getNickname(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getHostname(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getTokenName(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
public static String getReplicationAgreementName(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
+
public static String getEmail(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
String v = getString(request, name);
if (v.indexOf('@') == -1) {
- throw new IOException("Invalid email " + v);
+ throw new IOException("Invalid email " + v);
}
return v;
}
-
+
public static String getDomainName(HttpServletRequest request, String name)
- throws IOException
- {
+ throws IOException {
return getString(request, name);
}
-
- public static String getSecurityDomainName(HttpServletRequest request, String name)
- throws IOException
- {
+
+ public static String getSecurityDomainName(HttpServletRequest request, String name)
+ throws IOException {
String v = getName(request, name);
Pattern p = Pattern.compile("[A-Za-z0-9]+[A-Za-z0-9 -]*");
Matcher m = p.matcher(v);
diff --git a/pki/base/common/src/com/netscape/certsrv/util/IStatsSubsystem.java b/pki/base/common/src/com/netscape/certsrv/util/IStatsSubsystem.java
index c98812369..989d7a4a1 100644
--- a/pki/base/common/src/com/netscape/certsrv/util/IStatsSubsystem.java
+++ b/pki/base/common/src/com/netscape/certsrv/util/IStatsSubsystem.java
@@ -17,12 +17,10 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.util;
-
import java.util.Date;
import com.netscape.certsrv.base.ISubsystem;
-
/**
* A class represents a internal subsystem. This subsystem
* can be loaded into cert server kernel to perform
@@ -32,10 +30,9 @@ import com.netscape.certsrv.base.ISubsystem;
* @author thomask
* @version $Revision$, $Date$
*/
-public interface IStatsSubsystem extends ISubsystem
-{
+public interface IStatsSubsystem extends ISubsystem {
/**
- * Retrieves the start time since startup or
+ * Retrieves the start time since startup or
* clearing of statistics.
*/
public Date getStartTime();
diff --git a/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java b/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java
index 7c510b889..9e004b629 100644
--- a/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java
+++ b/pki/base/common/src/com/netscape/certsrv/util/StatsEvent.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.util;
-
import java.util.Enumeration;
import java.util.Vector;
@@ -28,167 +27,149 @@ import java.util.Vector;
* @author thomask
* @version $Revision$, $Date$
*/
-public class StatsEvent
-{
- private String mName = null;
- private long mMin = -1;
- private long mMax = -1;
- private long mTimeTaken = 0;
- private long mTimeTakenSqSum = 0;
- private long mNoOfOperations = 0;
- private Vector mSubEvents = new Vector();
- private StatsEvent mParent = null;
-
- public StatsEvent(StatsEvent parent)
- {
- mParent = parent;
- }
-
- public void setName(String name)
- {
- mName = name;
- }
-
- /**
- * Retrieves Transaction name.
- */
- public String getName()
- {
- return mName;
- }
-
- public void addSubEvent(StatsEvent st)
- {
- mSubEvents.addElement(st);
- }
-
- /**
- * Retrieves a list of sub transaction names.
- */
- public Enumeration getSubEventNames()
- {
- Vector names = new Vector();
- Enumeration e = mSubEvents.elements();
- while (e.hasMoreElements()) {
- StatsEvent st = (StatsEvent)e.nextElement();
- names.addElement(st.getName());
- }
- return names.elements();
- }
-
- /**
- * Retrieves a sub transaction.
- */
- public StatsEvent getSubEvent(String name)
- {
- Enumeration e = mSubEvents.elements();
- while (e.hasMoreElements()) {
- StatsEvent st = (StatsEvent)e.nextElement();
- if (st.getName().equals(name)) {
- return st;
- }
- }
- return null;
- }
-
- public void resetCounters()
- {
- mMin = -1;
- mMax = -1;
- mNoOfOperations = 0;
- mTimeTaken = 0;
- mTimeTakenSqSum = 0;
- Enumeration e = getSubEventNames();
- while (e.hasMoreElements()) {
- String n = (String)e.nextElement();
- StatsEvent c = getSubEvent(n);
- c.resetCounters();
- }
- }
-
- public long getMax()
- {
- return mMax;
- }
-
- public long getMin()
- {
- return mMin;
- }
-
- public void incNoOfOperations(long c)
- {
- mNoOfOperations += c;
- }
-
- public long getTimeTakenSqSum()
- {
- return mTimeTakenSqSum;
- }
-
- public long getPercentage()
- {
- if (mParent == null || mParent.getTimeTaken() == 0) {
- return 100;
- } else {
- return (mTimeTaken * 100 / mParent.getTimeTaken());
- }
- }
-
- public long getStdDev()
- {
- if (getNoOfOperations() == 0) {
- return 0;
- } else {
- long a = getTimeTakenSqSum();
- long b = (-2 * getAvg() *getTimeTaken());
- long c = getAvg() * getAvg() * getNoOfOperations();
- return (long)Math.sqrt((a + b + c)/getNoOfOperations());
- }
- }
-
- public long getAvg()
- {
- if (mNoOfOperations == 0) {
- return -1;
- } else {
- return mTimeTaken/mNoOfOperations;
- }
- }
-
- /**
- * Retrieves number of operations performed.
- */
- public long getNoOfOperations()
- {
- return mNoOfOperations;
- }
-
- public void incTimeTaken(long c)
- {
- if (mMin == -1) {
- mMin = c;
- } else {
- if (c < mMin) {
- mMin = c;
- }
- }
- if (mMax == -1) {
- mMax = c;
- } else {
- if (c > mMax) {
- mMax = c;
- }
- }
- mTimeTaken += c;
- mTimeTakenSqSum += (c * c);
- }
-
- /**
- * Retrieves total time token in msec.
- */
- public long getTimeTaken()
- {
- return mTimeTaken;
- }
+public class StatsEvent {
+ private String mName = null;
+ private long mMin = -1;
+ private long mMax = -1;
+ private long mTimeTaken = 0;
+ private long mTimeTakenSqSum = 0;
+ private long mNoOfOperations = 0;
+ private Vector mSubEvents = new Vector();
+ private StatsEvent mParent = null;
+
+ public StatsEvent(StatsEvent parent) {
+ mParent = parent;
+ }
+
+ public void setName(String name) {
+ mName = name;
+ }
+
+ /**
+ * Retrieves Transaction name.
+ */
+ public String getName() {
+ return mName;
+ }
+
+ public void addSubEvent(StatsEvent st) {
+ mSubEvents.addElement(st);
+ }
+
+ /**
+ * Retrieves a list of sub transaction names.
+ */
+ public Enumeration getSubEventNames() {
+ Vector names = new Vector();
+ Enumeration e = mSubEvents.elements();
+ while (e.hasMoreElements()) {
+ StatsEvent st = (StatsEvent) e.nextElement();
+ names.addElement(st.getName());
+ }
+ return names.elements();
+ }
+
+ /**
+ * Retrieves a sub transaction.
+ */
+ public StatsEvent getSubEvent(String name) {
+ Enumeration e = mSubEvents.elements();
+ while (e.hasMoreElements()) {
+ StatsEvent st = (StatsEvent) e.nextElement();
+ if (st.getName().equals(name)) {
+ return st;
+ }
+ }
+ return null;
+ }
+
+ public void resetCounters() {
+ mMin = -1;
+ mMax = -1;
+ mNoOfOperations = 0;
+ mTimeTaken = 0;
+ mTimeTakenSqSum = 0;
+ Enumeration e = getSubEventNames();
+ while (e.hasMoreElements()) {
+ String n = (String) e.nextElement();
+ StatsEvent c = getSubEvent(n);
+ c.resetCounters();
+ }
+ }
+
+ public long getMax() {
+ return mMax;
+ }
+
+ public long getMin() {
+ return mMin;
+ }
+
+ public void incNoOfOperations(long c) {
+ mNoOfOperations += c;
+ }
+
+ public long getTimeTakenSqSum() {
+ return mTimeTakenSqSum;
+ }
+
+ public long getPercentage() {
+ if (mParent == null || mParent.getTimeTaken() == 0) {
+ return 100;
+ } else {
+ return (mTimeTaken * 100 / mParent.getTimeTaken());
+ }
+ }
+
+ public long getStdDev() {
+ if (getNoOfOperations() == 0) {
+ return 0;
+ } else {
+ long a = getTimeTakenSqSum();
+ long b = (-2 * getAvg() * getTimeTaken());
+ long c = getAvg() * getAvg() * getNoOfOperations();
+ return (long) Math.sqrt((a + b + c) / getNoOfOperations());
+ }
+ }
+
+ public long getAvg() {
+ if (mNoOfOperations == 0) {
+ return -1;
+ } else {
+ return mTimeTaken / mNoOfOperations;
+ }
+ }
+
+ /**
+ * Retrieves number of operations performed.
+ */
+ public long getNoOfOperations() {
+ return mNoOfOperations;
+ }
+
+ public void incTimeTaken(long c) {
+ if (mMin == -1) {
+ mMin = c;
+ } else {
+ if (c < mMin) {
+ mMin = c;
+ }
+ }
+ if (mMax == -1) {
+ mMax = c;
+ } else {
+ if (c > mMax) {
+ mMax = c;
+ }
+ }
+ mTimeTaken += c;
+ mTimeTakenSqSum += (c * c);
+ }
+
+ /**
+ * Retrieves total time token in msec.
+ */
+ public long getTimeTaken() {
+ return mTimeTaken;
+ }
}