proxool配置文件中用户和密码加密

Proxool是一种Java数据库连接池技术。sourceforge下的一个开源项目,这个项目提供一个健壮、易用的连接池,最为关键的是这个连接池提供监控的功能,方便易用,便于发现连接泄漏的情况。

Proxool是一种Java 数据库连接池技术。sourceforge下的一个开源项目,这个项目提供一个健壮、易用的 连接池,最为关键的是这个连接池提供监控的功能,方便易用,便于发现连接泄漏的情况。
目前是和DBCP以及C3P0一起,最为常见的三种JDBC 连接池技术
日前,Hibernate官方宣布由于Bug太多不再支持DBCP,而推荐使用 Proxool或C3P0。

proxool是个很好的开源连接池。但配置文件中的用户和密码却是明文存储的,如果对系统安全有较高的要求,使用时就麻烦了。昨天下了Proxool 0.9.1的源码,研究了下,做了些小小的改动,现在proxool配置文件中用户和密码可以使用密文存储了,同时明文的也可以正常使用。解密功能部分做成了接口,可以用自己的算法来实现,很方便。

 

先上配置文件proxool.xml

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="gb2312"?>       
  2.   
  3. <!-- the proxool configuration can be embedded within your own application's. Anything outside the "proxool" tag is ignored. -->       
  4.   
  5. <something-else-entirely>     
  6.     <proxool>     
  7.         <!--连接池的别名-->     
  8.         <alias>hdqt</alias>  
  9.         <!--实现解密的工具类-->    
  10.         <encrypt>cn.bq.tools.DecUtil</encrypt>  
  11.         <!--proxool只能管理由自己产生的连接-->     
  12.         <driver-url>jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=xxxx</driver-url>     
  13.         <!--JDBC驱动程序-->     
  14.         <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>     
  15.         <driver-properties>     
  16.             <!--加密后的用户名和密码-->  
  17.             <property name="user" value="da33e8657877280c32683ae317ef78e1"/>     
  18.             <property name="password" value="3defde98af47835a74537600eebe78f2"/>     
  19.         </driver-properties>     
  20.         <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->     
  21.         <house-keeping-sleep-time>90000</house-keeping-sleep-time>   
  22.         <house-keeping-test-sql>select getdate()</house-keeping-test-sql>  
  23.         <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受-->       
  24.         <!--maximum-new-connections>150</maximum-new-connections-->     
  25.     <simultaneous-build-throttle>5</simultaneous-build-throttle>  
  26.         <!-- 最少保持的空闲连接数-->       
  27.         <prototype-count>3</prototype-count>     
  28.         <!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->       
  29.         <maximum-connection-count>100</maximum-connection-count>     
  30.         <!-- 最小连接数-->     
  31.         <minimum-connection-count>3</minimum-connection-count>     
  32.     </proxool>  
  33.   
  34. </something-else-entirely>  

 

 

proxool.properties配置文件:

Properties代码   收藏代码
  1. jdbc-0.proxool.alias=property-test  
  2. jdbc-0.encrypt=cn.bq.tools.DecUtil  
  3. jdbc-0.proxool.driver-url=jdbc:sqlserver://127.0.0.1:1433;databaseName=xxxx  
  4. jdbc-0.proxool.driver-class=com.microsoft.jdbc.sqlserver.SQLServerDriver  
  5. jdbc-0.user=da33e8657877280c32683ae317ef78e1  
  6. jdbc-0.password=3defde98af47835a74537600eebe78f2  
  7. jdbc-0.proxool.house-keeping-sleep-time=40000  
  8. jdbc-0.proxool.house-keeping-test-sql=select getdate()  
  9. jdbc-0.proxool.maximum-connection-count=10  
  10. jdbc-0.proxool.minimum-connection-count=3  
  11. jdbc-0.proxool.maximum-connection-lifetime=18000000  
  12. jdbc-0.proxool.simultaneous-build-throttle=5  
  13. jdbc-0.proxool.recently-started-threshold=40000  
  14. jdbc-0.proxool.overload-without-refusal-lifetime=50000  
  15. jdbc-0.proxool.maximum-active-time=60000  
  16. jdbc-0.proxool.verbose=true  
  17. jdbc-0.proxool.trace=true  
  18. jdbc-0.proxool.fatal-sql-exception=Fatal error  
  19. jdbc-0.proxool.prototype-count=2  

 

 下面是修改的类:

ProxoolConstants.java

