I am developing stateless session beans and would like to log details such as client IP address, port, etc. on the server side. I am using log4j as my logging module. I tried looking up on the net and apparently there is no straightforward way to achieve this. Is this true?
Any suggestions would be appreciated.
The EJB server pretty much as very little information about its clients. I hate to say this, but you are pretty much correct.
One thing that you might try is to look into the documentation for the security features of your server, and see if it has a mechanism for capturing this kind of information and dumping it to a log file. You may not be able to use Log4J, but at least the information will not be lost.
I think Paul is pretty much on the right track. I encountered similar thing in one of my previous projects, and I did one of the following 2:
1) Use log4j in web tier, which you can easily retrieved client information from the HttpRequest.
2) Retrieve the information you need in web tier, then pass this information (maybe you can use Value Object) to the session bean and log it from there.
Both methods should work, and it depends on your requirement about which way to go. Hope it helps.
Thanks for your replies guys.
Being a newbie I do find it strange that there is no way for an EJB to obtain client info directly. Are you aware of any architectural principle that is involved in this EJB design choice?
I develop fat clients for these beans, so there is no webtier that I can use to get this info. I can probably get the fat client to send me this info as serialized arguments to the bean business method call, but I would like to avoid that as much as possible.