Wednesday, December 28, 2011

Memcached Introduction / Installation / Usage / HA

1.     Memcached 原理:


2.     Memcached Server安裝
2.1 For Windows:   
                          http://www.ccvita.com/257.html
                          http://lwg2001s.iteye.com/blog/135976

3.     Memcached Client
3.1 Memcachec Java Client (By Greg Whalin, 目前最多人使用):
                          https://github.com/gwhalin/Memcached-Java-Client/wiki/ (API)
3.2  Spymemcached: http://code.google.com/p/spymemcached/ (API)
3.3  Xmemcached : http://code.google.com/p/xmemcached/ (API)

4.     其他
4.1 Repcached (使Memcached 具有fail over 功能, 侷限於 Master-Slave):
4.2  ReplCache (By jGroup, 將欲儲存的key-value廣播至每台server)

Sunday, November 20, 2011

How to build a simple environment for MySql Cluster

一. MySQL Cluster 中主機分三類:
  1. 管理主機: 服務程式(Deamon) 稱為 ndb_mgmd (NDB Management Daemon的意思), 管理工具稱為 ndb_mgm (NDB Management 的意思),預設使用 Port 1186。
  2. Data Node: 實際存放資料的主機 (Storage node),服務程式稱為 ndbd (NDB Daemon的意思). 
  3. SQL Node : 提供存取資料庫內容,服務程式稱為 mysqld (MySQL Deamon的意思)
二.  實驗環境
  1. 五台 Virtual Machine (安裝 CentOS 6.0)
    2.
  • node 1 eth1:192.168.152.139 (MGM Node)
  • node 2 eth1:192.168.152.140 (SQL Node 1)
  • node 3 eth1:192.168.152.141 (Data Node 1)
  • node 4 eth1:192.168.152.142 (Data Node 2)
  • node 5 eth1:192.168.152.143 (Data Node 2)
