วันอาทิตย์ที่ 12 มิถุนายน พ.ศ. 2554

การใช้งาน command MySQL 5.0

บางครั้งการใช้งาน database ในเครื่อง production ไม่มี GUI สำหรับ manage database server มีความจำเป็นต้องจำ command สำหรับใช้งานผ่าน หน้าจอ dos

cd C:\Program Files\MySQL\MySQL Server 5.0\bin
#mysql --user=root --password=root
or #-u root -p
or #-u root -pyourpassword
#show databases;
#use db_xxx;
#show tables;
#select,update,delete
#Exit;
แสดง field ในตาราง :
#show columns from table;
#status
#แสดงรายชื่อผู้ใช้ที่สามารถเข้า MySQL
mysql> use MySQL;

วันพฤหัสบดีที่ 5 พฤษภาคม พ.ศ. 2554

Exception :Cannot find the specified class java.security.PrivilegedActionException

ใคร,ทำอะไร,ที่ไหน,ทำอย่างไร,ทำแบบไหน ,ทำเพื่ออะไร,ปัญหาคือ ?

สิ่งที่ต้องการ หรือ output ?

Solution ที่ใช้ในการแก้ปัญหา ?

Key word : Cannot find the specified class java.security.PrivilegedActionException

Environment & tools

Environment & tools :

#IBM Rational Application Developer 7.0

#WebSphere Application Server 6.1

#JDK1.5

#Windows XP

#os.arch=x86

#os.name=Windows XP

#os.version=5.1 build 2600 Service Pack 3

#java.fullversion=J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20060504 (JIT enabled)

#java.vendor=IBM Corporation

#: java.version=1.5.0

#: java.vm.info=J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20060504 (JIT enabled)

J9VM - 20060501_06428_lHdSMR

JIT - 20060428_1800_r8

GC - 20060501_AA

Site HTTPS: https://203.146.18.xx/PGPayment/directpgw.aspx

Certificate ของ Site https://203.146.18.xx/PGPayment/directpgw.aspx

Save ไว้ที่ "D:\certs\cert_tbank_test.cer"

ปัญหาคือ : ไม่สามารถ Connection Site HTTPS ได้ จะมี Errors ดังนี้

Exception err:java.net.SocketException: Cannot find the specified class java.security.PrivilegedActionException: java.lang.ClassNotFoundException: com.ibm.websphere.ssl.protocol.SSLSocketFactory

หรือ Not trust certificate on jks

สิ่งที่ต้องการ หรือ output คือ :ต้องการทำ TestCase สำหรับ Connection Site ที่เป็น HTTPS โดยใช้รูปแบบที่เป็น HTTP POST แบบ Server to Server

ให้ run Method สำหรับ connection site https://203.146.18.xx/PGPayment/directpgw.aspx เพื่อต้องการค่าบางจาก เช่น ค่าที่มีการ Approve จาก bank หรือ Errors ต่างๆ

Solution ทีใช้ในการแก้ปัญหาคือ มีขั้นตอนดังนี้:

1 , source code HTTP POST method sender to site สำหรับ Test connection

ใช้ HttpClient POST

private static String sender2TBankTest(String paramInfo) throws IOException{

String ssl_filepath = "D:\\DEV\\IBM\\SDP70\\runtimes\\base_v61\\profiles\\AppSrv01\\etc\\DummyClientTrustFile.jks";

String ssl_password = “WebAS”

String K_PAYMENT_URL ="https://203.146.18.76/PGPayment/directpgw.aspx";

PostMethod post = new PostMethod(K_PAYMENT_URL);

System.out.println("##---->[sender2TBankTest] url_https : "+K_PAYMENT_URL);

try {

System.out.println("##---->[sender2TBankTest] paramInfo :"+paramInfo);

java.util.Properties props= new java.util.Properties(System.getProperties());

props.put("javax.net.ssl.trustStore",ssl_filepath);

props.put("javax.net.ssl.trustStorePassword",ssl_password);

props.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");

java.util.Properties newprops = new java.util.Properties(props);

System.setProperties(newprops);

System.out.println("##----->[sender2TBankTest] System.setProperties() OK...");

HttpClient httpclient = new HttpClient();

HttpClientParams param = new HttpClientParams();

param.setAuthenticationPreemptive(true);

System.out.println("##---->[sender2TBankTest] set Authentication Preemptive OK....");

//encrypt

String pgwMsgEnc = SinaptIQ3DES.encrypt(paramInfo);

System.out.println("##----->[sender2TBankTest] Encrypt:"+pgwMsgEnc);

//add parameter ถ้าต้องการ

post.addParameter(TBankConstant.PGWMSG, pgwMsgEnc);

String result=null;

String contenners=null;

//execute

int statusCode = httpclient.executeMethod(post);

System.out.println("##---->[sender2TBankTest] Status = " + statusCode);

if(statusCode != -1 ) {

contenners = post.getResponseBodyAsString();

//logger.info("response from post method :==> " + contents);

if(contenners!=null){

result = contenners;

}

else{

result = paramInfo;

}

System.out.println("##----->[sender2TBankTest] Connection 2 Tbank Ok.....");

}

System.out.println("##----->[sender2TBankTest] Result length:"+contenners.length());

System.out.println("##----->[sender2TBankTest] Result :"+contenners);

return result;

}

finally{

post.releaseConnection();

}

}

