You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Alexander Grünewald <al...@informus.de> on 2005/12/07 16:44:04 UTC
Can a portlet use a JNDI datasource?
Hello Jetspeed Community,
is it possible to use a JNDI datasource within a portlet deployed on
jetspeed 2. The datasource itself seems to work because I can use it in
a test servlet. But my portlets cann't access it through JNDI. I
configured the datasource as JNDI resource in the tomcate server.xml
file. The file $CATALINA_HOME/conf/server.xml therefore contains a
'global naming section':
...
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Forum DB -->
<Resource
auth="Container"
driverClassName="org.postgresql.Driver"
maxActive="20"
maxIdle="10"
maxWait="-1"
name="jdbc/forum"
password="xxxxx"
type="javax.sql.DataSource"
url="jdbc:postgresql://192.168.3.102:5432/forum"
username="forum"/>
</GlobalNamingResources>
Then I linked the resource to the jetspeed context. The file
$CATALINA_HOME/conf/Catalina/localhost/jetspeed.xml therefore contains a
reference to resource:
<Context path="/jetspeed" docBase="jetspeed" crossContext="true">
...
<ResourceLink global="jdbc/forum" name="jdbc/forum"
type="javax.sql.DataSource"/>
</Context>
And finally I added to the file:
$CATALINA_HOME/webapps/jetspeed/WEB-INF/web.xml the reference to the
datasource:
<web-app>
<display-name>Jetspeed-2 Enterprise Portal</display-name>
...
<resource-ref>
<description>Forum DB Connection</description>
<res-ref-name>jdbc/forum</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
</web-app>
Normally (if this would be a simple servlet) the datasource would now be
accessable through a JNDI lookup. As I said a little while ago, I tested
this with a simple standalone servlet deployed in tomcat. But the JNDI
lookup fails in my portlets. Adding the <resource-ref> to the web.xml
file of the portlet also didn't work. Has anyone experience on this?
Best regards,
Alexander
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Can a portlet use a JNDI datasource?
Posted by Alexander Grünewald <al...@informus.de>.
Aaron Evans wrote:
>Alexander Grünewald <alexander.gruenewald <at> informus.de> writes:
>
>
>>Hello Jetspeed Community,
>>
>>is it possible to use a JNDI datasource within a portlet deployed on
>>jetspeed 2. The datasource itself seems to work because I can use it in
>>a test servlet. But my portlets cann't access it through JNDI. I
>>configured the datasource as JNDI resource in the tomcate server.xml
>>file. The file $CATALINA_HOME/conf/server.xml therefore contains a
>>'global naming section':
>>...
>>
>
>I would think that you should put the reference to the JNDI data source in the
>web.xml of your portlet application, not that of jetspeed and I assume it
>*would* be accessible via a JNDI lookup somehow.
>
>I have used a JNDI datasource indirectly in a portlet as I have a data source
>set up as you describe and a component that exists as a servlet context
>attribute that uses the jndi data source (I instantiate and set up that
>component in a ServletContextListener implementation).
>
>I can access my component by using:
>
>request.getPortletSession().getPortletContext().getAttribute("mycomponent");
>
>HTH,
>aaron
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>
>
Thank you Aaron. Declaring the datasource in the web.xml file of the
portlet works. This is great :-)
Best regards,
Alexander
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Can a portlet use a JNDI datasource?
Posted by Aaron Evans <aa...@yahoo.ca>.
Alexander Grünewald <alexander.gruenewald <at> informus.de> writes:
>
> Hello Jetspeed Community,
>
> is it possible to use a JNDI datasource within a portlet deployed on
> jetspeed 2. The datasource itself seems to work because I can use it in
> a test servlet. But my portlets cann't access it through JNDI. I
> configured the datasource as JNDI resource in the tomcate server.xml
> file. The file $CATALINA_HOME/conf/server.xml therefore contains a
> 'global naming section':
> ...
I would think that you should put the reference to the JNDI data source in the
web.xml of your portlet application, not that of jetspeed and I assume it
*would* be accessible via a JNDI lookup somehow.
I have used a JNDI datasource indirectly in a portlet as I have a data source
set up as you describe and a component that exists as a servlet context
attribute that uses the jndi data source (I instantiate and set up that
component in a ServletContextListener implementation).
I can access my component by using:
request.getPortletSession().getPortletContext().getAttribute("mycomponent");
HTH,
aaron
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org