Two web service questions [message #176584] |
Tue, 08 August 2006 18:21 |
Eclipse User |
|
|
|
Originally posted by: michael.mailinator.com
I have created a web service from a couple of simple java classes using
the wizard. I would like to put database connection parameters in there,
but I don't know how to access them from the java class that becomes the
web service.
Question 1: How can I access context parameters from the resulting
web.xml file in the web service?
Secondly, I've currently got the connection info in the class itself.
Every time I make a call to the service, the connection is null, and it
has to make a new connection, even though I have the connection object
delclared as a member variable in the class.
Question 2: How do I keep an instance of the class alive so that it
simply reuses the connection?
I've been writing web services using Sun's WSDP, and I love the simple
approach that I'm seeing in the WTP plugin. However, the simplicity is
hiding some of the functionality that I need.
Thanks,
--Michael
|
|
|
|
|
Re: Two web service questions [message #176719 is a reply to message #176687] |
Wed, 09 August 2006 17:57 |
Eclipse User |
|
|
|
Originally posted by: michael.mailinator.com
Andrew, thank you for your reply. Concerning your suggestion to let the
container manage the database connections, I considered doing that, but
since I was essentially using a javabean, I had no idea how to get a
handle to the Context instance that is referenced in the tomcat how-to
documents you linked below.
Is there something similar to the MessageContext object that would allow
me to use the following code?
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
Thanks again,
--Michael
Andrew Mak wrote:
> Hi Michael,
>
> For your first question, you can use the MessageContext object which is
> part of the Axis API. From that object you can retrieve references to
> the servlet container or the current request/response objects. For
> example:
>
> MessageContext context = MessageContext.getCurrentContext();
> HttpServlet servlet =
> (HttpServlet) context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>
> // TODO: work with the servlet object
>
> You can refer to this page for more information:
> http://ws.apache.org/axis/java/user-guide.html#ClassesToKnow
>
>
> For your second question, instead of managing the connection within your
> class, you may want to let the container manage the connection for you.
> Try the following documents for reference:
>
> http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-exam ples-howto.html
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-exam ples-howto.html
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03688 seconds