Is there something similar to RequestListener that I can use to call RMI? Is there a way that I can embed contextual information in MD4 log4j when EJB boots through an RMI call?
I have a web application with all the business logic implemented through EJB. My EJBs use Log4j to create log entries.
In the query listener, I added some specific parameters to MD4 Log4j (such as the request identifier, session identifier, etc.) that are automatically added by the application.
public class Log4jMDCRequestListener implements ServletRequestListener {
@Override
public void requestInitialized(ServletRequestEvent paramServletRequestEvent) {
HttpServletRequest request = (HttpServletRequest) paramServletRequestEvent.getServletRequest();
String requestId = RandomStringUtils.randomAlphanumeric(32);
MDCUtils.setRequestId(requestId);
MDCUtils.setUsername(RequestUtils.getLoginUserName(request));
MDCUtils.setIP(RequestUtils.getRealIP(request));
}
}
log4j.xml:
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %X{requestId} [%c] %X{username} %X{ip} %m%n"/>
</layout>
This is great for all requests based on web requests (since RequestListener is run for every request)
, , EJB RMI /, , , IP.
- RequestListener, RMI, IP ..