Java代码   收藏代码
  1. /* 
  2.  * This software is released under a licence similar to the Apache Software Licence. 
  3.  * See org.logicalcobwebs.proxool.package.html for details. 
  4.  * The latest version is available at http://proxool.sourceforge.net 
  5.  */  
  6. package org.logicalcobwebs.proxool;  
  7.   
  8. /** 
  9.  * All constants here please. 
  10.  * 
  11.  * @version $Revision: 1.21 $, $Date: 2004/06/02 20:39:17 $ 
  12.  * @author billhorsman 
  13.  * @author $Author: billhorsman $ (current maintainer) 
  14.  */  
  15. public interface ProxoolConstants {  
  16.   
  17.     public final String PROXOOL = "proxool";  
  18.   
  19.     /** 
  20.      * The namespace uri associated with namepace aware Proxool xml configurations.<br> 
  21.      * Value: The latest version is available at http://proxool.sourceforge.net/xml-namespace 
  22.      */  
  23.     public final String PROXOOL_XML_NAMESPACE_URI = "The latest version is available at http://proxool.sourceforge.net/xml-namespace";  
  24.   
  25.     public final String ALIAS_DELIMITER = ".";  
  26.   
  27.     public final String PROPERTY_PREFIX = PROXOOL + ".";  
  28.   
  29.     public final String URL_DELIMITER = ":";  
  30.       
  31.     /** 用户名和密码是否加密,对应值为解密的class*/  
  32.     public final String USER_PASSWORD_ENCRYPT = "encrypt";  
  33.   
  34.     /** Standard JDBC property */  
  35.     public final String USER_PROPERTY = "user";  
  36.   
  37.     /** Standard JDBC property */  
  38.     public final String PASSWORD_PROPERTY = "password";  
  39.   
  40.     /** Used to build up URL */  
  41.     public final String ALIAS_PROPERTY = PROPERTY_PREFIX + "alias";  
  42.   
  43.     /** Instead of defining the driver in the url you can also use this property */  
  44.     public final String DELEGATE_DRIVER = "driver";  
  45.   
  46.     /** @see ProxoolDriver#getPropertyInfo */  
  47.      public final String DELEGATE_DRIVER_PROPERTY = PROPERTY_PREFIX + DELEGATE_DRIVER;  
  48.   
  49.     /** @see #HOUSE_KEEPING_SLEEP_TIME_PROPERTY */  
  50.     public final String DELEGATE_URL = "url";  
  51.   
  52.     /** @see ProxoolDriver#getPropertyInfo */  
  53.      public final String DELEGATE_URL_PROPERTY = PROPERTY_PREFIX + DELEGATE_URL;  
  54.   
  55.     /** @see #HOUSE_KEEPING_SLEEP_TIME_PROPERTY */  
  56.     public final String HOUSE_KEEPING_SLEEP_TIME = "house-keeping-sleep-time";  
  57.   
  58.     /** @see ProxoolDriver#getPropertyInfo */  
  59.      public final String HOUSE_KEEPING_SLEEP_TIME_PROPERTY = PROPERTY_PREFIX + HOUSE_KEEPING_SLEEP_TIME;  
  60.   
  61.     /** @see #HOUSE_KEEPING_TEST_SQL_PROPERTY */  
  62.     public final String HOUSE_KEEPING_TEST_SQL = "house-keeping-test-sql";  
  63.   
  64.     /** @see ProxoolDriver#getPropertyInfo */  
  65.     public final String HOUSE_KEEPING_TEST_SQL_PROPERTY = PROPERTY_PREFIX + HOUSE_KEEPING_TEST_SQL;  
  66.   
  67.     /** @see #TEST_BEFORE_USE_PROPERTY */  
  68.     public final String TEST_BEFORE_USE = "test-before-use";  
  69.   
  70.     /** @see ProxoolDriver#getPropertyInfo */  
  71.     public final String TEST_BEFORE_USE_PROPERTY = PROPERTY_PREFIX + TEST_BEFORE_USE;  
  72.   
  73.     /** @see #TEST_AFTER_USE_PROPERTY */  
  74.     public final String TEST_AFTER_USE = "test-after-use";  
  75.   
  76.     /** @see ProxoolDriver#getPropertyInfo */  
  77.     public final String TEST_AFTER_USE_PROPERTY = PROPERTY_PREFIX + TEST_AFTER_USE;  
  78.   
  79.     /** @see #MAXIMUM_CONNECTION_COUNT_PROPERTY */  
  80.     public final String MAXIMUM_CONNECTION_COUNT = "maximum-connection-count";  
  81.   
  82.     /** @see ProxoolDriver#getPropertyInfo */  
  83.     public final String MAXIMUM_CONNECTION_COUNT_PROPERTY = PROPERTY_PREFIX + MAXIMUM_CONNECTION_COUNT;  
  84.   
  85.     /** @see #MAXIMUM_CONNECTION_LIFETIME_PROPERTY */  
  86.     public final String MAXIMUM_CONNECTION_LIFETIME = "maximum-connection-lifetime";  
  87.   
  88.     /** @see ProxoolDriver#getPropertyInfo */  
  89.     public final String MAXIMUM_CONNECTION_LIFETIME_PROPERTY = PROPERTY_PREFIX + MAXIMUM_CONNECTION_LIFETIME;  
  90.   
  91.     /** 
  92.      * @deprecated use {@link #SIMULTANEOUS_BUILD_THROTTLE} instead 
  93.      */  
  94.     public final String MAXIMUM_NEW_CONNECTIONS = "maximum-new-connections";  
  95.   
  96.     /** 
  97.      * @deprecated use {@link #SIMULTANEOUS_BUILD_THROTTLE_PROPERTY} instead 
  98.      */  
  99.     public final String MAXIMUM_NEW_CONNECTIONS_PROPERTY = PROPERTY_PREFIX + MAXIMUM_NEW_CONNECTIONS;  
  100.   
  101.     /** @see #SIMULTANEOUS_BUILD_THROTTLE_PROPERTY*/  
  102.     public final String SIMULTANEOUS_BUILD_THROTTLE = "simultaneous-build-throttle";  
  103.   
  104.     /** @see ProxoolDriver#getPropertyInfo */  
  105.     public final String SIMULTANEOUS_BUILD_THROTTLE_PROPERTY = PROPERTY_PREFIX + SIMULTANEOUS_BUILD_THROTTLE;  
  106.   
  107.     /** @see #MINIMUM_CONNECTION_COUNT_PROPERTY */  
  108.     public final String MINIMUM_CONNECTION_COUNT = "minimum-connection-count";  
  109.   
  110.     /** @see ProxoolDriver#getPropertyInfo */  
  111.     public final String MINIMUM_CONNECTION_COUNT_PROPERTY = PROPERTY_PREFIX + MINIMUM_CONNECTION_COUNT;  
  112.   
  113.     /** @see #PROTOTYPE_COUNT_PROPERTY */  
  114.     public final String PROTOTYPE_COUNT = "prototype-count";  
  115.   
  116.     /** @see ProxoolDriver#getPropertyInfo */  
  117.     public final String PROTOTYPE_COUNT_PROPERTY = PROPERTY_PREFIX + PROTOTYPE_COUNT;  
  118.   
  119.     /** @see #RECENTLY_STARTED_THRESHOLD_PROPERTY */  
  120.     public final String RECENTLY_STARTED_THRESHOLD = "recently-started-threshold";  
  121.   
  122.     /** @see ProxoolDriver#getPropertyInfo */  
  123.     public final String RECENTLY_STARTED_THRESHOLD_PROPERTY = PROPERTY_PREFIX + RECENTLY_STARTED_THRESHOLD;  
  124.   
  125.     /** @see #OVERLOAD_WITHOUT_REFUSAL_LIFETIME_PROPERTY */  
  126.     public final String OVERLOAD_WITHOUT_REFUSAL_LIFETIME = "overload-without-refusal-lifetime";  
  127.   
  128.     /** @see ProxoolDriver#getPropertyInfo */  
  129.     public final String OVERLOAD_WITHOUT_REFUSAL_LIFETIME_PROPERTY = PROPERTY_PREFIX + OVERLOAD_WITHOUT_REFUSAL_LIFETIME;  
  130.   
  131.     /** @see #MAXIMUM_ACTIVE_TIME_PROPERTY */  
  132.     public final String MAXIMUM_ACTIVE_TIME = "maximum-active-time";  
  133.   
  134.     /** @see ProxoolDriver#getPropertyInfo */  
  135.     public final String MAXIMUM_ACTIVE_TIME_PROPERTY = PROPERTY_PREFIX + MAXIMUM_ACTIVE_TIME;  
  136.   
  137.     /** @see #INJECTABLE_CONNECTION_INTERFACE_NAME_PROPERTY */  
  138.     public final String INJECTABLE_CONNECTION_INTERFACE_NAME = "injectable-connection-interface";  
  139.   
  140.     /** @see ProxoolDriver#getPropertyInfo */  
  141.     public final String INJECTABLE_CONNECTION_INTERFACE_NAME_PROPERTY = PROPERTY_PREFIX + INJECTABLE_CONNECTION_INTERFACE_NAME;  
  142.   
  143.     /** @see #INJECTABLE_STATEMENT_INTERFACE_NAME_PROPERTY */  
  144.     public final String INJECTABLE_STATEMENT_INTERFACE_NAME = "injectable-statement-interface";  
  145.   
  146.     /** @see ProxoolDriver#getPropertyInfo */  
  147.     public final String INJECTABLE_STATEMENT_INTERFACE_NAME_PROPERTY = PROPERTY_PREFIX + INJECTABLE_STATEMENT_INTERFACE_NAME;  
  148.   
  149.     /** @see #INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME_PROPERTY */  
  150.     public final String INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME = "injectable-prepared-statement-interface";  
  151.   
  152.     /** @see ProxoolDriver#getPropertyInfo */  
  153.     public final String INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME_PROPERTY = PROPERTY_PREFIX + INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME;  
  154.   
  155.     /** @see #INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME_PROPERTY */  
  156.     public final String INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME = "injectable-callable-statement-interface";  
  157.   
  158.     /** @see ProxoolDriver#getPropertyInfo */  
  159.     public final String INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME_PROPERTY = PROPERTY_PREFIX + INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME;  
  160.   
  161.     /** 
  162.      * @deprecated use {@link #VERBOSE_PROPERTY verbose} instead. 
  163.      */  
  164.     public final String DEBUG_LEVEL_PROPERTY = PROPERTY_PREFIX + "debug-level";  
  165.   
  166.     /** @see #VERBOSE_PROPERTY */  
  167.     public final String VERBOSE = "verbose";  
  168.   
  169.     /** @see ProxoolDriver#getPropertyInfo */  
  170.     public final String VERBOSE_PROPERTY = PROPERTY_PREFIX + VERBOSE;  
  171.   
  172.     /** @see #TRACE_PROPERTY */  
  173.     public final String TRACE = "trace";  
  174.   
  175.     /** @see ProxoolDriver#getPropertyInfo */  
  176.     public final String TRACE_PROPERTY = PROPERTY_PREFIX + TRACE;  
  177.   
  178.     /** @see #FATAL_SQL_EXCEPTION_PROPERTY **/  
  179.     public final String FATAL_SQL_EXCEPTION = "fatal-sql-exception";  
  180.   
  181.     /** @see ProxoolDriver#getPropertyInfo */  
  182.     public final String FATAL_SQL_EXCEPTION_PROPERTY = PROPERTY_PREFIX + FATAL_SQL_EXCEPTION;  
  183.   
  184.     /** @see #FATAL_SQL_EXCEPTION_WRAPPER_CLASS_PROPERTY**/  
  185.     public final String FATAL_SQL_EXCEPTION_WRAPPER_CLASS = "fatal-sql-exception-wrapper-class";  
  186.   
  187.     /** @see ProxoolDriver#getPropertyInfo */  
  188.     public final String FATAL_SQL_EXCEPTION_WRAPPER_CLASS_PROPERTY = PROPERTY_PREFIX + FATAL_SQL_EXCEPTION_WRAPPER_CLASS;  
  189.   
  190.     public static final String STATISTICS = "statistics";  
  191.   
  192.     /** @see ProxoolDriver#getPropertyInfo */  
  193.     public final String STATISTICS_PROPERTY = PROPERTY_PREFIX + STATISTICS;  
  194.   
  195.     public static final String STATISTICS_LOG_LEVEL = "statistics-log-level";  
  196.   
  197.     /** @see ProxoolDriver#getPropertyInfo */  
  198.     public final String STATISTICS_LOG_LEVEL_PROPERTY = PROPERTY_PREFIX + STATISTICS_LOG_LEVEL;  
  199.   
  200.     public static final String JNDI_NAME = "jndi-name";  
  201.       
  202.     /** Prefix for generic JNDI properties. */  
  203.     public static final String JNDI_PROPERTY_PREFIX = "jndi-";  
  204.   
  205.     /** @see ProxoolDriver#getPropertyInfo */  
  206.     public final String JNDI_NAME_PROPERTY = PROPERTY_PREFIX + JNDI_NAME;  
  207.   
  208. // End JNDI  
  209.   
  210.     public static final String STATISTICS_LOG_LEVEL_TRACE = "TRACE";  
  211.   
  212.     public static final String STATISTICS_LOG_LEVEL_DEBUG = "DEBUG";  
  213.   
  214.     public static final String STATISTICS_LOG_LEVEL_INFO = "INFO";  
  215.   
  216.     /** 
  217.      * Element name for the container of properties passed directlry to the delegate driver. 
  218.      */  
  219.     public static final String DRIVER_PROPERTIES = "driver-properties";  
  220.   
  221.   
  222.     /** 
  223.      * Configuration attribute used to indicate that a pool should be registered with JMX. 
  224.      */  
  225.     public static final String JMX = "jmx";  
  226.   
  227.     /** 
  228.      * "proxool." prefixed version of {@link #JMX}. 
  229.      */  
  230.     public final String JMX_PROPERTY = PROPERTY_PREFIX + JMX;  
  231.   
  232.     /** 
  233.      * Configuration attribute for a list of jmx agent ids to register a 
  234.      * {@link org.logicalcobwebs.proxool.admin.jmx.ConnectionPoolMBean} to. 
  235.      * The list is comma separated. 
  236.      */  
  237.     public static final String JMX_AGENT_ID = "jmx-agent-id";  
  238.   
  239.     /** 
  240.      * "proxool." prefixed version of {@link #JMX_AGENT_ID}. 
  241.      */  
  242.     public final String JMX_AGENT_PROPERTY = PROPERTY_PREFIX + JMX_AGENT_ID;  
  243.   
  244.     /** 
  245.      *  Un-prefixed propety name for the Proxool alias configuration property. Value: alias 
  246.      */  
  247.     public final String ALIAS = "alias";  
  248.   
  249.     /** 
  250.      *  Un-prefixed propety name for the Proxool driver class  configuration property. Value: driver-class 
  251.      */  
  252.     public final String DRIVER_CLASS = "driver-class";  
  253.     /** 
  254.      *  Prefixed propety name for the Proxool driver class  configuration property. Value: proxool.driver-class 
  255.      */  
  256.     public final String DRIVER_CLASS_PROPERTY = PROPERTY_PREFIX + DRIVER_CLASS;;  
  257.     /** 
  258.      *  Un-prefixed propety name for the Proxool driver url configuration property. Value: driver-url 
  259.      */  
  260.     public final String DRIVER_URL = "driver-url";  
  261.     /** 
  262.      *  Prefixed propety name for the Proxool driver url configuration property. Value: proxool.driver-url 
  263.      */  
  264.     public final String DRIVER_URL_PROPERTY = PROPERTY_PREFIX + DRIVER_URL;  
  265. }  
  266.   
  267. /* 
  268.  Revision history: 
  269.  $Log: ProxoolConstants.java,v $ 
  270.  Revision 1.21  2004/06/02 20:39:17  billhorsman 
  271.  New injectable interface constants 
  272.  
  273.  Revision 1.20  2004/03/15 02:43:47  chr32 
  274.  Removed explicit JNDI properties. Going for a generic approach instead. 
  275.  Added constant for JNDI properties prefix. 
  276.  
  277.  Revision 1.19  2003/09/30 18:39:08  billhorsman 
  278.  New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. 
  279.  
  280.  Revision 1.18  2003/09/29 17:48:21  billhorsman 
  281.  New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you 
  282.  can make it a RuntimeException if you need to. 
  283.  
  284.  Revision 1.17  2003/09/05 17:00:42  billhorsman 
  285.  New wrap-fatal-sql-exceptions property. 
  286.  
  287.  Revision 1.16  2003/07/23 06:54:48  billhorsman 
  288.  draft JNDI changes (shouldn't effect normal operation) 
  289.  
  290.  Revision 1.15  2003/03/05 23:28:56  billhorsman 
  291.  deprecated maximum-new-connections property in favour of 
  292.  more descriptive simultaneous-build-throttle 
  293.  
  294.  Revision 1.14  2003/03/03 11:11:58  billhorsman 
  295.  fixed licence 
  296.  
  297.  Revision 1.13  2003/02/26 16:05:52  billhorsman 
  298.  widespread changes caused by refactoring the way we 
  299.  update and redefine pool definitions. 
  300.  
  301.  Revision 1.12  2003/02/24 18:02:24  chr32 
  302.  Added JMX related constants. 
  303.  
  304.  Revision 1.11  2003/02/24 01:16:15  chr32 
  305.  Added constant for "driver-properties" property. 
  306.  
  307.  Revision 1.10  2003/02/06 15:41:17  billhorsman 
  308.  add statistics-log-level 
  309.  
  310.  Revision 1.9  2003/01/30 17:22:03  billhorsman 
  311.  new statistics property 
  312.  
  313.  Revision 1.8  2003/01/23 10:41:05  billhorsman 
  314.  changed use of pool-name to alias for consistency 
  315.  
  316.  Revision 1.7  2002/12/26 11:32:22  billhorsman 
  317.  Moved ALIAS, DRIVER_URL and DRIVER_CLASS constants 
  318.  from XMLConfgiurator to ProxoolConstants. 
  319.  
  320.  Revision 1.6  2002/12/15 19:22:51  chr32 
  321.  Added constant for proxool xml namespace. 
  322.  
  323.  Revision 1.5  2002/12/11 01:47:12  billhorsman 
  324.  extracted property names without proxool. prefix for use 
  325.  by XMLConfigurators. 
  326.  
  327.  Revision 1.4  2002/11/09 15:50:49  billhorsman 
  328.  new trace constant 
  329.  
  330.  Revision 1.3  2002/10/27 13:29:38  billhorsman 
  331.  deprecated debug-level in favour of verbose 
  332.  
  333.  Revision 1.2  2002/10/25 15:59:32  billhorsman 
  334.  made non-public where possible 
  335.  
  336.  Revision 1.1.1.1  2002/09/13 08:13:06  billhorsman 
  337.  new 
  338.  
  339.  Revision 1.3  2002/08/24 19:57:15  billhorsman 
  340.  checkstyle changes 
  341.  
  342.  Revision 1.2  2002/07/12 23:03:22  billhorsman 
  343.  added doc headers 
  344.  
  345.  Revision 1.7  2002/07/10 16:14:47  billhorsman 
  346.  widespread layout changes and move constants into ProxoolConstants 
  347.  
  348.  Revision 1.6  2002/07/02 11:19:08  billhorsman 
  349.  layout code and imports 
  350.  
  351.  Revision 1.5  2002/07/02 08:27:47  billhorsman 
  352.  bug fix when settiong definition, displayStatistics now available to ProxoolFacade, prototyper no longer attempts to make connections when maximum is reached 
  353.  
  354.  Revision 1.4  2002/06/28 11:19:47  billhorsman 
  355.  improved doc 
  356.  
  357. */  

 

 

