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 christopher justin <ch...@hotmail.com> on 2004/01/29 21:40:27 UTC

JDBC datasource from Web Service

Hello all,
I have a 2-fold question in which I cannot find any information on from the 
docs, archives, google, etc.  Any help would be greatly appreciated.

What is the correct way to set up a JDBC resource from my Axis Web Service?  
It seems that the Axis Service is itself a Servlet, so I do not understand 
where my init() function that would do the JDBC resource connection would 
go.  For example, I want to do this in my Web Service:

   Context init = new InitialContext();
   dataSource = (DataSource)init.lookup( "java:comp/env/jdbc/mysql");

I have this working in a function called getDB() within the Web Service but 
I don't understand how it recognizes the Context it is in because I do not 
have a WEB-INF/web.xml file that would normally define the resource such as 
:

<resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/mysql</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
</resource-ref>

Does Axis know of the application specific WEB-INF/web.xml ?  I have set up 
Data Sources correcty when useing the JWS SDK and within that I needed a 
resource identified correctly in my application specific WEB-INF/web.xml , 
but Axis seems to not even care about that file.

_________________________________________________________________
Check out the new MSN 9 Dial-up — fast & reliable Internet access with prime 
features! http://join.msn.com/?pgmarket=en-us&page=dialup/home&ST=1


Re: JDBC datasource from Web Service

Posted by __matthewHawthorne <ma...@apache.org>.
christopher justin wrote:
> Does Axis know of the application specific WEB-INF/web.xml ?  I have set 
> up Data Sources correcty when useing the JWS SDK and within that I 
> needed a resource identified correctly in my application specific 
> WEB-INF/web.xml , but Axis seems to not even care about that file.


Where is your service class that Axis loads?  If it's inside of a war 
file, (or in a webapp directory) then it should be able to lookup 
resources through JNDI.

Axis doesn't seem to care about web.xml, application.xml or any of the 
typical deployment descriptors.  Just tell Axis about your service class 
and the rest is handled by the container that you're running in.


RE: JDBC datasource from Web Service

Posted by Richard Martin <rm...@essex.ac.uk>.
Hi Christopher, 

Comments inline below:

>I have this working in a function called getDB() within the Web Service but

>I don't understand how it recognizes the Context it is in because I do not 
>have a WEB-INF/web.xml file that would normally define the resource such as


You must have a web.xml file to map the AxisServlet to the Servlet
container? It's as simple as adding your xml to that file. For reference, a
simple web.xml file for a project I'm working on is attached. As you can
see, all I've done is added the resource-ref element and children to it.
Once that's done you can lookup the JDBC pool as usual. 

>Does Axis know of the application specific WEB-INF/web.xml ?  I have set up

>Data Sources correcty when useing the JWS SDK and within that I needed a 
>resource identified correctly in my application specific WEB-INF/web.xml , 
>but Axis seems to not even care about that file.

Axis might not care but the Servlet container does take note of that xml
file, and that's what provides the InitialContext implementation. 

One thing of note - DataSources with Axis has given me no end of hassle. It
seems that no matter what I do, how often I call Connection.close() to
return it to the pool, the server runs out of connections and then throws an
Exception (db pool could not get idle connection). 

Anyone else on the list had similar experiences?

Hope this helps!

Richard