2009年2月21日 星期六

在Spring 2 + Hibernate 3架構中以datasource方式使用Proxool 0.9 RC3的Connection Pool

下面是在Spring 2 + Hibernate 3 + MySQL 5架構中以datasource方式使用Proxool 0.9 RC3的Connection Pool的設定檔(XML)



<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="alias"><value>mysql</value></property>
<property name="driver"><value>com.mysql.jdbc.Driver</value></property>
<property name="driverUrl"><value>jdbc:mysql://localhost:3306/extreme?user=root&amp;password=123456</value></property>
<property name="user"><value>root</value></property>
<property name="password"><value>tsaijs</value></property>
<property name="houseKeepingSleepTime"><value>5000</value></property>
<property name="houseKeepingTestSql"><value>SELECT CURRENT_DATE</value></property>
<property name="maximumConnectionCount"><value>20</value></property>
<property name="minimumConnectionCount"><value>1</value></property>
<property name="simultaneousBuildThrottle"><value>30</value></property>
<property name="trace"><value>true</value></property>
<property name="verbose"><value>true</value></property>
</bean>

Read more...

2008年12月18日 星期四

設定 IIS 6.0 的 HTTPS 服務

若要在用戶端電腦和伺服器之間使用安全的通訊通道來交換資訊時,就必須啟用 Secure Sockets Layer (SSL) 功能。本文將說明如何在 Internet Information Services (IIS) 6.0 中設定 SSL / HTTPS 服務。

1. 從 IIS 網站伺服器中產生憑証申請要求
在【目錄安全設定】選項中點擊【伺服器憑證】按鈕,【下一步】,【建立新憑證】,【現在準備憑證請求】,【下一步】,輸入【名稱】,輸入【單位】和【部門】,輸入【公用名稱】,選擇【國家】並且輸入【省】和【市縣】並【下一步】,【下一步】,【下一步】,【完成】,最後儲存在 C:\certraq.txt 。

2. 準備 OpenSSL 工作環境
把 OpenSSL v0.9.8i (編譯後的 Win32 版本)安裝至系統中,在 bin 目錄下建立目錄 demoCA,在 demoCA 下建立 private 和 newcerts 目錄,並新建 index.txt,如果沒有 serial 檔案,則到OpenSSL 網站上下載 openssl 的源檔案,解壓後,到 apps\demoCA 下,拷貝 serial 檔案過來,兩個目錄兩個檔案都放到新建的 demoCA 下。

3. 使用 OpenSSL 建立專有憑證中心的私有金鑰與簽證檔



C:\OpenSSL\bin>openssl req -x509 -newkey rsa:1024 -keyout cakey.pem -out cacert.pem -days 3650 -config openssl.cfg
WARNING: can't open config file: openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...............++++++
..++++++
writing new private key to 'cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:TAIWAN
Locality Name (eg, city) []:TAIPEI
Organization Name (eg, company) [Internet Widgits Pty Ltd]:COMPANY
Organizational Unit Name (eg, section) []:UNIT
Common Name (eg, YOUR name) []:NAME
Email Address []:email@hinet.net


這時候會產生 CA 的私有金鑰 (cakey.pem) 與 CA 的簽證檔 (cacert.pem) 兩檔案,再將 cakey.pem 拷貝到 \demoCA\private 目錄下,把 cacert.pem 拷貝到 \demoCA 目錄下。

4. 使用 CA 簽證檔 (cacert.pem) 為 IIS 的憑証申請要求 (certreq.txt) 簽發憑証


C:\OpenSSL\bin>openssl ca -in certreq.txt -out server.pem -config openssl.cfg
WARNING: can't open config file: openssl.cnf
Using configuration from openssl.cfg
Loading 'screen' into random state - done
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 286 (0x11e)
Validity
Not Before: Dec 9 05:24:00 2008 GMT
Not After : Dec 9 05:24:00 2009 GMT
Subject:
countryName = TW
stateOrProvinceName = TAIWAN
organizationName = COMPANY
organizationalUnitName = UNIT
commonName = NAME
emailAddress = email@hinet.net
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
94:C0:17:C7:CC:5B:9F:E7:80:08:CF:7B:38:F7:65:3D:EF:8F:41:13
X509v3 Authority Key Identifier:
keyid:5C:E3:71:BC:C1:22:87:24:58:E4:D0:07:65:3C:5B:39:B5:63:0C:23

Certificate is to be certified until Dec 9 05:24:00 2009 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\OpenSSL\bin>



5. 把剛剛產生的 server.pem 轉換成 x509 格式


openssl x509 -in server.pem -out server.cer


然後將 server.cer 搬移至 C 碟的根目錄下 (C:\server.cer)。