2, ให้ทำการแก้ไข “java.security” %PATH%/java/jre/lib/security/java.security

ตัวอย่างเช่น

D:\DEV\IBM\SDP70\runtimes\base_v61\java\jre\lib\security\java.security

มองหา Tag ดังนี้

กรณีที่ต้องการทำ TestCase

ssl.SocketFactory.provider=com.ibm.jsse2.SSLSocketFactoryImpl

ssl.ServerSocketFactory.provider=com.ibm.jsse2.SSLServerSocketFactoryImpl

ถ้าไม่มีให้ทำการเพิ่มเข้าไปตาม code ข้างบนเพื่อให้ JVM รู้จัก และนำ Class com.ibm.*…. มาใช้งานสำหรับทำ HTTP POST กับ Site ที่เป็น HTTPS ซึ่งจะเกี่ยวกับ Security

กรณ๊ที่ Run โดย Websphere Application Server ให้ใน tag default ดังนี้

ssl.SocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLSocketFactory

ssl.ServerSocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLServerSocketFactory

3,จากนั้นก็ให้ทำการ trust certificate ให้กับ WebSphere Application Server หรือ JVM หรือ KeyStore สำหรับ Connection Site HTTPS มี command ดังนี้

3.1 set JVM path สำหรับ key tool ดังนี้

C:\> set PATH= D:\DEV\IBM\SDP70\runtimes\base_v61\java\jre\bin;%PATH%

C:\> java –version //เป็นการตรวจสอบ version ของ jdk ว่าตรงกับที่ set path หรือไม่

Command สำหรับ Import certificate ให้กับ DummyClientTrustFile.jks เพื่อใช้ในการ connection site https

keytool -import -alias tbank_test_cert61 -trustcacerts -file "D:\certs\cert_tbank_test.cer" -keystore "D:\DEV\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\etc\DummyClientTrustFile.jks" -storepass WebAS

สำหรับ WAS6.1 มีการใช้ key รูปแบบใหม่ ที่เป็น .p12 ซึ่งสามารถ trust certificate ให้ ดังนี้

keytool -import -alias tbank_test_cert61 -trustcacerts -file "D:\certs\cert_tbank_test.cer" -storetype pkcs12 -keystore "D:\DEV\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\config\cells\AI-MAITREENode02Cell\nodes\AI-MAITREENode02\trust.p12" -storepass WebAS

ให้ trust certificate .p12 หรือ jks ก็ได้รองรับได้ทั้งสอง key จากนั้น จะมีคำถามให้ตอบ ว่าต้องการ Trust cert หรือไม่ ให้ ตอบ yes

ถ้าไม่มี Errors อะไรแสดงว่ามีการ trust certificate ให้กับ KEY แล้วเพื่อความมั่นใจเราสามารถแสดง รายการของ certificate ที่ trust ด้วย command ดังนี้

keytool -list -v -keystore "D:\DEV\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\etc\DummyClientTrustFile.jks" > "D:\checkCerts.txt" -storepass WebAS

ถ้ากรณีที่ trust certificate ให้กับ .p12 ก็ให้เปลี่ยนจาก DummyClientTrustFile.jks เป็น cert.p12

*******************************************

Alias name: tbank_test_cert61

Creation date: 5 พ.ค. 2554

Entry type: trustedCertEntry

Owner: CN=203.146.18.76, OU=Retail and SME E-Business Department, O="TESTBANK Public Co., Ltd.", L=Ratburana, ST=Bangkok, C=TH

Issuer: CN=SinaptIQ CA

Serial number: 6805c300000000000004

Valid from: 15/11/2553, 8:03 น. until: 15/11/2558, 8:13 น.

Certificate fingerprints:

MD5: 33:C5:27:3F:04:29:18:78:2C:BE:44:49:1F:9D:74:48

SHA1: 64:B0:A3:A6:5C:83:04:04:F6:02:9D:08:6A:B7:49:58:F5:73:50:B9

*******************************************

แสดงว่ามีการ trust เรียบร้อยแล้ว แค่นี้ก็สามารถ run test case เพื่อทดสอบ module ได้และไม่เกิด Exception ดังกล่าวแล้วครับ

ถ้ากรณีที่ run test case ผ่าน WebSphere Application Server ก็ให้มีการ แก้ไข java.security กับเป็นค่า default และ trust certificate ผ่าน Adminconsole หรือ ผ่าน command line ได้

วันอังคารที่ 3 พฤษภาคม พ.ศ. 2554

การ Set System.proterties ของ JVM

