[JNDI/Naming/Network] - [JBoss 4.0.2] NameNotFoundException: datasource not bound
by rufik
Hi,
I have not trivial problem with looking up datasource. Some details:
xxx-ds.xml datasource entry:
| <local-tx-datasource>
| <jndi-name>jdbc/cms</jndi-name> <connection-url>jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=latin2</connection-url>
| <driver-class>org.gjt.mm.mysql.Driver</driver-class>
| <user-name>user</user-name>
| <password>passwd</password>
| </local-tx-datasource>
|
web.xml entry:
| <resource-ref>
| <description>CMS Datasource</description>
| <res-ref-name>jdbc/cms</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <res-auth>Container</res-auth>
| <res-sharing-scope>Shareable</res-sharing-scope>
| </resource-ref>
|
jboss-web.xml entry:
| <resource-ref>
| <res-ref-name>jdbc/cms</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <jndi-name>java:jdbc/cms</jndi-name>
| </resource-ref>
|
Code that does lookup:
| InitialContext initctx = new InitialContext();
| initctx.lookup("java:comp/env/jdbc/cms");
|
This code works in most cases well (within EJB module, web app, etc) but I have problem in one special case: I have servlet (let call it JobInitializerServlet) that uses Quartz to schedule some jobs.
This servlet uses my class QuartzManager to find all jobs in database and schedule them. Single job is just a single EJB which "have to be loaded" from db with EJB.load() method.
Load method uses his own DAO class, where is done datasource lookup using code above. So QuartzManager calls EJB and EJB internally calls lookup of DS.
And there is a problem:
| javax.naming.NameNotFoundException: cms not bound
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
| at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:701)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
| at javax.naming.InitialContext.lookup(InitialContext.java:392)
|
As I can say, I tried to do same DS lookup in JobInitializerServlet before calling QuartzManager and it works! But a while later (in QuartzManager code) looking up DS fails. Why???
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138258#4138258
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138258
18 years, 1 month
[JBoss Portal] - Re: Servlet calling java:portal/UserModule
by Antoine_h
ok, the other post say it is ok to do it this way.
so why not.
but for your need, yes, getting the principal from the security checking is enough...
you don't need to reproduce the password checking etc....
get the principal :
you can get the principal from the portlet request...
and also from the servlet request...
so, yes, you can get it from your servlet, even if out of any portlet or so.
in fact, the JBoss Portal relies on JAAS/Tomcat integration for setting up the Portal security.
the JAAS/Tomcat make the security authentification, then provide the principal to any servlet running under the security domain.
the principal is the same for the portlet and the servlet (read the JSR-168 about that).
look a HTTPServletRequest and the getPrincipal() method.
and how to use it to know if the user is logged in etc....
(I will be out of office for a while...)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138257#4138257
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138257
18 years, 1 month