You have to created a trustServerCertificate() which basically trust the certificate of the requested server at runtime.
For that you should do the following step
1)Create a keystore and import the certificate into this keystore file (say test.keystore)
2)put it into your project class path
3)Write a method trustServerCertificate() which trust the keystore file
keystore.properties
KeyStoreLocation=/test.keystore
TrustClass.java
class TrustClass{
static Properties properties = new Properties();
void trustServerCertificate(){
try {
properties.load(TrustClass.class.getClassLoader().getResourceAsStream("keystore.properties"));
System.out.println("Properties loaded successfully");
} catch (IOException e) {
properties = null;
System.out.println("Properties not loaded: " + e.getMessage());
e.printStackTrace();
}
String keyStore = Util.class.getClassLoader().getResource(TrustClass.getProperties("KeyStoreLocation")).getFile();
System.out.println("Keystore path :" + keyStore);
System.setProperty("javax.net.ssl.trustStore", keyStore);
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
}
public static String getProperties(String key) {
return properties.getProperty(key);
}
public static void main(String arg[]){
TrustClass obj=new TrustClass();
obj. trustServerCertificate
}
}
Tuesday, 16 April 2013
Saturday, 6 April 2013
Measure runtime memory used by your code
Measure runtime memory used by your code:
//Start------
-------
YourAPIClass object=new YourAPIClass();
Runtime runtime = Runtime.getRuntime();
object.someMethod()//call your api methods whose memory usage u want to know
runtime.gc(); // Run garbage collector
long usedMemory = runtime.totalMemory() - runtime.freeMemory(); // Used memory Evaluation In bytes
System.out.println("Memory used by someMetod is = " usedMemory +" bytes");
--------
--------
//end
Subscribe to:
Posts (Atom)