2014-10-23 10:44 GMT+04:00 Alessandro Manzoni <manzoni.alessand...@gmail.com>: > Il 23.10.2014 01.49, Christopher Schultz ha scritto: > >> On 10/22/14 1:04 PM, Alessandro Manzoni wrote: >>> >>> I configured a Resource datasouce inside context.xml but the >>> resulting connection is misconfigured. >>> >>> The failing attribute appears as: >>> >>> connectionProperties="sort=table;sort table=QSYS/QASCII" >>> >>> but looking at the connection (while debugging) properties are >>> messed up, instead of the above 2 properties I see only 1: >>> >>> sort=table=QSYS/QASCII >>> >>> It looks like the property "sort table", with a blank inside the >>> name, was not correctly parsed. >> >> It sure does. >> >>> I'm using jtOpen.jar AS400JDBCDriver that supports a lot of such >>> strange property names: >>> >>> http://www-01.ibm.com/support/knowledgecenter/api/content/ssw_ibm_i_61/rzahh/javadoc/com/ibm/as400/access/doc-files/JDBCProperties.html >> >> Aah, >> AS/400. You are a barrel of laughs. >> >>> If I try supplying the same properties using the >>> connect(Properties) method, or appending them to the url, all is >>> fine. >>> >>> Is there some special syntax to achieve my goal? >> >> I think this is likely a bug. >> >> Whose bug it is depends upon which connection pool you are using. Are >> you using Tomcat's default pool (based upon commons-dbcp) or >> tomcat-pool. If you don't know, it's probably the former. >> >> If the bug belongs to commons-dbcp, you should report it over there >> and when it gets fixed, we'll consume the changes and then Tomcat >> should work properly. >> >> What version of Tomcat are you using? > > I did nothing but inserting a <Resource element into context.xml with no > factory declared, so I think it's Tomcat's default pool fault: > <Resource name="jdbc/OmniaWebDB2400Pool" auth="Container" > type="javax.sql.DataSource" maxActive="100" maxIdle="30" > maxWait="10000" > username="USER" password="PASS" > driverClassName="com.ibm.as400.access.AS400JDBCDriver" > connectionProperties="sort=table;sort table=QSYS/QASCII;" > url="jdbc:as400://dbserver/SCHEMA" /> > > > I tried both 6.037 and 7.056 versions with the same result. > > Itried 8.014 too, but the prgram stops, just while getting the connection > from the datasource, datasource.getConnection() method, with this stack > trace: > > java.lang.AbstractMethodError: > com.ibm.as400.access.AS400JDBCConnection.isValid(I)Z > org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:913) > org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:226) > org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:302) > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2165) > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2148) > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1902) > org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412) > > even if I didn't declare any validate query in datasource definition. >
Default connection pool = Apache Commons DBCP. Searching Apache Commons DBCP source code for "connectionProperties", there a 2 places where that property is parsed: A) BasicDataSource.setConnectionProperties(String) It does String[] entries = connectionProperties.split(";"); followed by int index = entry.indexOf('='); It is OK. B) BasicDataSourceFactory.getProperties(String) This is an awful undocumented implementation with a bunch of side effects. /** * <p>Parse properties from the string. Format of the string must be [propertyName=property;]*<p> * @param propText * @return Properties * @throws Exception */ private static Properties getProperties(String propText) throws Exception { Properties p = new Properties(); if (propText != null) { p.load(new ByteArrayInputStream( propText.replace(';', '\n').getBytes(StandardCharsets.ISO_8859_1))); } return p; } It replaces ';' with '\n' and feeds the string as ISO-8859-1 into Properties.load(). The same implementation of that method is present both in current DBCP2 and in previous DBCP 1.4 used by Tomcat 7. If this implementation is of any use, it must be properly documented. As of now, it does not match its own javadoc which only says that format is "[propertyName=property;]*". Neither it is documented at [2]. The format of a properties file [1] is that "The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':', or white space character other than a line terminator." The workaround for you is to escape the whitespace character in key name with '\'. [1] http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29 [2] http://commons.apache.org/proper/commons-dbcp/configuration.html Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org