[
https://issues.apache.org/jira/browse/KARAF-3449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14581562#comment-14581562
]
Andy Schmidt edited comment on KARAF-3449 at 6/11/15 7:09 AM:
--------------------------------------------------------------
The problem happens if you provide the data source via blueprint. My data
source looks like
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="My.DataSource.Postgresql"
class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
<property name="serverName" value="localhost:5433/my_db"/>
<property name="user" value="user"/>
<property name="password" value="user"/>
<property name="dataSourceName" value="my_db"/>
<property name="initialConnections" value="2"/>
<property name="maxConnections" value="4" />
</bean>
<service interface="javax.sql.DataSource" ref="My.DataSource.Postgresql">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/my_db"/>
</service-properties>
</service>
</blueprint>
In this case you have to create a database with the name 'my_db/' to get it
running, because the jdbc driver or another component extends the serverName
with '/'.
was (Author: glance):
The problem happens if you provide the datasource via blueprint. My datasource
looks like
> 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)