6. 在 IIS 上安裝憑證 (server.cer)
在有憑證要求的網站上按一下滑鼠右鍵,點擊【內容】,點擊【目錄安全設定】索引標籤,點擊【伺服器憑證】按鈕,點擊【下一步】,點選【處理擱置要求及安裝憑證】,再點擊【下一步】,輸入CA回應之「憑證授權的檔案」的路徑與名稱,選取C碟的憑證即可 (C:\server.cer),點擊【下一步】,輸入網站使用的SSL連接埠,可採預設值443即可,【下一步】,【完成】,【確定】。

Read more...

2008年11月25日 星期二

Unexpected Multithreading on Spring2 IoC Container

目前小弟我在執行的工作案是使用Spring2 + Hibernate3 + Flex3 + BPM + Multithreading技術的環境,有一天客戶提出的Scenario是需要用到Multithreading的,因為沒有注意到Multithreading這個條件,所以,就跟以往一樣開始撰寫Java程式和設定Spring XML configuration,在整個開發過程中都有進行單元測試,而且都很順利。但是,最後進行整合測試時,竟然發現有些模組會出現前一次執行的結果,而不會產生現在所要的結果,這下可頭大了。只好從頭開始將每個可能發生錯誤的模組進行測試,結果跟開發時一樣都沒有問題,最後只好使用Debug模式一行一行Trace程式碼,就在此時發現透過Spring的IoC注入模組並不會產生新的結果,而是直接回覆舊有的資料,因此就發現到可能是這個模組被設定成Singleton模式,因此,小弟我就立刻去翻閱Spring 2的文件,在Spring BeanFactory的XML Configuration章節中有提到,所有Spring beans的內定值都是Singletons,所以,當你想要定義一個Prototype Bean,就要在 XML 的設定檔中註明 scope="prototype",範例如下:



<bean id="studentDao" class="com.spring.service.StudentDaoImpl" scope="prototype">


Reference: http://static.springframework.org/spring/docs/2.0.x/reference/index.html

Read more...

2008年11月5日 星期三

在Vista中設定3.5G網卡

自從Vista系統開賣以來,大家都覺得Vista不好用,導致微軟縮短了Vista的生命週期,積極推出下一代Windows 7的作業系統,但是小弟我針對網路連線的功能部分卻覺得它比XP的好多了,怎麼說呢?一般使用XP的網路連線時,只要有安裝新的網路卡或設備,就會在右下角的工作列中多一個網路連線的示意圖,如果安裝了五種網路,哇!那就有五個小icon在那裏,可是Vista就有個優點,會全部將這些網路都放在『網路和共用中心』裡納管,只要將滑鼠移至『網路和共用中心』的小icon上,就會全部列出目前的連線網路,如圖所示。

其實,小弟我要說的重點是在使用3.5G網卡上網時,並不用像HiNet說明書所說的那樣,需安裝『HiNet無線上網連線軟體』與『華為連線軟體』才可連線。只要在第一次使用時,安裝網卡的驅動程式,讓『網路和共用中心』知道有這個數據機可以撥號上網就好,之後都直接在『網路和共用中心』使用『連線到網路』功能,直接撥號連線即可,不用再透過這兩套軟體,是不是方便多了呢?

Read more...

2008年9月24日 星期三

Free cPanel Web Hosting with PHP5/Mysql - no advertising!

They can offer you a free web hosting package packed with advanced features for hosting & building professional dynamic websites. They provide secure free web space with all the web hosting tools you could possibly ever need.

Free Web Hosting with Website Builder

