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
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.