[ 
https://issues.apache.org/jira/browse/KARAF-3449?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jean-Baptiste Onofré updated KARAF-3449:
----------------------------------------
    Fix Version/s:     (was: 2.4.3)
                       (was: 3.0.4)
                       (was: 4.0.0.M3)

> Incorrect serverName parsing in JDBC DataSource Blueprint
> ---------------------------------------------------------
>
>                 Key: KARAF-3449
>                 URL: https://issues.apache.org/jira/browse/KARAF-3449
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf-feature, karaf-osgi
>    Affects Versions: 3.0.2
>            Reporter: Justin Reock
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>              Labels: features
>
> The serverName attribute in the JDBC DataSource code appears to be parsed 
> incorrectly.  It is tokenizing off of the ? character, but a trailing slash 
> exists between the database name and the ? parameter delimiter, so a request 
> for a database is matched against "[database_name]/" as opposed to just 
> "[database_name]".  
> This may be isolated to just the PGPoolingDataSource for Postgres, I haven't 
> tried to replicate with another connection driver.  
> To demonstrate, set up a DataSource blueprint similar to the following:
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
>   
>    <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" 
> destroy-method="close">
>       <property name="serverName" value="localhost:5432/postgres"/>
>       <property name="user" value="postgres"/>
>       <property name="password" value="pgpassword"/>
>       <property name="dataSourceName" value="pgConnectionPool"/>
>       <property name="initialConnections" value="5"/>
>       <property name="maxConnections" value="50" />
>   </bean>
>   
>   <service interface="javax.sql.DataSource" ref="dataSource">
>     <service-properties>
>             <entry key="osgi.jndi.service.name" value="jdbc/postgres"/>
>     </service-properties>
>   </service>
> </blueprint>
> ---
> Note that the intended database name from the serverName string here is 
> "postgres".  Upon attempting jdbc actions, the following error message will 
> be returned from the DataSource:
> 2015-01-16 16:22:32,398 | ERROR | h for user karaf | JdbcServiceImpl          
>         | 119 - org.apache.karaf.jdbc.core - 3.0.2 | Can't get information 
> about datasource jdbc/postgres
> org.postgresql.util.PSQLException: FATAL: database "postgres/" does not exist
> Notice the trailing slash after the database name.  That's because the 
> qualified URL for the database is:
> jdbc:postgresql://localhost:5432:postgres/?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&tcpKeepAlive=false&binaryTransfer=true&disableColumnSanitiser=false
> The trailing slash is coming in because the qualified name is being parsed 
> using the ? as a delimiter.  This is provable, because the following 
> serverName property can be used as a workaround:
>  <property name="serverName" value="localhost:5432/postgres?"/>
> Note the ? at the end of the value.  This forces the interpreter to parse the 
> proper database name.  So the fix here would be either to account for the 
> trailing slash in the qualified name, or, not to append the slash at all when 
> deriving the qualified name.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to