Search in sources :

Example 1 with ISO8601DateFormat

use of org.apache.log4j.helpers.ISO8601DateFormat in project openmrs-module-pihcore by PIH.

the class RequestMonitoringFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    long startTime = System.currentTimeMillis();
    chain.doFilter(request, response);
    long endTime = System.currentTimeMillis();
    long totalTime = endTime - startTime;
    if (enabled && request instanceof HttpServletRequest) {
        try {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpSession session = httpRequest.getSession();
            ISO8601DateFormat dateFormat = new ISO8601DateFormat();
            SimpleObject logLine = new SimpleObject();
            logLine.put("timestamp", dateFormat.format(new Date(startTime)));
            logLine.put("sessionId", session.getId());
            logLine.put("user", session.getAttribute("username"));
            logLine.put("loadTime", totalTime);
            logLine.put("method", httpRequest.getMethod());
            logLine.put("requestPath", httpRequest.getRequestURI());
            logLine.put("queryParams", formatRequestParams(httpRequest));
            logger.info(logLine.toJson());
        } catch (Exception e) {
        // Do nothing, we don't want this filter to cause any adverse behavior
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleObject(org.openmrs.ui.framework.SimpleObject) HttpSession(javax.servlet.http.HttpSession) ISO8601DateFormat(org.apache.log4j.helpers.ISO8601DateFormat) Date(java.util.Date) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with ISO8601DateFormat

use of org.apache.log4j.helpers.ISO8601DateFormat in project openmrs-module-pihcore by PIH.

the class TermsAndConditionsPageController method post.

public String post(@RequestParam(value = "termsAndConditionsAccepted", defaultValue = "false") boolean termsAndConditionsAccepted, @SpringBean("userService") UserService userService) {
    if (termsAndConditionsAccepted) {
        User currentUser = Context.getAuthenticatedUser();
        String acceptanceDate = new ISO8601DateFormat().format(new Date());
        currentUser.setUserProperty(PihCoreConstants.USER_PROPERTY_TERMS_AND_CONDITIONS_ACCEPTED_DATE, acceptanceDate);
        userService.saveUser(currentUser);
    }
    return "redirect:/pihcore/home.page";
}
Also used : User(org.openmrs.User) ISO8601DateFormat(org.apache.log4j.helpers.ISO8601DateFormat) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 ISO8601DateFormat (org.apache.log4j.helpers.ISO8601DateFormat)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 User (org.openmrs.User)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1