Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Acces to tomcat context in thread  RSS feed

 
alain martin
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Tomcat application, I read the parameters of the web.xml file with this lines:



But when I throw a new Thread the thread can't read it. How can I set thread to read the context of the tomcat application?

Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that you're implementing a web service using Axis, since that's where MessageContext comes from.

The message context is probably only valid in the thread that handles the WS invocation. If you want to use that information in some other thread, get it in the WS thread, and pass it to the newly created thread, either in the constructor or via setters.
 
alain martin
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I'm using axis.

Your proposal doesn't like me very much, I would like doing it more clean...

how could I read the web.xml file directly from the thread?

thanks
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alain:how could I read the web.xml file directly from the thread?

Well nothing stops you from reading a file on the file system! However, you would need to know which web.xml to read i.e. the path of the file on the filesystem.
This means that the thread reading the web.xml needs to be passed some contextual information, and this is exactly what Ulf suggested.
You may choose to pass the file path and read web.xml yourself or just passed the ServletContext that will read the xml for you.
The choice is yours, but indeed the sensible one will be to pass the ServletContext!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The choice is yours, but indeed the sensible one will be to pass the ServletContext!

I disagree. The ServletContext object should not be passed to other components. The proper thing to do is to retrieve those data items that are of interest from the context, and then pass those to the newly created thread.
[ February 21, 2008: Message edited by: Ulf Dittmer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!