解密接口类Decryptool.java

Java代码   收藏代码
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5. package org.logicalcobwebs.proxool.util;  
  6.   
  7. /** 
  8.  * 
  9.  * @author zhappy 
  10.  */  
  11. public interface Decryptool {  
  12.   
  13.     /** 
  14.      * 解密字符串 
  15.      * @param content 密文 
  16.      * @return 明文 
  17.      */  
  18.     public String decrypt(String content);  
  19.       
  20. }  

 

 

 

PropertyConfigurator.java

Java代码   收藏代码
  1. /* 
  2.  * This software is released under a licence similar to the Apache Software Licence. 
  3.  * See org.logicalcobwebs.proxool.package.html for details. 
  4.  * The latest version is available at http://proxool.sourceforge.net 
  5.  */  
  6. package org.logicalcobwebs.proxool.configuration;  
  7.   
  8. import java.io.FileInputStream;  
  9. import java.io.IOException;  
  10. import java.util.HashMap;  
  11. import java.util.Iterator;  
  12. import java.util.Map;  
  13. import java.util.Properties;  
  14. import org.apache.commons.logging.Log;  
  15. import org.apache.commons.logging.LogFactory;  
  16. import org.logicalcobwebs.proxool.ProxoolConstants;  
  17. import org.logicalcobwebs.proxool.ProxoolException;  
  18. import org.logicalcobwebs.proxool.ProxoolFacade;  
  19. import org.logicalcobwebs.proxool.util.Decryptool;  
  20.   
  21. /** 
  22.  * Uses a standard Java properties file to configure Proxool. For example: 
  23.  * 
  24.  * <pre> 
  25.  * jdbc-0.proxool.alias=property-test 
  26.  * jdbc-0.proxool.driver-url=jdbc:hsqldb:. 
  27.  * jdbc-0.proxool.driver-class=org.hsqldb.jdbcDriver 
  28.  * jdbc-0.encrypt=org.logicalcobwebs.proxool.util.Decryptool 
  29.  * jdbc-0.user=foo 
  30.  * jdbc-0.password=bar 
  31.  * jdbc-0.proxool.house-keeping-sleep-time=40000 
  32.  * jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE 
  33.  * jdbc-0.proxool.maximum-connection-count=10 
  34.  * jdbc-0.proxool.minimum-connection-count=3 
  35.  * jdbc-0.proxool.maximum-connection-lifetime=18000000 
  36.  * jdbc-0.proxool.simultaneous-build-throttle=5 
  37.  * jdbc-0.proxool.recently-started-threshold=40000 
  38.  * jdbc-0.proxool.overload-without-refusal-lifetime=50000 
  39.  * jdbc-0.proxool.maximum-active-time=60000 
  40.  * jdbc-0.proxool.verbose=true 
  41.  * jdbc-0.proxool.trace=true 
  42.  * jdbc-0.proxool.fatal-sql-exception=Fatal error 
  43.  * jdbc-0.proxool.prototype-count=2 
  44.  * 
  45.  * jdbc-1.proxool.alias=property-test-2 
  46.  * jdbc-1.proxool.driver-url=jdbc:hsqldb:. 
  47.  * jdbc-1.proxool.driver-class=org.hsqldb.jdbcDriver 
  48.  * jdbc-1.user=scott 
  49.  * jdbc-1.password=tiger 
  50.  * jdbc-1.proxool.house-keeping-sleep-time=40000 
  51.  * jdbc-1.proxool.house-keeping-test-sql=select CURRENT_DATE 
  52.  * jdbc-1.proxool.maximum-connection-count=10 
  53.  * jdbc-1.proxool.minimum-connection-count=3 
  54.  * jdbc-1.proxool.maximum-connection-lifetime=18000000 
  55.  * jdbc-1.proxool.simultaneous-build-throttle=5 
  56.  * jdbc-1.proxool.recently-started-threshold=40000 
  57.  * jdbc-1.proxool.overload-without-refusal-lifetime=50000 
  58.  * jdbc-1.proxool.maximum-active-time=60000 
  59.  * jdbc-1.proxool.verbose=true 
  60.  * jdbc-1.proxool.trace=true 
  61.  * jdbc-1.proxool.fatal-sql-exception=Fatal error 
  62.  * jdbc-1.proxool.prototype-count=2 
  63.  * </pre> 
  64.  * 
  65.  * <p>The first word (up to the first dot) must start with "jdbc", but it can be 
  66.  * anything you like. Use unique names to identify each pool. Any property not 
  67.  * starting with "jdbc" will be ignored.</p> <p> The properties prefixed with 
  68.  * "proxool." will be used by Proxool while the properties that are not prefixed 
  69.  * will be passed on to the delegate JDBC driver. </p> 
  70.  * 
  71.  * @version $Revision: 1.11 $, $Date: 2006/01/18 14:39:58 $ 
  72.  * @author Bill Horsman (bill@logicalcobwebs.co.uk) 
  73.  * @author $Author: billhorsman $ (current maintainer) 
  74.  * @since Proxool 0.5 
  75.  */  
  76. public class PropertyConfigurator {  
  77.   
  78.     private static final Log LOG = LogFactory.getLog(PropertyConfigurator.class);  
  79.     protected static final String PREFIX = "jdbc";  
  80.     private static final String DOT = ".";  
  81.     private static final String EXAMPLE_FORMAT = PREFIX + "*" + DOT + "*";  
  82.   
  83.     /** 
  84.      * Configure proxool with the given properties file. 
  85.      * 
  86.      * @param filename the filename of the properties file. 
  87.      * @throws ProxoolException if the configuration fails. 
  88.      */  
  89.     public static void configure(String filename) throws ProxoolException {  
  90.         Properties properties = new Properties();  
  91.         try {  
  92.             properties.load(new FileInputStream(filename));  
  93.         } catch (IOException e) {  
  94.             throw new ProxoolException("Couldn't load property file " + filename);  
  95.         }  
  96.         configure(properties);  
  97.     }  
  98.   
  99.     /** 
  100.      * Configure proxool with the given properties. 
  101.      * 
  102.      * @param properties the properties instance to use. 
  103.      * @throws ProxoolException if the configuration fails. 
  104.      */  
  105.     public static void configure(Properties properties) throws ProxoolException {  
  106.         final Map propertiesMap = new HashMap();  
  107.         final Iterator allPropertyKeysIterator = properties.keySet().iterator();  
  108.         Properties proxoolProperties = null;  
  109.   
  110.         while (allPropertyKeysIterator.hasNext()) {  
  111.             String key = (String) allPropertyKeysIterator.next();  
  112.             String value = properties.getProperty(key);  
  113.   
  114.             if (key.startsWith(PREFIX)) {  
  115.                 int a = key.indexOf(DOT);  
  116.                 if (a == -1) {  
  117.                     throw new ProxoolException("Property " + key + " must be of the format " + EXAMPLE_FORMAT);  
  118.                 }  
  119.                 final String tag = key.substring(0, a);  
  120.                 final String name = key.substring(a + 1);  
  121.                 proxoolProperties = (Properties) propertiesMap.get(tag);  
  122.                 if (proxoolProperties == null) {  
  123.                     proxoolProperties = new Properties();  
  124.                     propertiesMap.put(tag, proxoolProperties);  
  125.                 }  
  126.                 proxoolProperties.put(name, value);  
  127.             }  
  128.         }  
  129.   
  130.         final Iterator tags = propertiesMap.keySet().iterator();  
  131.         while (tags.hasNext()) {  
  132.             proxoolProperties = (Properties) propertiesMap.get(tags.next());  
  133.   
  134.             final String ec = proxoolProperties.getProperty(ProxoolConstants.USER_PASSWORD_ENCRYPT);  
  135.             if (ec != null) {//如果在配置文件中存在解密项就先动态加载解密类,然后对用户名和密码进行解密  
  136.                 Decryptool dec = null;  
  137.                 try {  
  138.                     Class c = Class.forName(ec);  
  139.                     Object o = c.newInstance();  
  140.                     dec = (Decryptool) o;  
  141.                 } catch (Exception e) {  
  142.                     LOG.error("new Class [" + ec + "] fail!", e);  
  143.                 }  
  144.                 final String user = proxoolProperties.getProperty(ProxoolConstants.USER_PROPERTY);//取原值  
  145.                 proxoolProperties.setProperty(ProxoolConstants.USER_PROPERTY, dec.decrypt(user));//解密并设置  
  146.                 final String password = proxoolProperties.getProperty(ProxoolConstants.PASSWORD_PROPERTY);//取原值  
  147.                 proxoolProperties.setProperty(ProxoolConstants.PASSWORD_PROPERTY, dec.decrypt(password));//解密并设置  
  148.             }  
  149.             // make sure that required propeties are defined  
  150.             // and build the url  
  151.             // Check that we have defined the minimum information  
  152.             final String driverClass = proxoolProperties.getProperty(ProxoolConstants.DRIVER_CLASS_PROPERTY);  
  153.             final String driverUrl = proxoolProperties.getProperty(ProxoolConstants.DRIVER_URL_PROPERTY);  
  154.             if (driverClass == null || driverUrl == null) {  
  155.                 throw new ProxoolException("You must define the " + ProxoolConstants.DRIVER_CLASS_PROPERTY + " and the "  
  156.                         + ProxoolConstants.DRIVER_URL_PROPERTY + ".");  
  157.             }  
  158.             final String alias = proxoolProperties.getProperty(ProxoolConstants.ALIAS_PROPERTY);  
  159.   
  160.             // Build the URL; optionally defining a name  
  161.             StringBuffer url = new StringBuffer();  
  162.             url.append("proxool");  
  163.             if (alias != null) {  
  164.                 url.append(ProxoolConstants.ALIAS_DELIMITER);  
  165.                 url.append(alias);  
  166.                 proxoolProperties.remove(ProxoolConstants.ALIAS_PROPERTY);  
  167.             }  
  168.             url.append(ProxoolConstants.URL_DELIMITER);  
  169.             url.append(driverClass);  
  170.             proxoolProperties.remove(ProxoolConstants.DRIVER_CLASS_PROPERTY);  
  171.             url.append(ProxoolConstants.URL_DELIMITER);  
  172.             url.append(driverUrl);  
  173.             proxoolProperties.remove(ProxoolConstants.DRIVER_URL_PROPERTY);  
  174.             if (LOG.isDebugEnabled()) {  
  175.                 LOG.debug("Created url: " + url);  
  176.             }  
  177.   
  178.             ProxoolFacade.registerConnectionPool(url.toString(), proxoolProperties);  
  179.         }  
  180.     }  
  181. }  
  182.   
  183. /* 
  184.  * Revision history: $Log: PropertyConfigurator.java,v $ Revision 1.11 
  185.  * 2006/01/18 14:39:58 billhorsman Unbundled Jakarta's Commons Logging. 
  186.  * 
  187.  * Revision 1.10 2003/03/05 23:28:56 billhorsman deprecated 
  188.  * maximum-new-connections property in favour of more descriptive 
  189.  * simultaneous-build-throttle 
  190.  * 
  191.  * Revision 1.9 2003/03/03 11:12:00 billhorsman fixed licence 
  192.  * 
  193.  * Revision 1.8 2003/02/06 17:41:05 billhorsman now uses imported logging 
  194.  * 
  195.  * Revision 1.7 2003/02/05 14:46:31 billhorsman fixed copyright and made PREFIX 
  196.  * protected for use by ServletConfigurator 
  197.  * 
  198.  * Revision 1.6 2003/01/27 18:26:43 billhorsman refactoring of ProxyConnection 
  199.  * and ProxyStatement to make it easier to write JDK 1.2 patch 
  200.  * 
  201.  * Revision 1.5 2003/01/23 10:41:05 billhorsman changed use of pool-name to 
  202.  * alias for consistency 
  203.  * 
  204.  * Revision 1.4 2003/01/22 17:35:01 billhorsman checkstyle 
  205.  * 
  206.  * Revision 1.3 2003/01/18 15:13:12 billhorsman Signature changes (new 
  207.  * ProxoolException thrown) on the ProxoolFacade API. 
  208.  * 
  209.  * Revision 1.2 2002/12/26 11:32:59 billhorsman Rewrote to support new format. 
  210.  * 
  211.  * Revision 1.1 2002/12/15 18:48:33 chr32 Movied in from 'ext' source tree. 
  212.  * 
  213.  * Revision 1.4 2002/11/09 15:57:57 billhorsman fix doc 
  214.  * 
  215.  * Revision 1.3 2002/11/02 14:22:16 billhorsman Documentation 
  216.  * 
  217.  * Revision 1.2 2002/10/27 13:05:01 billhorsman checkstyle 
  218.  * 
  219.  * Revision 1.1 2002/10/27 12:00:16 billhorsman moved classes from ext 
  220.  * sub-package which is now obsolete - let's keep everything together in one 
  221.  * place 
  222.  * 
  223.  * Revision 1.1 2002/10/25 10:40:27 billhorsman draft 
  224.  * 
  225.  */  

 

 

 

