Wednesday, December 18, 2013

Unique Request ID in XPath



I had a requirement to generate unique 10 char ids as Request Ids. The Oracle out of the box UID’s are long 32 char ids. The longer it is, the difficult it becomes.
Custom XPath function in java which did the work for me.

  public static String getRandomUniqueId(){
    SecureRandom random = new SecureRandom();
    String id = "";
    while (id.length() !=10)
     id = new BigInteger(50, random).toString(32).toUpperCase();
  return id;
  }