JNDI Datasource in GateIn portlet on JBoss 7.1

1.1k views Asked by At

I'm trying to get a datasource in a portlet that I deployed in GateIn 3.2.0 on JBoss 7.1.

First I created the datasource in the standalone.xml

            <datasource jta="true" jndi-name="java:jboss/datasources/ccr" pool-name="ccr-pool" enabled="true" use-java-context="false" use-ccm="true">
                <connection-url>jdbc:mysql://localhost:42006/contentrepository</connection-url>
                <driver>com.mysql</driver>
                <security>
                    <user-name>node</user-name>
                </security>
                <statement>
                    <prepared-statement-cache-size>100</prepared-statement-cache-size>
                    <share-prepared-statements>true</share-prepared-statements>
                </statement>
            </datasource>

I also added the driver and the module for the driver.

In my portlet I'm trying to access the datasource using

dataSource = (DataSource) new InitialContext().lookup("java:jboss/datasources/ccr");

but I'm only getting a javax.naming.NameNotFoundException: Name 'jboss' not found in context ''.

I also tried to fetch it with

dataSource = (DataSource) new InitialContext().lookup("java:comp/env/datasources/ccr");

and mapped it with the following entries in the web.xml and jboss-web.xml

web.xml:

<resource-ref>
    <description>MySQL DS</description>
    <res-ref-name>datasources/ccr</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <resource-ref>
        <res-ref-name>datasources/ccr</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jboss/datasources/ccr</jndi-name>
    </resource-ref>
</jboss-web>

then I got javax.naming.NameNotFoundException: Name 'comp' not found in context ''.

What am I missing? Is there some security setting that prevents my application from fetching the datasource?

Strangely I could fetch the datasource in the same webapplication when using a servlet, but only in the doGet/doPost methods and not in the init().

1

There are 1 answers

0
ilalex On

I have the same issue on GateIn 3.3. But it not reproduced with GateIn 3.4M1. When I google this bug i've found it in JIRA here: https://issues.jboss.org/browse/GTNPORTAL-2511