http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6a864a1/test/src/com/cloud/test/stress/TestClientWithAPI.java
----------------------------------------------------------------------
diff --git a/test/src/com/cloud/test/stress/TestClientWithAPI.java 
b/test/src/com/cloud/test/stress/TestClientWithAPI.java
index 84cb087..9d21927 100644
--- a/test/src/com/cloud/test/stress/TestClientWithAPI.java
+++ b/test/src/com/cloud/test/stress/TestClientWithAPI.java
@@ -49,7 +49,6 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import com.cloud.utils.encoding.Base64;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.trilead.ssh2.ChannelCondition;
 import com.trilead.ssh2.Connection;
@@ -182,7 +181,7 @@ public class TestClientWithAPI {
                 if (arg.equals("-no")) {
                     networkOfferingId = iter.next();
                 }
-                
+
                 if (arg.equals("-pass")) {
                     vmPassword = iter.next();
                 }
@@ -210,6 +209,7 @@ public class TestClientWithAPI {
 
             for (int i = 0; i < numThreads; i++) {
                 new Thread(new Runnable() {
+                    @Override
                     public void run() {
                         do {
                             String username = null;
@@ -440,7 +440,7 @@ public class TestClientWithAPI {
                 for (int j = 0; j < childNodes.getLength(); j++) {
                     Node n = childNodes.item(j);
                     if ("id".equals(n.getNodeName())) {
-                //    if ("ipaddress".equals(n.getNodeName())) {
+                        //    if ("ipaddress".equals(n.getNodeName())) {
                         ipAddress = n.getTextContent();
                     } else if ("issourcenat".equals(n.getNodeName())) {
                         isSourceNat = Boolean.parseBoolean(n.getTextContent());
@@ -478,7 +478,7 @@ public class TestClientWithAPI {
                     }
                     else if("ipaddress".equals(n.getNodeName()))
                     {
-                       ipAddress = n.getTextContent();
+                        ipAddress = n.getTextContent();
                     }
                     else if ("issourcenat".equals(n.getNodeName())) {
                         isSourceNat = Boolean.parseBoolean(n.getTextContent());
@@ -609,7 +609,7 @@ public class TestClientWithAPI {
             s_logger.error("Create virtual network failed for account " + 
username + " with error code :" + responseCode + ", aborting deployment test. 
The command was sent with url " + url);
             return -1;
         }
-/*
+        /*
         // ---------------------------------
         // CREATE DIRECT NETWORK
         // ---------------------------------
@@ -629,9 +629,9 @@ public class TestClientWithAPI {
             s_logger.error("Create direct network failed for account " + 
username + " with error code :" + responseCode + ", aborting deployment test. 
The command was sent with url " + url);
             return -1;
         }
-*/
-        
-        
+         */
+
+
         // ---------------------------------
         // DEPLOY LINUX VM
         // ---------------------------------
@@ -706,7 +706,7 @@ public class TestClientWithAPI {
                 } 
                 else
                 {
-                       s_logger.info("Associate IP Address response code: " + 
responseCode);
+                    s_logger.info("Associate IP Address response code: " + 
responseCode);
                     long publicIpId = Long.parseLong(values.get("id"));
                     s_logger.info("Associate IP's Id: " + publicIpId);
                     _publicIpId.set(values.get("id"));         
@@ -715,13 +715,13 @@ public class TestClientWithAPI {
                 s_logger.error("associate ip address for windows vm failed 
with error code: " + responseCode + ". Following URL was sent: " + url);
                 return responseCode;
             }
-            
+
             String encodedPublicIpId = URLEncoder.encode(_publicIpId.get(), 
"UTF-8");
             requestToSign = "apikey=" + encodedApiKey + 
"&command=listPublicIpAddresses"+"&id="+ encodedPublicIpId;
             requestToSign = requestToSign.toLowerCase();
             signature = signRequest(requestToSign, _secretKey.get());
             encodedSignature = URLEncoder.encode(signature, "UTF-8");
-            
+
             url = developerServer + "?command=listPublicIpAddresses&apikey=" + 
encodedApiKey + "&id=" + encodedPublicIpId + "&signature=" + encodedSignature;
             client = new HttpClient();
             method = new GetMethod(url);
@@ -730,9 +730,9 @@ public class TestClientWithAPI {
             s_logger.info("list ip addresses for user " + userId + " response 
code: " + responseCode);
             if (responseCode == 200) {
                 InputStream is = method.getResponseBodyAsStream();
-         //       InputStream ips = method.getResponseBodyAsStream();
+                //       InputStream ips = method.getResponseBodyAsStream();
                 List<String> ipAddressValues = getIPs(is, false);
-         //       List<String> ipAddressVals = getIPs(is, false, true);
+                //       List<String> ipAddressVals = getIPs(is, false, true);
                 if ((ipAddressValues != null) && !ipAddressValues.isEmpty()) {
                     _windowsIpId.set(ipAddressValues.get(0));
                     _windowsIP.set(ipAddressValues.get(1));
@@ -743,7 +743,7 @@ public class TestClientWithAPI {
                 s_logger.error("list ip addresses failed with error code: " + 
responseCode + ". Following URL was sent: " + url);
                 return responseCode;
             }
-            
+
             // ---------------------------------
             // Use the SourceNat IP for linux
             // ---------------------------------
@@ -776,17 +776,17 @@ public class TestClientWithAPI {
                     return responseCode;
                 }
             }
-            
+
             //--------------------------------------------
             // Enable Static NAT for the Source NAT Ip
             //--------------------------------------------
             String encodedSourceNatPublicIpId = 
URLEncoder.encode(_linuxIpId.get(), "UTF-8");
-                   
-  /*          requestToSign = "apikey=" + encodedApiKey + 
"&command=enableStaticNat"+"&id=" + encodedSourceNatPublicIpId + 
"&virtualMachineId=" + encodedVmId;;
+
+            /*          requestToSign = "apikey=" + encodedApiKey + 
"&command=enableStaticNat"+"&id=" + encodedSourceNatPublicIpId + 
"&virtualMachineId=" + encodedVmId;;
             requestToSign = requestToSign.toLowerCase();
             signature = signRequest(requestToSign, _secretKey.get());
             encodedSignature = URLEncoder.encode(signature, "UTF-8");
-            
+
             url = developerServer + "?command=enableStaticNat&apikey=" + 
encodedApiKey + "&signature=" + encodedSignature + "&id=" + 
encodedSourceNatPublicIpId + "&virtualMachineId=" + encodedVmId;
             client = new HttpClient();
             method = new GetMethod(url);
@@ -801,7 +801,7 @@ public class TestClientWithAPI {
                 s_logger.error("Enable Static NAT failed with error code: " + 
responseCode + ". Following URL was sent: " + url);
                 return responseCode;
             }
-  */          
+             */          
             // -------------------------------------------------------------
             // CREATE IP FORWARDING RULE -- Linux VM
             // -------------------------------------------------------------
@@ -825,7 +825,7 @@ public class TestClientWithAPI {
                 long ipfwdid = Long.parseLong(values.get("id"));
                 s_logger.info("got Port Forwarding Rule's Id:" + ipfwdid);
                 _linipfwdid.set(values.get("id"));
-                
+
             } else {
                 s_logger.error("Port forwarding rule creation failed with 
error code: " + responseCode + ". Following URL was sent: " + url);
                 return responseCode;
@@ -882,7 +882,7 @@ public class TestClientWithAPI {
                     String encodedTemplateId = URLEncoder.encode("" + 
templateId, "UTF-8");
                     encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8");
                     String encodedNetworkIds = 
URLEncoder.encode(_networkId.get()+",206","UTF-8");
-                    
+
                     requestToSign = "apikey=" + encodedApiKey + 
"&command=deployVirtualMachine&diskofferingid=" + diskOfferingId + 
"&networkids=" + encodedNetworkIds + "&serviceofferingid=" + 
encodedServiceOfferingId + "&templateid=" + encodedTemplateId
                             + "&zoneid=" + encodedZoneId;
                     requestToSign = requestToSign.toLowerCase();
@@ -918,14 +918,14 @@ public class TestClientWithAPI {
                 //--------------------------------------------
                 // Enable Static NAT for the Non Source NAT Ip
                 //--------------------------------------------
-                
+
                 encodedVmId = URLEncoder.encode(_windowsVmId.get(), "UTF-8");
                 encodedPublicIpId = URLEncoder.encode(_publicIpId.get(), 
"UTF-8");
                 requestToSign = "apikey=" + encodedApiKey + 
"&command=enableStaticNat"+"&ipaddressid="+ encodedPublicIpId + 
"&virtualMachineId=" + encodedVmId;
                 requestToSign = requestToSign.toLowerCase();
                 signature = signRequest(requestToSign, _secretKey.get());
                 encodedSignature = URLEncoder.encode(signature, "UTF-8");
-                
+
                 url = developerServer + "?command=enableStaticNat&apikey=" + 
encodedApiKey + "&ipaddressid=" + encodedPublicIpId + "&signature=" + 
encodedSignature + "&virtualMachineId=" + encodedVmId;
                 client = new HttpClient();
                 method = new GetMethod(url);
@@ -941,7 +941,7 @@ public class TestClientWithAPI {
                     return responseCode;
                 }                                            
 
-                
+
                 // 
-------------------------------------------------------------
                 // CREATE IP FORWARDING RULE -- Windows VM
                 // 
-------------------------------------------------------------
@@ -972,7 +972,7 @@ public class TestClientWithAPI {
                     s_logger.error("Port forwarding rule creation failed with 
error code: " + responseCode + ". Following URL was sent: " + url);
                     return responseCode;
                 }
-           }
+            }
         }
         return responseCode;
     }
@@ -1178,7 +1178,7 @@ public class TestClientWithAPI {
         }
 
         // Create volume from the snapshot created on the previous step and 
attach it to the running vm
-  /*      encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8");
+        /*      encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8");
         requestToSign = "apikey=" + encodedApiKey + 
"&command=createVolume&name=" + _account.get() + "&snapshotid=" + 
_snapshot.get();
         requestToSign = requestToSign.toLowerCase();
         signature = signRequest(requestToSign, _secretKey.get());
@@ -1222,7 +1222,7 @@ public class TestClientWithAPI {
                 return responseCode;
             }
         }
-*/
+         */
         // -----------------------------
         // Execute reboot/stop/start commands for the VMs before deleting the 
account - made to exercise xen
         // -----------------------------
@@ -1896,7 +1896,7 @@ public class TestClientWithAPI {
                 InputStream input = method.getResponseBodyAsStream();
                 Element el = queryAsyncJobResult(server, input);
                 s_logger.info("IP forwarding rule was successfully deleted");  
      
-                
+
             } else {
                 s_logger.error("IP forwarding rule creation failed with error 
code: " + responseCode + ". Following URL was sent: " + url);
                 return responseCode;
@@ -1911,7 +1911,7 @@ public class TestClientWithAPI {
             requestToSign = requestToSign.toLowerCase();
             signature = signRequest(requestToSign, _secretKey.get());
             encodedSignature = URLEncoder.encode(signature, "UTF-8");
-            
+
             url = developerServer + "?command=disableStaticNat&apikey=" + 
encodedApiKey + "&id=" + encodedPublicIpId + "&signature=" + encodedSignature ;
             client = new HttpClient();
             method = new GetMethod(url);
@@ -1926,7 +1926,7 @@ public class TestClientWithAPI {
                 s_logger.error("Disable Static NAT failed with error code: " + 
responseCode + ". Following URL was sent: " + url);
                 return responseCode;
             }
-            
+
             // -----------------------------------------
             // DISASSOCIATE IP ADDRESSES
             // -----------------------------------------
@@ -1946,7 +1946,7 @@ public class TestClientWithAPI {
                         InputStream input = method.getResponseBodyAsStream();
                         Element disassocipel = queryAsyncJobResult(server, 
input);
                         Map<String, String> success = 
getSingleValueFromXML(disassocipel, new String[] {"success"});
-               //       Map<String, String> success = 
getSingleValueFromXML(input, new String[] { "success" });
+                        //       Map<String, String> success = 
getSingleValueFromXML(input, new String[] { "success" });
                         s_logger.info("disassociate ip address..success? " + 
success.get("success"));
                     } else {
                         s_logger.error("disassociate ip address failed with 
error code: " + responseCode + ". Following URL was sent: " + url);
@@ -1977,7 +1977,7 @@ public class TestClientWithAPI {
             mac.init(keySpec);
             mac.update(request.getBytes());
             byte[] encryptedBytes = mac.doFinal();
-            return Base64.encodeBytes(encryptedBytes);
+            return 
org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(encryptedBytes);
         } catch (Exception ex) {
             s_logger.error("unable to sign request", ex);
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6a864a1/test/src/com/cloud/test/utils/UtilsForTest.java
----------------------------------------------------------------------
diff --git a/test/src/com/cloud/test/utils/UtilsForTest.java 
b/test/src/com/cloud/test/utils/UtilsForTest.java
index 500cea5..6414c0b 100644
--- a/test/src/com/cloud/test/utils/UtilsForTest.java
+++ b/test/src/com/cloud/test/utils/UtilsForTest.java
@@ -30,208 +30,208 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.apache.commons.codec.binary.Base64;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import com.cloud.utils.encoding.Base64;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 public class UtilsForTest {
-       
-       private static DocumentBuilderFactory factory = DocumentBuilderFactory
-       .newInstance();
-       
-       public static boolean verifyTags (Map<String, String> params) {
-               boolean result = true;
-               for (String value : params.keySet()) {
-                       if (params.get(value) == null) {
-                               result=false;
-                       }
-               }
-               return result;
-       }
-       
-       public static boolean verifyTagValues (Map<String, String> params, 
Map<String, String> pattern) {
-               boolean result = true;
-               
-               if (pattern != null) {
-                       for (String value : pattern.keySet()) {
-                               if 
(!pattern.get(value).equals(params.get(value))) {
-                                       result=false;
-                                       System.out.println("Tag " + value + " 
has " + params.get(value) + " while expected value is: " + pattern.get(value));
-                               }
-                       }
-               }
-               return result;
-       }
-       
-       
-       public static Map<String, String> parseXML(InputStream is,
-                       String[] tagNames) {
-               Map<String, String> returnValues = new HashMap<String, 
String>();
-               try {
-                       DocumentBuilder docBuilder = 
factory.newDocumentBuilder();
-                       Document doc = docBuilder.parse(is);
-                       Element rootElement = doc.getDocumentElement();
-
-                       for (int i = 0; i < tagNames.length; i++) {
-                               NodeList targetNodes = rootElement
-                                               
.getElementsByTagName(tagNames[i]);
-                               if (targetNodes.getLength() <= 0) {
-                                       System.out.println("no " + tagNames[i]
-                                                       + " tag in the 
response");
-                                       returnValues.put(tagNames[i], null);
-                               } else {
-                                       returnValues.put(tagNames[i], 
targetNodes.item(0)
-                                                       .getTextContent());
-                               }
-                       }
-               } catch (Exception ex) {
-                       System.out.println("error processing XML");
-                       ex.printStackTrace();
-               }
-               return returnValues;
-       }
-       
-       
-       public static ArrayList<HashMap<String, String>> parseMulXML 
(InputStream is, String[] tagNames){
-               ArrayList<HashMap<String, String>> returnValues = new 
ArrayList<HashMap <String, String>>();
-               
-               try {
-                       DocumentBuilder docBuilder = 
factory.newDocumentBuilder();
-                       Document doc = docBuilder.parse(is);
-                       Element rootElement = doc.getDocumentElement();
-                       for (int i = 0; i < tagNames.length; i++) {
-                               NodeList targetNodes = rootElement
-                                               
.getElementsByTagName(tagNames[i]);
-                               if (targetNodes.getLength() <= 0) {
-                                       System.out.println("no " + tagNames[i]
-                                                       + " tag in XML 
response...returning null");
-                               } else {
-                                       for (int j = 0; j < 
targetNodes.getLength(); j++) {
-                                               HashMap<String, String> 
valueList = new HashMap<String,String> ();
-                                               Node node = targetNodes.item(j);
-                                               //parse child nodes
-                                               NodeList child = 
node.getChildNodes();
-                                               for (int c=0; 
c<node.getChildNodes().getLength(); c++){
-                                                       
child.item(c).getNodeName();
-                                                       
valueList.put(child.item(c).getNodeName(), child.item(c).getTextContent());
-                                               }
-                                               returnValues.add(valueList);
-                                       }
-                                       
-                               }
-                       }
-               } catch (Exception ex) {
-                       System.out.println(ex);
-               }
-               
-               return returnValues;
-       }
-       
-       
-       public static String createMD5String(String password) {
-               MessageDigest md5;
-               try {
-                       md5 = MessageDigest.getInstance("MD5");
-               } catch (NoSuchAlgorithmException e) {
-                       throw new CloudRuntimeException("Error", e);
-               }
-
-               md5.reset();
-               BigInteger pwInt = new BigInteger(1, 
md5.digest(password.getBytes()));
-
-               // make sure our MD5 hash value is 32 digits long...
-               StringBuffer sb = new StringBuffer();
-               String pwStr = pwInt.toString(16);
-               int padding = 32 - pwStr.length();
-               for (int i = 0; i < padding; i++) {
-                       sb.append('0');
-               }
-               sb.append(pwStr);
-               return sb.toString();
-       }
-       
-       
-       
-       
-       
-       
-       
-       public static Map<String, String> getSingleValueFromXML(InputStream is,
-                       String[] tagNames) {
-               Map<String, String> returnValues = new HashMap<String, 
String>();
-               try {
-                       DocumentBuilder docBuilder = 
factory.newDocumentBuilder();
-                       Document doc = docBuilder.parse(is);
-                       Element rootElement = doc.getDocumentElement();
-
-                       for (int i = 0; i < tagNames.length; i++) {
-                               NodeList targetNodes = rootElement
-                                               
.getElementsByTagName(tagNames[i]);
-                               if (targetNodes.getLength() <= 0) {
-                                       System.out.println("no " + tagNames[i]
-                                                       + " tag in XML 
response...returning null");
-                               } else {
-                                       returnValues.put(tagNames[i], 
targetNodes.item(0)
-                                                       .getTextContent());
-                               }
-                       }
-               } catch (Exception ex) {
-                       System.out.println("error processing XML");
-                       ex.printStackTrace();
-               }
-               return returnValues;
-       }
-       
-       
-       public static Map<String, List<String>> getMultipleValuesFromXML(
-                       InputStream is, String[] tagNames) {
-               Map<String, List<String>> returnValues = new HashMap<String, 
List<String>>();
-               try {
-                       DocumentBuilder docBuilder = 
factory.newDocumentBuilder();
-                       Document doc = docBuilder.parse(is);
-                       Element rootElement = doc.getDocumentElement();
-                       for (int i = 0; i < tagNames.length; i++) {
-                               NodeList targetNodes = rootElement
-                                               
.getElementsByTagName(tagNames[i]);
-                               if (targetNodes.getLength() <= 0) {
-                                       System.out.println("no " + tagNames[i]
-                                                       + " tag in XML 
response...returning null");
-                               } else {
-                                       List<String> valueList = new 
ArrayList<String>();
-                                       for (int j = 0; j < 
targetNodes.getLength(); j++) {
-                                               Node node = targetNodes.item(j);
-                                               
valueList.add(node.getTextContent());
-                                       }
-                                       returnValues.put(tagNames[i], 
valueList);
-                               }
-                       }
-               } catch (Exception ex) {
-                       System.out.println(ex);
-               }
-               return returnValues;
-       }
-       
-       
-       
-       public static String signRequest(String request, String key) {
-               try {
-                       Mac mac = Mac.getInstance("HmacSHA1");
-                       SecretKeySpec keySpec = new 
SecretKeySpec(key.getBytes(),
-                                       "HmacSHA1");
-                       mac.init(keySpec);
-                       mac.update(request.getBytes());
-                       byte[] encryptedBytes = mac.doFinal();
-                       //System.out.println("HmacSHA1 hash: " + 
encryptedBytes);
-                       return Base64.encodeBytes(encryptedBytes);
-               } catch (Exception ex) {
-                       System.out.println("unable to sign request");
-                       ex.printStackTrace();
-               }
-               return null;
-       }
-       
+
+    private static DocumentBuilderFactory factory = DocumentBuilderFactory
+            .newInstance();
+
+    public static boolean verifyTags (Map<String, String> params) {
+        boolean result = true;
+        for (String value : params.keySet()) {
+            if (params.get(value) == null) {
+                result=false;
+            }
+        }
+        return result;
+    }
+
+    public static boolean verifyTagValues (Map<String, String> params, 
Map<String, String> pattern) {
+        boolean result = true;
+
+        if (pattern != null) {
+            for (String value : pattern.keySet()) {
+                if (!pattern.get(value).equals(params.get(value))) {
+                    result=false;
+                    System.out.println("Tag " + value + " has " + 
params.get(value) + " while expected value is: " + pattern.get(value));
+                }
+            }
+        }
+        return result;
+    }
+
+
+    public static Map<String, String> parseXML(InputStream is,
+            String[] tagNames) {
+        Map<String, String> returnValues = new HashMap<String, String>();
+        try {
+            DocumentBuilder docBuilder = factory.newDocumentBuilder();
+            Document doc = docBuilder.parse(is);
+            Element rootElement = doc.getDocumentElement();
+
+            for (int i = 0; i < tagNames.length; i++) {
+                NodeList targetNodes = rootElement
+                        .getElementsByTagName(tagNames[i]);
+                if (targetNodes.getLength() <= 0) {
+                    System.out.println("no " + tagNames[i]
+                            + " tag in the response");
+                    returnValues.put(tagNames[i], null);
+                } else {
+                    returnValues.put(tagNames[i], targetNodes.item(0)
+                            .getTextContent());
+                }
+            }
+        } catch (Exception ex) {
+            System.out.println("error processing XML");
+            ex.printStackTrace();
+        }
+        return returnValues;
+    }
+
+
+    public static ArrayList<HashMap<String, String>> parseMulXML (InputStream 
is, String[] tagNames){
+        ArrayList<HashMap<String, String>> returnValues = new 
ArrayList<HashMap <String, String>>();
+
+        try {
+            DocumentBuilder docBuilder = factory.newDocumentBuilder();
+            Document doc = docBuilder.parse(is);
+            Element rootElement = doc.getDocumentElement();
+            for (int i = 0; i < tagNames.length; i++) {
+                NodeList targetNodes = rootElement
+                        .getElementsByTagName(tagNames[i]);
+                if (targetNodes.getLength() <= 0) {
+                    System.out.println("no " + tagNames[i]
+                            + " tag in XML response...returning null");
+                } else {
+                    for (int j = 0; j < targetNodes.getLength(); j++) {
+                        HashMap<String, String> valueList = new 
HashMap<String,String> ();
+                        Node node = targetNodes.item(j);
+                        //parse child nodes
+                        NodeList child = node.getChildNodes();
+                        for (int c=0; c<node.getChildNodes().getLength(); c++){
+                            child.item(c).getNodeName();
+                            valueList.put(child.item(c).getNodeName(), 
child.item(c).getTextContent());
+                        }
+                        returnValues.add(valueList);
+                    }
+
+                }
+            }
+        } catch (Exception ex) {
+            System.out.println(ex);
+        }
+
+        return returnValues;
+    }
+
+
+    public static String createMD5String(String password) {
+        MessageDigest md5;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+        } catch (NoSuchAlgorithmException e) {
+            throw new CloudRuntimeException("Error", e);
+        }
+
+        md5.reset();
+        BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes()));
+
+        // make sure our MD5 hash value is 32 digits long...
+        StringBuffer sb = new StringBuffer();
+        String pwStr = pwInt.toString(16);
+        int padding = 32 - pwStr.length();
+        for (int i = 0; i < padding; i++) {
+            sb.append('0');
+        }
+        sb.append(pwStr);
+        return sb.toString();
+    }
+
+
+
+
+
+
+
+    public static Map<String, String> getSingleValueFromXML(InputStream is,
+            String[] tagNames) {
+        Map<String, String> returnValues = new HashMap<String, String>();
+        try {
+            DocumentBuilder docBuilder = factory.newDocumentBuilder();
+            Document doc = docBuilder.parse(is);
+            Element rootElement = doc.getDocumentElement();
+
+            for (int i = 0; i < tagNames.length; i++) {
+                NodeList targetNodes = rootElement
+                        .getElementsByTagName(tagNames[i]);
+                if (targetNodes.getLength() <= 0) {
+                    System.out.println("no " + tagNames[i]
+                            + " tag in XML response...returning null");
+                } else {
+                    returnValues.put(tagNames[i], targetNodes.item(0)
+                            .getTextContent());
+                }
+            }
+        } catch (Exception ex) {
+            System.out.println("error processing XML");
+            ex.printStackTrace();
+        }
+        return returnValues;
+    }
+
+
+    public static Map<String, List<String>> getMultipleValuesFromXML(
+            InputStream is, String[] tagNames) {
+        Map<String, List<String>> returnValues = new HashMap<String, 
List<String>>();
+        try {
+            DocumentBuilder docBuilder = factory.newDocumentBuilder();
+            Document doc = docBuilder.parse(is);
+            Element rootElement = doc.getDocumentElement();
+            for (int i = 0; i < tagNames.length; i++) {
+                NodeList targetNodes = rootElement
+                        .getElementsByTagName(tagNames[i]);
+                if (targetNodes.getLength() <= 0) {
+                    System.out.println("no " + tagNames[i]
+                            + " tag in XML response...returning null");
+                } else {
+                    List<String> valueList = new ArrayList<String>();
+                    for (int j = 0; j < targetNodes.getLength(); j++) {
+                        Node node = targetNodes.item(j);
+                        valueList.add(node.getTextContent());
+                    }
+                    returnValues.put(tagNames[i], valueList);
+                }
+            }
+        } catch (Exception ex) {
+            System.out.println(ex);
+        }
+        return returnValues;
+    }
+
+
+
+    public static String signRequest(String request, String key) {
+        try {
+            Mac mac = Mac.getInstance("HmacSHA1");
+            SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(),
+                    "HmacSHA1");
+            mac.init(keySpec);
+            mac.update(request.getBytes());
+            byte[] encryptedBytes = mac.doFinal();
+            //System.out.println("HmacSHA1 hash: " + encryptedBytes);
+            return Base64.encodeBase64URLSafeString(encryptedBytes);
+        } catch (Exception ex) {
+            System.out.println("unable to sign request");
+            ex.printStackTrace();
+        }
+        return null;
+    }
+
 }

Reply via email to