XMLConfigurator.java

Java代码   收藏代码
  1. /* 
  2.  * This software is released under a licence similar to the Apache Software Licence. 
  3.  * See org.logicalcobwebs.proxool.package.html for details. 
  4.  * The latest version is available at http://proxool.sourceforge.net 
  5.  */  
  6. package org.logicalcobwebs.proxool.configuration;  
  7.   
  8. import java.util.Iterator;  
  9. import java.util.Properties;  
  10. import org.apache.commons.logging.Log;  
  11. import org.apache.commons.logging.LogFactory;  
  12. import org.logicalcobwebs.proxool.ProxoolConstants;  
  13. import org.logicalcobwebs.proxool.ProxoolException;  
  14. import org.logicalcobwebs.proxool.ProxoolFacade;  
  15. import org.logicalcobwebs.proxool.util.Decryptool;  
  16. import org.xml.sax.Attributes;  
  17. import org.xml.sax.SAXException;  
  18. import org.xml.sax.SAXParseException;  
  19. import org.xml.sax.helpers.DefaultHandler;  
  20.   
  21. /** 
  22.  * <p>A SAX 2 ContentHandler that can configure Proxool from an XML source.</p> 
  23.  * 
  24.  * <p>This is just a <a 
  25.  * href="http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html" 
  26.  * target="_new" >ContentHandler</a>, so you must associate it with a SAX parser 
  27.  * for it to actually do anything. If you have JAXP available {@link JAXPConfigurator} 
  28.  * will do this for you.</p> 
  29.  * 
  30.  * <p>Properties that you pass on to the delegate driver have to be treated 
  31.  * specially. They must be contained within a &lt;driver-properties&gt; 
  32.  * element.</p> 
  33.  * 
  34.  * <p>See the <a href="The latest version is available at 
  35.  * http://proxool.sourceforge.net/properties.html" target="_new">Proxool 
  36.  * properties</a> for documentation on the available configuration 
  37.  * properties.</p> 
  38.  * 
  39.  * Example configuration: 
  40.  * <pre> 
  41.  * &lt;proxool&gt; 
  42.  *     &lt;alias&gt;apple&lt;/alias&gt; 
  43.  *     &lt;encrypt&gt;org.logicalcobwebs.proxool.util.Decryptool&lt;/alias&gt; 
  44.  *     &lt;driver-url&gt;jdbc:hsqldb:.&lt;/driver-url&gt; 
  45.  *     &lt;driver-class&gt;org.hsqldb.jdbcDriver&lt;/driver-class&gt; 
  46.  *     &lt;driver-properties&gt; 
  47.  *         &lt;property name="user" value="abc" /&gt; 
  48.  *         &lt;property name="password" value="def" /&gt; 
  49.  *     &lt;/driver-properties&gt; 
  50.  *     &lt;house-keeping-sleep-time&gt;40000&lt;/house-keeping-sleep-time&gt; 
  51.  *     &lt;house-keeping-test-sql&gt;select CURRENT_DATE&lt;/house-keeping-test-sql&gt; 
  52.  *     &lt;maximum-connection-count&gt;10&lt;/maximum-connection-count&gt; 
  53.  *     &lt;minimum-connection-count&gt;3&lt;/minimum-connection-count&gt; 
  54.  *     &lt;maximum-connection-lifetime&gt;18000000&lt;/maximum-connection-lifetime&gt; &lt;!-- 5 hours --&gt; 
  55.  *     &lt;simultaneous-build-throttle&gt;5&lt;/simultaneous-build-throttle&gt; 
  56.  *     &lt;recently-started-threshold&gt;40000&lt;/recently-started-threshold&gt; 
  57.  *     &lt;overload-without-refusal-lifetime&gt;50000&lt;/overload-without-refusal-lifetime&gt; 
  58.  *     &lt;maximum-active-time&gt;60000&lt;/maximum-active-time&gt; 
  59.  *     &lt;verbose&gt;true&lt;/verbose&gt; 
  60.  *     &lt;trace&gt;true&lt;/trace&gt; 
  61.  *     &lt;fatal-sql-exception&gt;ORA-1234&lt;/fatal-sql-exception&gt; 
  62.  *     &lt;prototype-count&gt;2&lt;/prototype-count&gt; 
  63.  * &lt;/proxool&gt; 
  64.  * </pre> 
  65.  * 
  66.  * When the parser reaches the end of the &lt;proxool&gt; element the pool is 
  67.  * automatically registered. You can contain the &lt;proxool&gt; element in any 
  68.  * other elements as you wish. And the &lt;proxool&gt; element can occur as many 
  69.  * times as you wish. This allows you to use an XML file that configures your 
  70.  * whole application as the source. This configurator will ignore everything 
  71.  * apart from the elements contained within the &lt;proxool&gt; element. <p><a 
  72.  * name="#validation"> <b>Validation</b><br> A couple of additional steps are 
  73.  * required if you want your SAX parser to validate your Proxool xml 
  74.  * confguration: <ul> <li> Put your proxool configuration elements inside a root 
  75.  * <code>proxool-config</code> element. The document must adhere to the <a 
  76.  * href="proxool.dtd">Proxool dtd</a>. </li> <li> Add a 
  77.  * <code>DOCTYPE</code> entry to your xml with a system id containing the 
  78.  * <i>absolute url</i> to the Proxool dtd. The Proxool jar contains a copy of 
  79.  * the Proxool dtd in the confguration package. You can reference that with a 
  80.  * jar url like this:<br> 
  81.  * <code><nobr>&lt;!DOCTYPE proxool-config SYSTEM "jar:file:///C:/Proxool/lib/proxool.jar!/org/logicalcobwebs/proxool/configuration/proxool.dtd"&gt;</nobr></code></li> 
  82.  * <li> Configure your parser to be validating. In the {@link JAXPConfigurator} 
  83.  * this is done by passing 
  84.  * <code>true</code> as the second arghument to any of the 
  85.  * <code>configure</code> methods. </li> </ul> </p> <p>This class is not thread 
  86.  * safe.</p> 
  87.  * 
  88.  * @version $Revision: 1.18 $, $Date: 2006/01/18 14:39:58 $ 
  89.  * @author billhorsman 
  90.  * @author $Author: billhorsman $ (current maintainer) 
  91.  */  
  92. public class XMLConfigurator extends DefaultHandler {  
  93.   
  94.     private static final Log LOG = LogFactory.getLog(XMLConfigurator.class);  
  95.     private StringBuffer content = new StringBuffer();  
  96.     private String poolName;  
  97.     private String driverClass;  
  98.     private String driverUrl;  
  99.     private Properties properties = new Properties();  
  100.     private static final String PROXOOL = "proxool";  
  101.     private static final String DRIVER_PROPERTIES = "driver-properties";  
  102.     private static final String PROPERTY = "property";  
  103.     private static final String NAME = "name";  
  104.     private static final String VALUE = "value";  
  105.     private boolean insideDelegateProperties;  
  106.     private boolean insideProxool;  
  107.   
  108.     /** 
  109.      * @see org.xml.sax.ContentHandler#startElement 
  110.      */  
  111.     @Override  
  112.     public void startElement(String uri, String lname, String qname, Attributes attributes) throws SAXException {  
  113.         content.setLength(0);  
  114.   
  115.         if (!namespaceOk(uri)) {  
  116.             return;  
  117.         }  
  118.   
  119.         final String elementName = getElementName(uri, lname, qname);  
  120.   
  121.         if (elementName.equals(PROXOOL)) {  
  122.             if (insideProxool) {  
  123.                 throw new SAXException("A <" + PROXOOL + "> element can't contain another <" + PROXOOL + "> element.");  
  124.             }  
  125.             insideProxool = true;  
  126.             properties.clear();  
  127.             driverClass = null;  
  128.             driverUrl = null;  
  129.         }  
  130.   
  131.         if (insideProxool) {  
  132.             if (elementName.equals(DRIVER_PROPERTIES)) {  
  133.                 insideDelegateProperties = true;  
  134.             } else if (insideDelegateProperties) {  
  135.                 if (elementName.equals(PROPERTY)) {  
  136.                     setDriverProperty(attributes);  
  137.                 }  
  138.             }  
  139.         }  
  140.     }  
  141.   
  142.     /** 
  143.      * @see org.xml.sax.ContentHandler#characters 
  144.      */  
  145.     @Override  
  146.     public void characters(char[] chars, int start, int length) throws SAXException {  
  147.         if (insideProxool) {  
  148.             content.append(chars, start, length);  
  149.         }  
  150.     }  
  151.   
  152.     /** 
  153.      * @see org.xml.sax.ContentHandler#endElement 
  154.      */  
  155.     @Override  
  156.     public void endElement(String uri, String lname, String qname) throws SAXException {  
  157.         if (!namespaceOk(uri)) {  
  158.             return;  
  159.         }  
  160.   
  161.         final String elementName = getElementName(uri, lname, qname);  
  162.   
  163.         // Are we ending a proxool configuration section?  
  164.         if (elementName.equals(PROXOOL)) {  
  165.   
  166.             // Check that we have defined the minimum information  
  167.             if (driverClass == null || driverUrl == null) {  
  168.                 throw new SAXException("You must define the "   
  169.                         + ProxoolConstants.DRIVER_CLASS + " and the " + ProxoolConstants.DRIVER_URL + ".");  
  170.             }  
  171.   
  172.             // Build the URL; optinally defining a name  
  173.             StringBuffer url = new StringBuffer();  
  174.             url.append("proxool");  
  175.             if (poolName != null) {  
  176.                 url.append(ProxoolConstants.ALIAS_DELIMITER);  
  177.                 url.append(poolName);  
  178.             }  
  179.             url.append(ProxoolConstants.URL_DELIMITER);  
  180.             url.append(driverClass);  
  181.             url.append(ProxoolConstants.URL_DELIMITER);  
  182.             url.append(driverUrl);  
  183.             if (LOG.isDebugEnabled()) {  
  184.                 LOG.debug("Created url: " + url);  
  185.             }  
  186.   
  187.             // Register the pool  
  188.             try {  
  189.                 final String ec = properties.getProperty(ProxoolConstants.PROPERTY_PREFIX   
  190.                         + ProxoolConstants.USER_PASSWORD_ENCRYPT);  
  191.                 if (ec != null) {//判断配置文件中是否有解密class的配置,如果有则动态加载  
  192.                     Decryptool dec = null;  
  193.                     try {  
  194.                         Class c = Class.forName(ec);  
  195.                         Object o = c.newInstance();  
  196.                         dec = (Decryptool) o;  
  197.                     } catch (Exception e) {  
  198.                         LOG.error("new Class [" + ec + "] fail!", e);  
  199.                     }  
  200.                     final String user = properties.getProperty(ProxoolConstants.USER_PROPERTY);//取原值  
  201.                     properties.setProperty(ProxoolConstants.USER_PROPERTY, dec.decrypt(user));//解密并设置  
  202.                     final String password = properties.getProperty(ProxoolConstants.PASSWORD_PROPERTY);//取原值  
  203.                     properties.setProperty(ProxoolConstants.PASSWORD_PROPERTY, dec.decrypt(password));//解密并设置  
  204.                 }  
  205.                 ProxoolFacade.registerConnectionPool(url.toString(), properties);  
  206.             } catch (ProxoolException e) {  
  207.                 throw new SAXException(e);  
  208.             }  
  209.   
  210.             // This ensures we ignore remaining XML until we come across another  
  211.             // <proxool> element.  
  212.             insideProxool = false;  
  213.         }  
  214.   
  215.         if (insideProxool && !elementName.equals(PROXOOL)) {  
  216.             if (elementName.equals(DRIVER_PROPERTIES)) {  
  217.                 insideDelegateProperties = false;  
  218.             } else if (!insideDelegateProperties) {  
  219.                 setProxoolProperty(elementName, content.toString().trim());  
  220.             }  
  221.         }  
  222.     }  
  223.   
  224.     private void setProxoolProperty(String localName, String value) {  
  225.         if (localName.equals(ProxoolConstants.ALIAS)) {  
  226.             poolName = value;  
  227.         } else if (localName.equals(ProxoolConstants.DRIVER_CLASS)) {  
  228.             driverClass = value;  
  229.         } else if (localName.equals(ProxoolConstants.DRIVER_URL)) {  
  230.             driverUrl = value;  
  231.         } else {  
  232.             if (LOG.isDebugEnabled()) {  
  233.                 LOG.debug("Setting property '" + ProxoolConstants.PROPERTY_PREFIX + localName + "' to value '" + value + "'.");  
  234.             }  
  235.             properties.put(ProxoolConstants.PROPERTY_PREFIX + localName, value);  
  236.         }  
  237.     }  
  238.   
  239.     private void setDriverProperty(Attributes attributes) throws SAXException {  
  240.         final String name = attributes.getValue(NAME);  
  241.         final String value = attributes.getValue(VALUE);  
  242.         if (name == null || name.length() < 1 || value == null) {  
  243.             throw new SAXException("Name or value attribute missing from property element."  
  244.                     + "Name: '" + name + "' Value: '" + value + "'.");  
  245.         }  
  246.         if (LOG.isDebugEnabled()) {  
  247.             if (name.toLowerCase().indexOf("password") > -1) {  
  248.                 LOG.debug("Adding driver property: " + name + "=" + "*******");  
  249.             } else {  
  250.                 LOG.debug("Adding driver property: " + name + "=" + value);  
  251.             }  
  252.         }  
  253.         properties.put(name, value);  
  254.     }  
  255.   
  256.     /** 
  257.      * @see org.xml.sax.ErrorHandler#warning(SAXParseException) 
  258.      */  
  259.     @Override  
  260.     public void warning(SAXParseException e) throws SAXException {  
  261.         // Just debug-log the warning. We'll probably survive.  
  262.         LOG.debug("The saxparser reported a warning.", e);  
  263.     }  
  264.   
  265.     /** 
  266.      * @see org.xml.sax.ErrorHandler#error(SAXParseException) 
  267.      */  
  268.     @Override  
  269.     public void error(SAXParseException e) throws SAXException {  
  270.         // On error we rethrow the exception.  
  271.         // This should cause the parser stop and an exeption be thrown back to the client.  
  272.         throw e;  
  273.     }  
  274.   
  275.     /** 
  276.      * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException) 
  277.      */  
  278.     @Override  
  279.     public void fatalError(SAXParseException e) throws SAXException {  
  280.         // On fatal error we rethrow the exception.  
  281.         // This should cause the parser stop and an exeption be thrown back to the client.  
  282.         throw e;  
  283.     }  
  284.   
  285.     // If no namespace use qname, else use lname.  
  286.     private String getElementName(String uri, String lname, String qname) {  
  287.         if (uri == null || "".equals(uri)) {  
  288.             return qname;  
  289.         } else {  
  290.             return lname;  
  291.         }  
  292.     }  
  293.   
  294.     private boolean namespaceOk(String uri) {  
  295.         return uri == null || uri.length() == 0 || uri.equals(ProxoolConstants.PROXOOL_XML_NAMESPACE_URI);  
  296.     }  
  297. }  

 

 

