Hello,
I have the following question:
I have a web application that is accessed from several fat J2SE clients. All logging happens on the server, i.e. the clients access a stateful session bean that acts as a facade for server-side log4j. The clients submit an ID, making it possible to identify a specific client in the logs. This works fine so far:
On the server:
[code]
public interface Logger {
public void log(String msg);
}
@Stateful
public class LoggerBean implements Logger {
public void log(String msg) { ... }
}
[/code]
And on the client:
[code]
Logger logger = (Logger) new InitialContext().lookup(Logger.class.getName());
logger.log("something");
[/code]
There is another stateful session bean that acts as a facade between the clients and JPA:
[code]
@Stateful
public class PersistenceFacade {
public Object findEntity(Class c, Object primaryKey) { return entityManager.findEntity(c, primaryKey); }
}
[/code]
And on the client:
[code]
Example example = (Example) new InitialContext().lookup(Example.class.getName());
example.setValue(foobar);
...
[/code]
Now my problem is that when a client tries to access an entity bean, and someting happens in the entity bean, it can't log to the client's logger bean instance as it has no way of knowing about this instance. Entity beans are instantiated from the EntityManager and I can't pass the instance of the logger bean to them:
[code]
@Entity
public class Example {
public void setValue(Object o) {
try { foobar(o); }
catch(Exception e) {
logger.log(e.toString()); // how to get the current session's logger bean instance?
}
}
[/code]
Is there any way, maybe some kind of SessionContext, into which I could put the logger bean instance in the session bean and from which I can retrieve it in the entity bean?
Thanks in advance for all your useful answers.
Greetings
ronin
[Message sent by forum member 'ronin2' (ronin2)]
http://forums.java.net/jive/thread.jspa?messageID=266803