Create a webapp around an existing webapp for handling session control


Hi all,

A time ago I posted this question http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21650462.html#15405554

The result of that question was to use tomcat valves. So far so good. In a couple of weeks, I will begin development of the application described in the above question.
I have one reservation left.

Are these Valves thread-safe? Does anyone know about this?

Thank you.
tcollogneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
I would treat them like servlets, so any static or global members should be handles with care, but otherwise all method level variables should be fine :-)

Tim
0
tcollogneAuthor Commented:
So, I can use private methods inside the class with no problem like this. The getDatabaseUser is a private method that I created. It will get information from inside a database (JDBC).

public class TomcatValveEx extends ValveBase {
 
   public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException {

             System.out.println("Example VALVE hit");
             context.invokeNext(request, response);
   }

   private String getDatabaseUser() {
      return "test";
   }

}
0
TimYatesCommented:
that *should* be ok

Not sure if you can get at the DBCP from inside a valve though...  You're treading new ground as far as my experience goes :-/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

tcollogneAuthor Commented:
I am going to keep this open for a little longer.
0
tcollogneAuthor Commented:
Indeed, I can't seem to manage getting a DataSource in the valve.
I get a javax.naming.NameNotFoundException : Name comp is not bound in this Context.

I use this code for getting a datasource :

Context initContext = new InitialContext();                        
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)initContext.lookup("jdbc/vtvres");            
Connection conn = ds.getConnection();

Is there another way of achieving it?
0
tcollogneAuthor Commented:
Sorry the code is

Context initContext = new InitialContext();                  
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/vtvres");            
Connection conn = ds.getConnection();
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.