You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by sanugu <sa...@gmail.com> on 2005/09/02 15:20:17 UTC

accessing tomcat context in Axis service object

Hi,

I am developing a web service, which has to insert the data into Oracle 
database. I am not able to get the datasource object created as a global 
resource. I also, created a resource link for 'AXIS' web module.

My Server *is tomcat 5.0*, and I configured Axis on it, and its working fine 
with simple test services.

My service object calls a DAO class, where I am creating an Initial context 
and loop up the "datasource".

But my service object throws an exception.

* *Context ctx=new InitialContext();

*DataSource ds = (DataSource)ctx.lookup("jdbc/axisDS");*

* **OR*

Thinking that axis has to create the server context with binding variables, 
I used the following code

* ** Properties props=new Properties(); *

* ** props.put(Context.INITIAL_CONTEXT_FACTORY,"
org.apache.naming.java.javaURLContextFactory"); *

* props.put(Context.PROVIDER_URL,"t3://localhost:80"); (my server is running 
on port 80).*

* Context ctx=new InitialContext(props); *

*DataSource ds = (DataSource)ctx.lookup("jdbc/axisDS");*

When use this code, Exception is : "*jdbc is not bound in this Context*" 

Context envCtx = (Context) (new InitialContext()).lookup("java:comp/env");

This code throw an exception is "java:comp *is not bound in this Context*"

Could somebody give me the clear directioins of creating and calling the 
datasource from axis.

 -thanks

Re: accessing tomcat context in Axis service object

Posted by Javier Gonzalez <ja...@gmail.com>.
while I don't know how to access the context in the way you want, what
I've done is encapsulate the data access stuff (the initialcontext,
lookup datasource, etc) in a separate class, and when I need a
connection I call a method from that class. Then I initialize that
class on a servlet and bob's your uncle.

On 9/2/05, sanugu <sa...@gmail.com> wrote:
> 
> 
> Hi, 
> 
>  I am developing a web service, which has to insert the data into Oracle
> database.  I am not able to get the datasource object created as a global
> resource. I also, created a resource link for 'AXIS' web module. 
> 
>  My Server is tomcat 5.0, and I configured Axis on it, and its working fine
> with simple test services. 
> 
>  My service object calls a DAO class, where I am creating an Initial context
> and loop up the "datasource". 
> 
>  But my service object throws an exception. 
> 
>    Context ctx=new InitialContext(); 
> 
> DataSource ds =  (DataSource)ctx.lookup("jdbc/axisDS"); 
> 
>   OR 
> 
> Thinking that axis has to create the server context with binding variables,
> I used the following code 
> 
>                                       Properties props=new
> Properties(); 
> 
>                                      
> props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java.javaURLContextFactory");
> 
>                                    
> props.put(Context.PROVIDER_URL," t3://localhost:80");  (my server is running
> on port 80). 
> 
>                                     Context ctx=new InitialContext(props);  
>    
> 
> DataSource ds =  (DataSource)ctx.lookup("jdbc/axisDS"); 
> 
>  When use this code, Exception is  : " jdbc is not bound in this Context "  
>        
> 
>  Context envCtx = (Context) (new
> InitialContext()).lookup("java:comp/env"); 
> 
>  
> 
> This code throw an exception is "java:comp is not bound in this Context " 
> 
>   Could somebody give me the clear directioins of creating and calling the
> datasource from axis. 
> 
>   
> 
> -thanks 


-- 
Javier Gonzalez Nicolini