Register RMI EJB Requests

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 {
    /**
     * Inject the necessary trackers into the MDC to use in the log4j loggers
     */
    @Override
    public void requestInitialized(ServletRequestEvent paramServletRequestEvent) {

        HttpServletRequest request = (HttpServletRequest) paramServletRequestEvent.getServletRequest();

        // generate a random requestId to correlate all logs from the same request
        String requestId = RandomStringUtils.randomAlphanumeric(32);
        MDCUtils.setRequestId(requestId);

        // inject the username and ip into the MDC as well for use in some logs
        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 ..

+4

Source: https://habr.com/ru/post/1656420/


All Articles