把上面这几个类编译后,添加、替换原包中的类就可以了。使用上跟原来没有区别。

注意:如果配置使用了解密,就必须先实现接口Decryptool,并在配置文件中设置正确的类路径

接口Decryptool的简单实现:

DecUtil.java

Java代码   收藏代码
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5. package cn.bq.tools;  
  6.   
  7. import java.io.IOException;  
  8. import java.util.logging.Level;  
  9. import java.util.logging.Logger;  
  10. import org.logicalcobwebs.proxool.util.Decryptool;  
  11. import sun.misc.BASE64Decoder;  
  12. import sun.misc.BASE64Encoder;  
  13.   
  14. /** 
  15.  * 
  16.  * @author zhappy 
  17.  */  
  18. public class DecUtil implements Decryptool {  
  19.   
  20.     @Override  
  21.     public String decrypt(String string) {  
  22.         BASE64Decoder decode = new BASE64Decoder();  
  23.         String s = null;  
  24.         try {  
  25.             byte[] b = decode.decodeBuffer(string);  
  26.             s = new String(b);  
  27.         } catch (IOException ex) {  
  28.             Logger.getLogger(DecUtil.class.getName()).log(Level.SEVERE, null, ex);  
  29.         }  
  30.         return s;  
  31.     }  
  32.   
  33.       
  34.     public String encrypt(String string) {  
  35.         BASE64Encoder encode = new BASE64Encoder();  
  36.         return encode.encode(string.getBytes());  
  37.     }  
  38.       
  39.     public static void main(String[] args) {  
  40.         DecUtil dec = new DecUtil();  
  41.         String str = "password";  
  42.         System.out.println("未加密前:" + str);  
  43.         String _str = dec.encrypt(str);  
  44.         System.out.println("加密后:" + _str);  
  45.         System.out.println("加密字符串[" + _str + "]解密后:" + dec.decrypt(_str));  
  46.     }  
  47.       
  48. }  

 

 

xml配置文件的

Java代码   收藏代码
  1. JAXPConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test-no-ns.xml"false);  
  2. ……  
  3. connection = DriverManager.getConnection("proxool.xml-test");  

 

properties 配置文件的

Java代码   收藏代码
  1. PropertyConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test.properties");   
  2. ……  
  3. connection = DriverManager.getConnection("proxool.property-test");  


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值