Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Two web service questions
Two web service questions [message #176584] Tue, 08 August 2006 18:21 Go to next message
Eclipse UserFriend
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 #176687 is a reply to message #176584] Wed, 09 August 2006 14:45 Go to previous messageGo to next message
Andrew Mak is currently offline Andrew MakFriend
Messages: 41
Registered: July 2009
Member
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
Re: Two web service questions [message #176703 is a reply to message #176687] Wed, 09 August 2006 14:57 Go to previous messageGo to next message
Andrew Mak is currently offline Andrew MakFriend
Messages: 41
Registered: July 2009
Member
P.S. The code above is missing one more line to actually retrieve the
ServletContext, i.e.

ServletContext servletContext = servlet.getServletContext();


Andrew
Re: Two web service questions [message #176719 is a reply to message #176687] Wed, 09 August 2006 17:57 Go to previous messageGo to next message
Eclipse UserFriend
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
>
Re: Two web service questions [message #176758 is a reply to message #176719] Thu, 10 August 2006 05:06 Go to previous messageGo to next message
Andrew Mak is currently offline Andrew MakFriend
Messages: 41
Registered: July 2009
Member
Hi Michael,

Actually I think the code should work as is, since Tomcat has
implementations for the JNDI interfaces. You'll just have to define your
resource correctly following the examples in those documents.

Also, take a look at these pages for more information:
http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto .html
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto .html

Andrew
Re: Two web service questions [message #176765 is a reply to message #176758] Thu, 10 August 2006 13:19 Go to previous message
Eclipse UserFriend
Originally posted by: michael.mailinator.com

I'll take a look. Thanks very much.

--Michael

Andrew Mak wrote:
> Hi Michael,
>
> Actually I think the code should work as is, since Tomcat has
> implementations for the JNDI interfaces. You'll just have to define
> your resource correctly following the examples in those documents.
>
> Also, take a look at these pages for more information:
> http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto .html
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto .html
>
> Andrew
>
Previous Topic:Leveraging WST Server Tools for non web servers
Next Topic:starting IBM websphere (WAS 6.0.2.7) from eclipse with security enabled
Goto Forum:
  


Current Time: Fri Apr 19 20:49:07 GMT 2024

Powered by FUDForum. Page generated in 0.03031 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top