tcollogne
asked on
Create a webapp around an existing webapp for handling session control
Hi all,
A time ago I posted this question https://www.experts-exchange.com/questions/21650462/Create-a-webapp-around-an-existing-webapp-for-handling-session-control.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.
ASKER
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("Exampl e VALVE hit");
context.invokeNext(request , response);
}
private String getDatabaseUser() {
return "test";
}
}
public class TomcatValveEx extends ValveBase {
public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException {
System.out.println("Exampl
context.invokeNext(request
}
private String getDatabaseUser() {
return "test";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am going to keep this open for a little longer.
ASKER
Indeed, I can't seem to manage getting a DataSource in the valve.
I get a javax.naming.NameNotFoundE xception : Name comp is not bound in this Context.
I use this code for getting a datasource :
Context initContext = new InitialContext();
Context envContext = (Context)initContext.looku p("java:/c omp/env");
DataSource ds = (DataSource)initContext.lo okup("jdbc /vtvres");
Connection conn = ds.getConnection();
Is there another way of achieving it?
I get a javax.naming.NameNotFoundE
I use this code for getting a datasource :
Context initContext = new InitialContext();
Context envContext = (Context)initContext.looku
DataSource ds = (DataSource)initContext.lo
Connection conn = ds.getConnection();
Is there another way of achieving it?
ASKER
Sorry the code is
Context initContext = new InitialContext();
Context envContext = (Context)initContext.looku p("java:/c omp/env");
DataSource ds = (DataSource)envContext.loo kup("jdbc/ vtvres");
Connection conn = ds.getConnection();
Context initContext = new InitialContext();
Context envContext = (Context)initContext.looku
DataSource ds = (DataSource)envContext.loo
Connection conn = ds.getConnection();
Tim