[jboss-user] [JNDI and Naming] - Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]

Kousik Rajendran do-not-reply at jboss.com
Tue Nov 29 05:43:02 EST 2011


Kousik Rajendran [http://community.jboss.org/people/kousikraj] created the discussion

"Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]"

To view the discussion, visit: http://community.jboss.org/message/638838#638838

--------------------------------------------------------------
Hey Abiya,

I tried in init() method of a servlet container too. it works fine. Here is the test servlet

> import java.io.IOException;
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.sql.DataSource;
> 
> 
> @WebServlet("/test")
> public class TestGateway extends AbstractGateway {
> 
>           private static final long          serialVersionUID          = 5756805325624066368L;
> 
>           @Override
>           public void init() throws ServletException {
>                     super.init();
>                     DataSource ds = null;
>                     Context ctx = null;
>                     try {
>       String strDSName = "java:jboss/datasources/Test";
>       ctx = new InitialContext();
>       ds = (javax.sql.DataSource) ctx.lookup(strDSName);
>       System.out.println("Success getting DS : " + ds.getClass());
>                     } catch (Exception e) {
>       System.out.println("Error getting DS : " + e);
>   }
>           }
> 
> 
When I execute  http://localhost:8080/test/test http://localhost:8080/test/test 
I got my output like this in console.
> 16:11:51,818 INFO  [stdout] (http--0.0.0.0-8080-2) Success getting DS : class org.jboss.jca.adapters.jdbc.WrapperDataSource
So, I think there should be some problem in your Servlet or I am not able to get your problem. Can you detail a little bit in your case.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/638838#638838]

Start a new discussion in JNDI and Naming at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111129/b4f151a4/attachment-0001.html 


More information about the jboss-user mailing list