************การใช้งานและ List ******************
// add by pradoem 2010-10-23
String SSL_FILE_PATH = PropertyUtil.getProperty("PROXY_CONFIG_EURO","PROXY_SSL_PATH");
String SSL_PASSWORD = PropertyUtil.getProperty("PROXY_CONFIG_EURO","PROXY_SSL_PASSWORD");

java.util.Properties props= System.getProperties();

//java.util.Properties props= new java.util.Properties(System.getProperties());
props.put("javax.net.ssl.trustStore",SSL_FILE_PATH);
props.put("javax.net.ssl.trustStorePassword",SSL_PASSWORD);

//remark by pradoem
props.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
//remark by pradoem


java.util.Properties newprops = new java.util.Properties(props);
System.setProperties(newprops);



//System.setProperties(props);
PrintTest.printProproties();




**************Method show Properties System ของ JVM ****************
public static void printProproties()
{
Properties pr = System.getProperties();
TreeSet propKeys = new TreeSet(pr.keySet()); // TreeSet sorts keys

int i = 1;
for (Iterator it = propKeys.iterator(); it.hasNext(); ) {
String key = (String)it.next();
System.out.println(i+": "+key +"="+ pr.get(key));
i++;
}
System.out.println("test:"+pr.size());
}

วันพฤหัสบดีที่ 16 ธันวาคม พ.ศ. 2553

Was6.1 connection datasource db2 ไปยังเครื่อง database server ไม่ได้ เพราะว่าติด firewall น่ะครับ

วันพุธที่ 3 พฤศจิกายน พ.ศ. 2553

Selenium IDE simulate Test Tools ครับ

details :Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly...

reference :http://release.seleniumhq.org/selenium-ide/1.0.6/
https://addons.mozilla.org/en-US/firefox/addon/2079/

คำอธิบายเพิ่มเติม สำหรับจำลอง Test ที่ต้องการ volume เยอะๆ

วันอังคารที่ 2 พฤศจิกายน พ.ศ. 2553

การ set ให้ RAD7.0 run ใน Mode profile

Rational Application Developer 7.0 base on Eclipse
WAS6.0 or higher
jdk1.4,jdk1.5

output:
ต้องการ run debug ใน mode profile เพื่อต้องการ จับ ว่ามี package,class,method หรือ process ไหนใช้เวลาเท่าไร เพื่อมาใช้วิเคราะห์ Application ที่เราพัฒนา มีการใช้ memory เท่าโดนเรียกกี่ครั้ง ใช้ CPU เท่า

ปัญหา: เมื่อ Run WAS6.1 ใน mode profile แล้วได้
Error message
\DEV\IBM\SDP70\runtimes\base_v61\profiles\AppSrv02\logs\server1 should contain failure information

วิีธีแก้ไข :
ให้หาไฟล์ piAgent.dll แล้วนำ path ไป set path ให้กับ JVM
ตัวอย่าง :
D:\DEV\IBM\SDP70Shared\plugins\org.eclipse.hyades.execution.win32.x86_4.2.0.v200606131519\piAgent.dll
ก็นำ path D:\DEV\IBM\SDP70Shared\plugins\org.eclipse.hyades.execution.win32.x86_4.2.0.v200606131519
ไป set ที่ path ของ System ของ windows ก็ได้ จากนั้นทำการ Restart WAS ถ้ายัง Start อยู่

จากนั้นก็สามารถ ดู โปรไฟล์เลอร์ต่างๆได้ตามต้องการ เพื่อนำมาวิเคราะห์ปัญหาหรือเพื่อปรับจูน JVM ต่อไป

WAS : Websphere Application Server

วันจันทร์ที่ 1 พฤศจิกายน พ.ศ. 2553

Setting/Increase JVM heap size

Java programs executes in JVM uses Heap of memory to manage the data.
if your java program requires a larg amount of memory , it is possible that the virttual machine will begin to throw OutOfMemoryError instances when
attempting instantiate and object the default heap size if 1 MB and can increase as much as 16 MB
=======Setting/Incrase JVM heap size================
it is possible to increase heap size allocated by the java virtual machine (JVM) by using command line option.
Following are few options available to change Heap Size.
-Xms : set initial Java heap size
-Xmx : set maxinum Java heap size
-Xss : set java thread stack size

For Example, you can set mininum heap to 64 MB and maximum heap 256 MB for a Java program helloWorld.
java -Xms64m -Xmx256m HelloWorld

t is possible to read the default JVM heap size programmatically by using totalMemory() method of Runtime class. Use following code to read JVM heap size.

public class GetHeapSize {
public static void main(String[]args){

//Get the jvm heap size.
long heapSize = Runtime.getRuntime().totalMemory();

//Print the jvm heap size.
System.out.println("Heap Size = " + heapSize);
}
}

อ้างอิง : http://viralpatel.net/blogs/2009/01/jvm-java-increase-heap-size-setting-heap-size-jvm-heap.html