Skip to content

Instantly share code, notes, and snippets.

@kwon37xi
kwon37xi / MdcLoggingInterceptor.java
Last active July 20, 2020 17:31
Spring MVC logging controller information with MDC.
@Slf4j
public class MdcLoggingInterceptor implements HandlerInterceptor {
public static final String REQUEST_URL_MDC_KEY = "URL";
public static final String REQUEST_CONTROLLER_MDC_KEY = "Controller";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
String fullUrl = request.getRequestURI() + Optional.ofNullable(request.getQueryString()).map(qs -> "?" + qs).orElse("");
@joergrathlev
joergrathlev / Demo.java
Created June 23, 2015 21:06
The IO monad (or something similar) in Java
import java.util.function.Function;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class Demo {
/**
* An IO operation that results in a value of type T.