三.  安裝
    0. 關閉SELinux:
  • chkconfig iptables off
  • /usr/sbin/setenforce 0 close SELINUX
  • reboot
  1. 下載以下 MySQL cluster package 至 /home/MySQL Cluster Package 目錄:
  • MySQL-Cluster-gpl-client-7.1.4b-1.rhel5.x86_64.rpm
  • MySQL-Cluster-gpl-clusterj-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-debuginfo-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-devel-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-embedded-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-extra-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-management-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-server-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-shared-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-storage-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-test-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-tools-7.1.4b-1.rhel5.x86_64
    2. 於/home/MySQL Cluster Package目錄中, 執行 rpm -Uhv *.rpm (建議全部機器都做), 若遇到 conflict 請將既有的 mysql 移除: yum -y remove mysql*

    3. MGM Node Setting
  • a. mkdir -p /var/lib/mysql-cluster
  • b. vi /var/lib/mysql-cluster/config.ini (這裡有 config.ini 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • c. 將以下內容貼上
  •  [ndbd default]
  •  NoOfReplicas=2
  •  DataMemory=80M
  •  IndexMemory=18M
  •  [tcp default]
  •  portnumber=2202
  •  [ndb_mgmd]
  •  hostname=192.168.152.139
  •  id=1
  •  datadir=/var/lib/mysql-cluster
  •  [ndbd]
  •  hostname=192.168.152.142
  •  datadir=/var/lib/mysql-cluster
  •  id=4
  •  [ndbd]
  •  hostname=192.168.152.141
  •  datadir=/var/lib/mysql-cluster
  •  id=3
  •  [mysqld]
  •  hostname=192.168.152.140
  • id=2
  •  [mysqld]
  •  hostname=192.168.152.143
  •  id=5
4. SQL Node Setting
  • a. vi /etc/my.cnf (這裡有 my.cnf 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • b. 將以下內容貼上: 

  • [mysqld]
  • ndbcluster # run NDB storage engine
  • ndb-connectstring=192.168.152.139 ## MGM Node IP Address

  • [mysql_cluster]
  • ndb-connectstring=192.168.152.139  ## MGM Node IP Address

5. 啟動 MySQL Cluster
  • a. 注意啟動順序: MGM Node > Data Node > SQL Node
  • b. 於 MGM Node: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
  • c. 於兩台 Data Node: ndbd --initial
  • d. 於兩台 SQL Node: service mysql start
6. 檢查目前狀況
  • a. 於MGM Node: ndb_mgm -e show
  • b. 畫面會出現: 
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @192.168.152.141  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)
id=4 @192.168.152.142  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.152.139  (mysql-5.1.44 ndb-7.1.4)

[mysqld(API)] 2 node(s)
id=2 @192.168.152.140  (mysql-5.1.44 ndb-7.1.4)
id=5 @192.168.152.143  (mysql-5.1.44 ndb-7.1.4)

7. 簡單測試
  • a. 資料庫要設為 Cluster 有些重點必須先知道:
Table 的 storage engine 須設為 NDBCLUSTER。
Table 必須有一個 primary key,若沒有,系統會自動新增一個隱藏的 primary key。
新增資料庫時,需在 Cluster 的每個 SQL node 手動執行新增該資料庫名稱。
新增 SQL node 時,需在該 node 手動新增那些要作同步的資料庫名稱。
  • b. 新增資料庫至其中一台SQL NODE:
mysql -u root -p
Enter password: 
mysql> create database testDB;
mysql> use testDB;
mysql> create table testTable (id mediumint unsigned not null auto_increment primary key, name varchar(20) not null default '') engine = ndbcluster default charset utf8;
mysql> insert into testTable value(1,'test1');
mysql> insert into testTable value(2,'test2');
**注意要達到兩台同步化一定要在table建立時加入: engine = ndbcluster

c. 兩台SQL Node 均出現以下資料
mysql> select * from testTable;
+----+-------+
| id | name  |
+----+-------+
|  1 | test1 |
|  2 | test2 |
+----+-------+
2 rows in set (0.04 sec)

8. 其他常用指令集:
  • a. MGM Node:
啟動: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
檢視目前狀況: ndb_mgm -e show
停止: ndb_mgm -e shutdown (它會把所有 MGM Node 和所有 Data Node 的 ndb_mgmd 和 ndbd 都停止掉, 但是mysqld 還留著)


  • b. Data Node: 
啟動: ndbd
  • c. SQL Node: 
啟動: service mysql start
停止: service mysql stop
重啟: service mysql restart

9. 參考資料
  1. http://helloworld.pixnet.net/blog/post/26817994-mysql-cluster-%E5%AE%89%E8%A3%9D%E7%AD%86%E8%A8%98
  2. http://space.itpub.net/15415488/viewspace-620903
  3. http://gis.nchc.org.tw/lsi/linux_basic/discuss/look.asp?id=1135&Page=2&ADMIN=1
  4. http://www.osslab.com.tw/index.php?title=User:Alang/Linux_%26_UNIX_%E5%B7%A5%E4%BD%9C%E7%AD%86%E8%A8%98/MySQL_DBA_%E7%AD%86%E8%A8%98/MySQL_Cluster


How to build a simple environment for MySql Cluster

一. MySQL Cluster 中主機分三類:
  1. 管理主機: 服務程式(Deamon) 稱為 ndb_mgmd (NDB Management Daemon的意思), 管理工具稱為 ndb_mgm (NDB Management 的意思),預設使用 Port 1186。
  2. Data Node: 實際存放資料的主機 (Storage node),服務程式稱為 ndbd (NDB Daemon的意思). 
  3. SQL Node : 提供存取資料庫內容,服務程式稱為 mysqld (MySQL Deamon的意思)
二.  實驗環境
  1. 五台 Virtual Machine (安裝 CentOS 6.0)
    2.
  • node 1 eth1:192.168.152.139 (MGM Node)
  • node 2 eth1:192.168.152.140 (SQL Node 1)
  • node 3 eth1:192.168.152.141 (Data Node 1)
  • node 4 eth1:192.168.152.142 (Data Node 2)
  • node 5 eth1:192.168.152.143 (Data Node 2)
三.  安裝
    0. 關閉SELinux:
  • chkconfig iptables off
  • /usr/sbin/setenforce 0 close SELINUX
  • reboot
  1. 下載以下 MySQL cluster package 至 /home/MySQL Cluster Package 目錄:
  • MySQL-Cluster-gpl-client-7.1.4b-1.rhel5.x86_64.rpm
  • MySQL-Cluster-gpl-clusterj-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-debuginfo-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-devel-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-embedded-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-extra-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-management-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-server-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-shared-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-storage-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-test-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-tools-7.1.4b-1.rhel5.x86_64
    2. 於/home/MySQL Cluster Package目錄中, 執行 rpm -Uhv *.rpm (建議全部機器都做), 若遇到 conflict 請將既有的 mysql 移除: yum -y remove mysql*

    3. MGM Node Setting
  • a. mkdir -p /var/lib/mysql-cluster
  • b. vi /var/lib/mysql-cluster/config.ini (這裡有 config.ini 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • c. 將以下內容貼上
  •  [ndbd default]
  •  NoOfReplicas=2
  •  DataMemory=80M
  •  IndexMemory=18M
  •  [tcp default]
  •  portnumber=2202
  •  [ndb_mgmd]
  •  hostname=192.168.152.139
  •  id=1
  •  datadir=/var/lib/mysql-cluster
  •  [ndbd]
  •  hostname=192.168.152.142
  •  datadir=/var/lib/mysql-cluster
  •  id=4
  •  [ndbd]
  •  hostname=192.168.152.141
  •  datadir=/var/lib/mysql-cluster
  •  id=3
  •  [mysqld]
  •  hostname=192.168.152.140
  • id=2
  •  [mysqld]
  •  hostname=192.168.152.143
  •  id=5
4. SQL Node Setting
  • a. vi /etc/my.cnf (這裡有 my.cnf 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • b. 將以下內容貼上: 

  • [mysqld]
  • ndbcluster # run NDB storage engine
  • ndb-connectstring=192.168.152.139 ## MGM Node IP Address

  • [mysql_cluster]
  • ndb-connectstring=192.168.152.139  ## MGM Node IP Address

5. 啟動 MySQL Cluster
  • a. 注意啟動順序: MGM Node > Data Node > SQL Node
  • b. 於 MGM Node: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
  • c. 於兩台 Data Node: ndbd --initial
  • d. 於兩台 SQL Node: service mysql start
6. 檢查目前狀況
  • a. 於MGM Node: ndb_mgm -e show
  • b. 畫面會出現: 
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @192.168.152.141  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)
id=4 @192.168.152.142  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.152.139  (mysql-5.1.44 ndb-7.1.4)

[mysqld(API)] 2 node(s)
id=2 @192.168.152.140  (mysql-5.1.44 ndb-7.1.4)
id=5 @192.168.152.143  (mysql-5.1.44 ndb-7.1.4)

7. 簡單測試
  • a. 資料庫要設為 Cluster 有些重點必須先知道:
Table 的 storage engine 須設為 NDBCLUSTER。
Table 必須有一個 primary key,若沒有,系統會自動新增一個隱藏的 primary key。
新增資料庫時,需在 Cluster 的每個 SQL node 手動執行新增該資料庫名稱。
新增 SQL node 時,需在該 node 手動新增那些要作同步的資料庫名稱。
  • b. 新增資料庫至其中一台SQL NODE:
mysql -u root -p
Enter password: 
mysql> create database testDB;
mysql> use testDB;
mysql> create table testTable (id mediumint unsigned not null auto_increment primary key, name varchar(20) not null default '') engine = ndbcluster default charset utf8;
mysql> insert into testTable value(1,'test1');
mysql> insert into testTable value(2,'test2');
**注意要達到兩台同步化一定要在table建立時加入: engine = ndbcluster

c. 兩台SQL Node 均出現以下資料
mysql> select * from testTable;
+----+-------+
| id | name  |
+----+-------+
|  1 | test1 |
|  2 | test2 |
+----+-------+
2 rows in set (0.04 sec)

8. 其他常用指令集:
  • a. MGM Node:
啟動: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
檢視目前狀況: ndb_mgm -e show
停止: ndb_mgm -e shutdown (它會把所有 MGM Node 和所有 Data Node 的 ndb_mgmd 和 ndbd 都停止掉, 但是mysqld 還留著)


  • b. Data Node: 
啟動: ndbd
  • c. SQL Node: 
啟動: service mysql start
停止: service mysql stop
重啟: service mysql restart

9. 參考資料
  1. http://helloworld.pixnet.net/blog/post/26817994-mysql-cluster-%E5%AE%89%E8%A3%9D%E7%AD%86%E8%A8%98
  2. http://space.itpub.net/15415488/viewspace-620903
  3. http://gis.nchc.org.tw/lsi/linux_basic/discuss/look.asp?id=1135&Page=2&ADMIN=1
  4. http://www.osslab.com.tw/index.php?title=User:Alang/Linux_%26_UNIX_%E5%B7%A5%E4%BD%9C%E7%AD%86%E8%A8%98/MySQL_DBA_%E7%AD%86%E8%A8%98/MySQL_Cluster


How to build a simple environment for MySql Cluster

一. MySQL Cluster 中主機分三類:
  1. 管理主機: 服務程式(Deamon) 稱為 ndb_mgmd (NDB Management Daemon的意思), 管理工具稱為 ndb_mgm (NDB Management 的意思),預設使用 Port 1186。
  2. Data Node: 實際存放資料的主機 (Storage node),服務程式稱為 ndbd (NDB Daemon的意思). 
  3. SQL Node : 提供存取資料庫內容,服務程式稱為 mysqld (MySQL Deamon的意思)
二.  實驗環境
  1. 五台 Virtual Machine (安裝 CentOS 6.0)
    2.
  • node 1 eth1:192.168.152.139 (MGM Node)
  • node 2 eth1:192.168.152.140 (SQL Node 1)
  • node 3 eth1:192.168.152.141 (Data Node 1)
  • node 4 eth1:192.168.152.142 (Data Node 2)
  • node 5 eth1:192.168.152.143 (Data Node 2)
三.  安裝
    0. 關閉SELinux:
  • chkconfig iptables off
  • /usr/sbin/setenforce 0 close SELINUX
  • reboot
  1. 下載以下 MySQL cluster package 至 /home/MySQL Cluster Package 目錄:
  • MySQL-Cluster-gpl-client-7.1.4b-1.rhel5.x86_64.rpm
  • MySQL-Cluster-gpl-clusterj-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-debuginfo-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-devel-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-embedded-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-extra-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-management-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-server-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-shared-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-storage-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-test-7.1.4b-1.rhel5.x86_64
  • MySQL-Cluster-gpl-tools-7.1.4b-1.rhel5.x86_64
    2. 於/home/MySQL Cluster Package目錄中, 執行 rpm -Uhv *.rpm (建議全部機器都做), 若遇到 conflict 請將既有的 mysql 移除: yum -y remove mysql*

    3. MGM Node Setting
  • a. mkdir -p /var/lib/mysql-cluster
  • b. vi /var/lib/mysql-cluster/config.ini (這裡有 config.ini 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • c. 將以下內容貼上
  •  [ndbd default]
  •  NoOfReplicas=2
  •  DataMemory=80M
  •  IndexMemory=18M
  •  [tcp default]
  •  portnumber=2202
  •  [ndb_mgmd]
  •  hostname=192.168.152.139
  •  id=1
  •  datadir=/var/lib/mysql-cluster
  •  [ndbd]
  •  hostname=192.168.152.142
  •  datadir=/var/lib/mysql-cluster
  •  id=4
  •  [ndbd]
  •  hostname=192.168.152.141
  •  datadir=/var/lib/mysql-cluster
  •  id=3
  •  [mysqld]
  •  hostname=192.168.152.140
  • id=2
  •  [mysqld]
  •  hostname=192.168.152.143
  •  id=5
4. SQL Node Setting
  • a. vi /etc/my.cnf (這裡有 my.cnf 的基本範例http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html)
  • b. 將以下內容貼上: 

  • [mysqld]
  • ndbcluster # run NDB storage engine
  • ndb-connectstring=192.168.152.139 ## MGM Node IP Address

  • [mysql_cluster]
  • ndb-connectstring=192.168.152.139  ## MGM Node IP Address

5. 啟動 MySQL Cluster
  • a. 注意啟動順序: MGM Node > Data Node > SQL Node
  • b. 於 MGM Node: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
  • c. 於兩台 Data Node: ndbd --initial
  • d. 於兩台 SQL Node: service mysql start
6. 檢查目前狀況
  • a. 於MGM Node: ndb_mgm -e show
  • b. 畫面會出現: 
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @192.168.152.141  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)
id=4 @192.168.152.142  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.152.139  (mysql-5.1.44 ndb-7.1.4)

[mysqld(API)] 2 node(s)
id=2 @192.168.152.140  (mysql-5.1.44 ndb-7.1.4)
id=5 @192.168.152.143  (mysql-5.1.44 ndb-7.1.4)

7. 簡單測試
  • a. 資料庫要設為 Cluster 有些重點必須先知道:
Table 的 storage engine 須設為 NDBCLUSTER。
Table 必須有一個 primary key,若沒有,系統會自動新增一個隱藏的 primary key。
新增資料庫時,需在 Cluster 的每個 SQL node 手動執行新增該資料庫名稱。
新增 SQL node 時,需在該 node 手動新增那些要作同步的資料庫名稱。
  • b. 新增資料庫至其中一台SQL NODE:
mysql -u root -p
Enter password: 
mysql> create database testDB;
mysql> use testDB;
mysql> create table testTable (id mediumint unsigned not null auto_increment primary key, name varchar(20) not null default '') engine = ndbcluster default charset utf8;
mysql> insert into testTable value(1,'test1');
mysql> insert into testTable value(2,'test2');
**注意要達到兩台同步化一定要在table建立時加入: engine = ndbcluster

c. 兩台SQL Node 均出現以下資料
mysql> select * from testTable;
+----+-------+
| id | name  |
+----+-------+
|  1 | test1 |
|  2 | test2 |
+----+-------+
2 rows in set (0.04 sec)

8. 其他常用指令集:
  • a. MGM Node:
啟動: ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
檢視目前狀況: ndb_mgm -e show
停止: ndb_mgm -e shutdown (它會把所有 MGM Node 和所有 Data Node 的 ndb_mgmd 和 ndbd 都停止掉, 但是mysqld 還留著)


  • b. Data Node: 
啟動: ndbd
  • c. SQL Node: 
啟動: service mysql start
停止: service mysql stop
重啟: service mysql restart

9. 參考資料
  1. http://helloworld.pixnet.net/blog/post/26817994-mysql-cluster-%E5%AE%89%E8%A3%9D%E7%AD%86%E8%A8%98
  2. http://space.itpub.net/15415488/viewspace-620903
  3. http://gis.nchc.org.tw/lsi/linux_basic/discuss/look.asp?id=1135&Page=2&ADMIN=1
  4. http://www.osslab.com.tw/index.php?title=User:Alang/Linux_%26_UNIX_%E5%B7%A5%E4%BD%9C%E7%AD%86%E8%A8%98/MySQL_DBA_%E7%AD%86%E8%A8%98/MySQL_Cluster


Tuesday, October 11, 2011

How to deal with XSS - Reflected issue

XSS-Reflected critical error detected by Fority, as follows:
  • JSP Page1 transmits some parameters to JSP page2, then page2 displays these parameters by <%=para1%> method. However, Forfity will detect some XSS Reflected critical errors

Example:
  • <a href="logmgt.jsp?orderName=<%=orderName%>&cateName=<%=cateName%>">Go to Another Page</a>
where, orderName and cateName come from Pasge1 

References:
  1. http://knowledge.twisc.ntust.edu.tw/doku.php?id=3%E4%BC%BA%E6%9C%8D%E7%AB%AF%E5%AE%89%E5%85%A8:3-2%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E5%BC%B1%E9%BB%9E:%E8%B7%A8%E7%B6%B2%E7%AB%99%E8%85%B3%E6%9C%AC%E6%94%BB%E6%93%8A
  2. http://itschool.dgbas.gov.tw/blog/post.do?bid=5&pid=79

  • Recommendations from above references:  Using the structured output mechanism (such as <bean:write ……> or JSTL(<c:outvalue=”……”/>) instead of using (<%=……%>)

Hence, the above source code can be recoded, as follows:
<a href="logmgt.jsp?orderName=<%c:out value="${param.orderName}"/>&cateName=<c:out value="${param.cateName}"/>">Go to Another Page</a>

Difference: 
<%=orderName%>    -------    <%c:out value="${param.orderName}"/>
where, the orderName can be save into request.setAttribute("orderName",request.getParameter("orderName"))

Finally, all the XSS-Reflected errors have been solved by JSTL tag.

How to use JSTL:
1.    Download the required jar files (jstl-impl-1.2.jar, jstl-api-1.2.jar) from http://jstl.java.net/download.html
2.     Put these jar files into WEB-INF/lib folder
3.     To define the tag (<%c/> ), you should add this line (<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>)  in the top of your page 

Monday, October 3, 2011

Install VMC under Windows

  1. Install rubyinstaller-1.9.2-p290.exe from http://www.rubyinstaller.org (make sure to check the boxes to add the ruby directory to your command path)
  2. In console mode, Type: gem install vmc
    If you are behind a firewall, you will get a nasty error message:
    ERROR: Could not find a valid gem 'vmc' (>=0) in any repository 
  3. Install vmc gem through a proxy server, type:
    gem install --http-proxy http://proxy.vmware.com:3128 (this proxy url is proxy server of your company) vmc
  4. Tell Cloud Foundry which cloud you want to connect to. Type:
    vmc target api.cloudfoundry.com (in general, you have to set the hosts info in your hosts document) 
  •  the hosts document located in C:\Windows\System32\drivers\hosts
  • add localhost name and its DNS, for example
  •  11.111.111.22   api.cf-controller.test.com.tw
     11.111.111.22   test.cf-controller.test.com.tw
  •  
  1. To communicate with Cloud Foundry through a proxy server, set the environment variable "http_proxy". In the command window, type
  2. set http_proxy=http://proxy.vmware.com:3128 (this proxy url is proxy server of your company) vmc target api.cloudfoundry.com 
  3. Login to Cloud Foundry
    vmc login
    Enter your email address and password
  4. Create a simple Ruby application.
    • c:\> md helloTest 
    • c:\> cd helloTest
    • c:\helloTest\> copy nul helloTest.rb
    • type the following sample code in helloTest.rb using a test editor :
    • require 'sinatra'
      get '/' do
          "Hello from Cloud Foundry"
      end
  5. Publish the application to the cloud. Type:
    • c:\helloTest>vmc push helloTest (helloTest only without extension (.rb))
     
  6. Would you like to deploy from the current directory? [Yn]: y
    • Application Deployed URL: 'helloTest.cf-controller.cht.com.tw'? y
    • Detected a Sinatra Application, is this correct? [Yn]: y
    • Memory Reservation [Default:128M] (64M, 128M, 256M, 512M or 1G)
    • Creating Application: OK
    • Would you like to bind any services to 'helloTest'? [yN]: n
    • Uploading Application:
    •  Checking for available resources: OK
    •  Packing application: OK
    •  Uploading (0K): OK
    • Push Status: OK
    • Staging Application: OK
    • Starting Application: OK
  7. modify C:\Windows\System32\drivers\hosts and add your application info:  
    • 11.111.111.22 helloTest.cf-controller.testcom.tw
  8. Launch a web browser and go to your Application Deployment URL (helloTest.cf-controller.testcom.tw)
Reference:
  1. http://cloud.dzone.com/news/world-your-oyster-installing
  2. http://support.cloudfoundry.com/entries/20425003-error-creating-war-file
  3. http://support.cloudfoundry.com/entries/20014132-vmc-push-failed-error-300-invalid-application-description

      Monday, August 29, 2011

      Simple Spring

      1. Download spring framework from (http://www.springsource.org/download) and commons-logging-1.1.1 from (http://commons.apache.org/logging/download_logging.cgi)
      2. Unzip the spring-framework-3.1.0.M2-with-docs.zip and commons-logging-1.1.1-src.zip
      3. Import all jar files contained in dist folder and commons-logging-1.1.1.jar into your project.
      4. create Hellobean.java
      • public class HelloBean {
            private String helloWord;
            public void setHelloWord(String helloWord) {
                this.helloWord = helloWord;
            }
            public String getHelloWord() {
                return helloWord;
            }
        }
         5.  create applicationContext.xml
      • <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
        "http://www.springframework.org/dtd/spring-beans.dtd">
        <beans>
            <bean id="helloBean" class="com.cht.paas.springtest.HelloBean">
                <property name="helloWord">
                    <value>Hello Hello Testing</value>
                </property>
            </bean>
        </beans>
         6.  create demo java:
      • import org.springframework.core.io.FileSystemResource;
        import org.springframework.core.io.Resource;
        import org.springframework.beans.factory.BeanFactory;
        import org.springframework.beans.factory.xml.XmlBeanFactory;
        public class SpringDemo {
            public static void main(String[] args) {
                Resource rs = new FileSystemResource("applicationConfig.xml");
                BeanFactory factory = new XmlBeanFactory(rs);
                HelloBean hello = (HelloBean) factory.getBean("helloBean");
                hello.setHelloWord("This is setting hello world");
                System.out.println(hello.getHelloWord());  
            }
        }
      References:
      1. http://caterpillar.onlyfun.net/Gossip/SpringGossip/SpringGossip.html
      2. http://www.springsource.org/download
      3. http://www.ibm.com/developerworks/cn/java/wa-spring1/

      Sunday, August 28, 2011

      Simple Jersey

      1. Download the jersey.zip file from (http://download.java.net/maven/2/com/sun/jersey/jersey-archive/1.8/jersey-archive-1.8.zip)
      2. nzip jersey-archive-1.8.zip and import all the jar files contained lib folder.
      3. Create Hello.java:
      • import javax.ws.rs.GET;
      • import javax.ws.rs.Path;
      • import javax.ws.rs.Produces;
      • import javax.ws.rs.core.MediaType;
      • @Path("/hello")
      • public class Hello {
      •     // This method is called if TEXT_PLAIN is request
      •     @GET
      •     @Produces(MediaType.TEXT_PLAIN)
      •     public String sayPlainTextHello() {
      •         return "Hello World";
      •     }
      •     // This method is called if XML is request
      •     @GET
      •     @Produces(MediaType.TEXT_XML)
      •     public String sayXMLHello() {
      •         return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
      •     }
      •     // This method is called if HTML is request
      •     @GET
      •     @Produces(MediaType.TEXT_HTML)
      •     public String sayHtmlHello() {
      •         return "<html> " + "<title>" + "Hello World" + "</title>"
      •                 + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
      •     }
      • }

      4. In web.xml, add the following context:
      • <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
            id="WebApp_ID" version="2.5">
            <display-name>JerseyTest</display-name>
            <welcome-file-list>
                <welcome-file>index.html</welcome-file>
                <welcome-file>index.htm</welcome-file>
                <welcome-file>index.jsp</welcome-file>
                <welcome-file>default.html</welcome-file>
                <welcome-file>default.htm</welcome-file>
                <welcome-file>default.jsp</welcome-file>
            </welcome-file-list>
            <display-name>Jersey Service</display-name>
            <servlet>
                <servlet-name>Jersey REST Service</servlet-name>
                <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
                <init-param>
                    <param-name>com.sun.jersey.config.property.packages</param-name>
                    <param-value>com.cht.paas.jersey</param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
            </servlet>
            <servlet-mapping>
                <servlet-name>Jersey REST Service</servlet-name>
                <url-pattern>/rest/*</url-pattern>
            </servlet-mapping>
        </web-app>
      5. start your tomcat server and enter the url:  http://localhost:8080/JerseyTest/rest/hello
      References:
      1. http://www.vogella.de/articles/REST/article.html#first_project
      2. http://jersey.java.net/nonav/documentation/latest/user-guide.html#chapter_deps