You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Vasiliy Kiryanov <va...@gmail.com> on 2006/08/07 08:24:58 UTC
jndi integration problems
Good afternoon.
In my BackBeans I use InitialContext from which i aquire datasource, shale
mock InitialContext and
therefore I try to find a way to test my BackBeans using Shale ..
[ http://shale.apache.org/features-jndi-integration.html] link says to me
that I can aquire a java.sql.Connection ..
but integration using way from that link is constantly return null.
from the myfaces BackBean this datasource resolves good using ussual jndi
way:
------------------------------------------
public String Perform()
{
try
{
InitialContext initialContext = new InitialContext();
if (initialContext == null)
{
...
}
DataSource dataSource = (DataSource) initialContext.lookup
("java:/comp/env/jdbc/postgres");
...
------------------------------------------
I have next entry in the web.xml
<resource-ref>
<description>postgreSQL Datasource</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and use next class:
public class jndiTest extends AbstractViewController
{
public jndiTest()
{
try
{
FacesContext context = FacesContext.getCurrentInstance();
Application appl = context.getApplication();
ValueBinding vb =
context.getApplication().createValueBinding("#{jndi['jdbc/postgres'].connection}");
Connection conn = (Connection) vb.getValue(context);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
and I call object of this class in this way:
public class TestLoginBackBean extends AbstractViewControllerTestCase
{
LoginBackBean loginBackBean;
public TestLoginBackBean(String name)
{
super(name);
}
public static Test suite()
{
return (new TestSuite(TestLoginBackBean.class));
}
public void setUp()
{
super.setUp();
loginBackBean = new LoginBackBean();
}
public void tearDown()
{
loginBackBean = null;
super.tearDown();
}
public void testLoginBackBean_one()
{
jndiTest jnditest = new jndiTest();
}
}
Re: jndi integration problems
Posted by James Mitchell <jm...@apache.org>.
FYI -- this was hung in the moderation queue, I sent this one
through, but you (Vasiliy Kiryanov) will not be able to reply. Please
sign up on the mailing list.
http://shale.apache.org/mail-lists.html
Thanks
--
James Mitchell
678.910.8017
On Aug 7, 2006, at 2:24 AM, Vasiliy Kiryanov wrote:
> Good afternoon.
>
> In my BackBeans I use InitialContext from which i aquire
> datasource, shale
> mock InitialContext and
> therefore I try to find a way to test my BackBeans using Shale ..
>
> [ http://shale.apache.org/features-jndi-integration.html] link says
> to me
> that I can aquire a java.sql.Connection ..
>
> but integration using way from that link is constantly return null.
>
>
> from the myfaces BackBean this datasource resolves good using
> ussual jndi
> way:
> ------------------------------------------
> public String Perform()
> {
> try
> {
> InitialContext initialContext = new InitialContext();
> if (initialContext == null)
> {
> ...
> }
> DataSource dataSource = (DataSource) initialContext.lookup
> ("java:/comp/env/jdbc/postgres");
> ...
> ------------------------------------------
>
>
> I have next entry in the web.xml
> <resource-ref>
> <description>postgreSQL Datasource</description>
> <res-ref-name>jdbc/postgres</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
>
>
> and use next class:
> public class jndiTest extends AbstractViewController
> {
> public jndiTest()
> {
> try
> {
>
> FacesContext context = FacesContext.getCurrentInstance();
> Application appl = context.getApplication();
> ValueBinding vb =
> context.getApplication().createValueBinding("#{jndi['jdbc/
> postgres'].connection}");
>
>
> Connection conn = (Connection) vb.getValue(context);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
> and I call object of this class in this way:
> public class TestLoginBackBean extends AbstractViewControllerTestCase
> {
>
> LoginBackBean loginBackBean;
>
> public TestLoginBackBean(String name)
> {
> super(name);
> }
>
> public static Test suite()
> {
> return (new TestSuite(TestLoginBackBean.class));
> }
>
> public void setUp()
> {
> super.setUp();
> loginBackBean = new LoginBackBean();
> }
>
> public void tearDown()
> {
> loginBackBean = null;
> super.tearDown();
> }
>
> public void testLoginBackBean_one()
> {
> jndiTest jnditest = new jndiTest();
> }
> }
Re: jndi integration problems
Posted by Craig McClanahan <cr...@apache.org>.
On 8/6/06, Vasiliy Kiryanov <va...@gmail.com> wrote:
>
> Good afternoon.
>
> In my BackBeans I use InitialContext from which i aquire datasource,
> shale
> mock InitialContext and
> therefore I try to find a way to test my BackBeans using Shale ..
>
> [ http://shale.apache.org/features-jndi-integration.html] link says to me
> that I can aquire a java.sql.Connection ..
>
> but integration using way from that link is constantly return null.
>
>
> from the myfaces BackBean this datasource resolves good using ussual jndi
> way:
> ------------------------------------------
> public String Perform()
> {
> try
> {
> InitialContext initialContext = new InitialContext();
> if (initialContext == null)
> {
> ...
> }
> DataSource dataSource = (DataSource) initialContext.lookup
> ("java:/comp/env/jdbc/postgres");
> ...
> ------------------------------------------
>
>
> I have next entry in the web.xml
> <resource-ref>
> <description>postgreSQL Datasource</description>
> <res-ref-name>jdbc/postgres</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
>
>
> and use next class:
> public class jndiTest extends AbstractViewController
> {
> public jndiTest()
> {
> try
> {
>
> FacesContext context = FacesContext.getCurrentInstance();
> Application appl = context.getApplication();
> ValueBinding vb =
> context.getApplication
> ().createValueBinding("#{jndi['jdbc/postgres'].connection}");
>
>
> Connection conn = (Connection) vb.getValue(context);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
> and I call object of this class in this way:
> public class TestLoginBackBean extends AbstractViewControllerTestCase
> {
>
> LoginBackBean loginBackBean;
>
> public TestLoginBackBean(String name)
> {
> super(name);
> }
>
> public static Test suite()
> {
> return (new TestSuite(TestLoginBackBean.class));
> }
>
> public void setUp()
> {
> super.setUp();
> loginBackBean = new LoginBackBean();
> }
>
> public void tearDown()
> {
> loginBackBean = null;
> super.tearDown();
> }
>
> public void testLoginBackBean_one()
> {
> jndiTest jnditest = new jndiTest();
> }
> }
>
>
Vasilly,
I spent some time looking into this issue, and was able to successfully use
an expression like "#{jndi['jdbc/travel']}" to retrieve a data source from
Tomcat. The details are in the JIRA issue[1] that I filed about this
problem. As you'll see the issue is resolved as "cannot reproduce" ... feel
free to reopen it if you can provide a complete test case where this is
failing for you.
Craig
[1] http://issues.apache.org/struts/browse/SHALE-253