Their package includes:
- 350 MB of Disk Space, 100 GB Bandwidth
- Host your own domain (http://www.yourdomain.com)
- cPanel Powered Hosting (you will love it)
- Over 500 website templates ready to download
- Easy to use website builder
- Free POP3 Email Box with Webmail access
- FTP and Web based File Manager
- PHP, MySQL, Perl, CGI, Ruby.
- And many more..

Click here to Register now: http://www.000webhost.com/

Read more...

Java語言中的 interface 和 abstract class 的比較

如果你有在開發 Java 程式語言的話,應該常常會遇到什麼狀況應該使用 abstract class ,什麼狀況應該使用 interface , 還是兩者都一起用呢? Interface 和 abstract class 表面上好像提供幾乎相同的能力,那如何決定使用哪個呢?
什麼時機使用 Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package.
什麼時機使用Abstract classes
An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation.
The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently. In Java, a class can inherit from only one base class.
什麼時機使用兩者一起使用
You can offer the best of both worlds, an interface and an abstract class. Implementors can ignore your abstract class if they choose. The only drawback of doing that is calling methods via their interface name is slightly slower than calling them via their abstract class name.
比較表



Interfaces vs Abstract Classes
feature
interface
abstract class
multiple inheritanceA class may implement several interfaces.A class may extend only one abstract class.
default implementationAn interface cannot provide any code at all, much less default code.An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.
constantsStatic final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.
third party convenienceAn interface implementation may be added to any existing third party class.A third party class must be rewritten to extend only from the abstract class.
is-a vs -able or can-doInterfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.An abstract class defines the core identity of its descendants. If you defined a Dog abstract class then Dalmatian descendants are Dogs, they are not merely dogable. Implemented interfaces enumerate the general things a class can do, not the things a class is. In a Java context, users should typically implement the Runnable interface rather than extending Thread, because they’re not really interested in providing some new Thread functionality, they normally just want some code to have the capability of running independently. They want to create something that can be run in a thread, not a new kind of thread.The similar is-a vs has-a debate comes up when you decide to inherit or delegate.
plug-inYou can write a new replacement module for an interface that contains not one stick of code in common with the existing implementations. When you implement the interface, you start from scratch without any default implementation. You have to obtain your tools from other classes; nothing comes with the interface other than a few constants. This gives you freedom to implement a radically different internal design.You must use the abstract class as-is for the code base, with all its attendant baggage, good or bad. The abstract class author has imposed structure on you. Depending on the cleverness of the author of the abstract class, this may be good or bad.
homogeneityIf all the various implementations share is the method signatures, then an interface works best.If the various implementations are all of a kind and share a common status and behaviour, usually an abstract class works best. Another issue that’s important is what I call "heterogeneous vs. homogeneous." If implementors/subclasses are homogeneous, tend towards an abstract base class. If they are heterogeneous, use an interface. (Now all I have to do is come up with a good definition of hetero/homo-geneous in this context.) If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.
maintenanceIf your client code talks only in terms of an interface, you can easily change the concrete implementation behind it, using a factory method.Just like an interface, if your client code talks only in terms of an abstract class, you can easily change the concrete implementation behind it, using a factory method.
speedSlow, requires extra indirection to find the corresponding method in the actual class. Modern JVMs are discovering ways to reduce this speed penalty.Fast
tersenessThe constant declarations in an interface are all presumed public static final, so you may leave that part out. You can’t call any methods to compute the initial values of your constants. You need not declare individual methods of an interface abstract. They are all presumed so.You can put shared code into an abstract class, where you cannot into an interface. If interfaces want to share code, you will have to write other bubblegum to arrange that. You may use methods to compute the initial values of your constants and variables, both instance and static. You must declare all the individual methods of an abstract class abstract.
adding functionalityIf you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method.If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.

Reference:
interface vs abstract class : Java Glossary

Read more...

2008年9月21日 星期日

會自動產生 autorun.inf 的 kavo 病毒

昨天朋友送來一部中毒的筆電,請我幫他解毒,看他似乎非常地灰心,所以還附上還原光碟給我,說最後手段就是重灌。可是常用電腦工作的人都知道,重灌作業系統是一件很可怕的事情,因為花費在恢復到以前工作環境的時間會比重灌作業系統的時間多上很多,而且還有可能會把資料給弄丟了,所以,基本上還是朝著把病毒清乾淨的目標前進。
我把電腦開機後發現桌面上怎麼有一堆殺 kavo 病毒的清毒工具,直覺上就猜想到這部電腦應該中了 kavo 相關的病毒,而且應該有人試著去解毒。因為之前我有解過這個病毒經驗,知道這個不好解,所以他們應該都試不成功吧!當然要檢查是否中了 kavo 病毒,在網路上有一篇的文章,寫得蠻詳細,可參考一下。
接著在 c:\windows\system32\ 目錄底下,用 dir /hs 的指令去查詢是否有 kavo 病毒的相關檔案,哇!如下面所列的真的好多!
kavo.exe
kxvo.exe
kevo1.dll
j3ewro.exe
jwedsfdo1.dll
解毒過程中,基本上都是使用進入作業系統的安全模式下,將這些檔案一一刪除,就完成解毒了,但是,不知道這部筆電是怎麼了,就是進不了安全模式,等了老半天螢幕還是黑的,硬碟沒有任何動靜,最後,想到一招,就是用 windows XP 的光碟片開機,用 R 修復功能進入控制台,就是像以前 DOS 一樣黑底白字的命令提示字元。然後進入 c:\windows\system32\ 目錄底下,先將這些病毒檔案的屬性改掉,然後就可一一刪除檔案,最後再重新開機就大功告成了!
Reference:
五個步驟,檢查你是否中了kavo病毒

Read more...

  © Blogger template Spain by Ourblogtemplates.com 2008

Back to TOP