You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "vasiliy.kiryanov" <go...@mail.ru> on 2006/08/05 14:35:41 UTC

shale: jndi lookup error

Good afternoon.

[http://shale.apache.org/features-jndi-integration.html] link says to me
that I can aquire a java.sql.Connection from this data source ..

but it constantly return null.
from the myfaces BackBean this datasource resolves good.
Does anybody have any ideas? 

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(); 
    }
}
-- 
View this message in context: http://www.nabble.com/shale%3A-jndi-lookup-error-tf2055640.html#a5663762
Sent from the Struts - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: shale: jndi lookup error

Posted by "vasiliy.kiryanov" <go...@mail.ru>.
>>What you are trying looks like it should work.  If you try to look it up in
>>the usual JNDI way,

>>    InitialContext initContext = new InitContext();
>>    DataSource ds = (DataSource) initContext.lookup
("java:comp/env/jdbc/postgres");

>>does it actually work?  Also, what servlet container are you running on? 
Yes, it  works form myfaces BackBeans using ussual Jndi way that looks like
example you provided.
But when I use Shale it mocks initialcontext and therefore I looking for 
another way to aquire connection.

I am using Tomcat 5.5.17
-- 
View this message in context: http://www.nabble.com/shale%3A-jndi-lookup-error-tf2055640.html#a5671730
Sent from the Struts - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: shale: jndi lookup error

Posted by Craig McClanahan <cr...@apache.org>.
On 8/5/06, vasiliy.kiryanov <go...@mail.ru> wrote:
>
>
> Good afternoon.
>
> [http://shale.apache.org/features-jndi-integration.html] link says to me
> that I can aquire a java.sql.Connection from this data source ..
>
> but it constantly return null.
> from the myfaces BackBean this datasource resolves good.
> Does anybody have any ideas?


Shale has become it's own top level project with it's own mailing lists ...
you might want to subscribe to the user list there via the links on <
http://shale.apache.org/mail-lists.html>.

What you are trying looks like it should work.  If you try to look it up in
the usual JNDI way,

    InitialContext initContext = new InitContext();
    DataSource ds = (DataSource) initContext.lookup
("java:comp/env/jdbc/postgres");

does it actually work?  Also, what servlet container are you running on?

Craig

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();
>     }
> }
> --
> View this message in context:
> http://www.nabble.com/shale%3A-jndi-lookup-error-tf2055640.html#a5663762
> Sent from the Struts - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>