package xstefanox;

import org.springframework.stereotype.Service;

/**
 * Store the ID of the current request.
 */
@Service
public class RequestIdProvider {

    private static final ThreadLocal<String> REQUEST_ID = new ThreadLocal<>();

    public String get() {
        return REQUEST_ID.get();
    }

    public void set(String requestId) {
        REQUEST_ID.set(requestId);
    }

    public void unset() {
        REQUEST_ID.remove();
    }
}

@@ -59,16 +59,151 @@
 Service;
+%0Aimport org.springframework.web.context.request.RequestAttributes;%0Aimport org.springframework.web.context.request.RequestContextHolder;
 %0A%0A/**%0A *
@@ -260,16 +260,22 @@
 %0Apublic 
+final 
 class Re
@@ -301,48 +301,195 @@
     
-private static final ThreadLocal%3C
+/**%0A     * The name of the request attribute that holds the request ID in the%0A     * %7B@link org.springframework.web.servlet.support.RequestContext%7D.%0A     */%0A    public static final 
 String
-%3E
  REQ
@@ -497,100 +497,401 @@
 EST_
-ID = new ThreadLocal%3C%3E();%0A%0A    public String get() %7B%0A        return REQUEST_ID.get();%0A    %7D%0A
+ATTRIBUTE_NAME = %22REQUEST_ID%22;%0A%0A    /**%0A     * Get the request ID.%0A     *%0A     * @return The request ID%0A     */%0A    public String get() %7B%0A        return (String) RequestContextHolder.currentRequestAttributes()%0A                .getAttribute(REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);%0A    %7D%0A%0A    /**%0A     * Set the request ID.%0A     *%0A     * @param requestId The request ID%0A     */
 %0A   
@@ -907,16 +907,22 @@
 oid set(
+final 
 String r
@@ -946,93 +946,433 @@
    R
-EQUEST_ID.set(requestId);%0A    %7D%0A%0A    public void unset() %7B%0A        REQUEST_ID.remove(
+equestContextHolder%0A                .currentRequestAttributes()%0A                .setAttribute(REQUEST_ATTRIBUTE_NAME, requestId, RequestAttributes.SCOPE_REQUEST);%0A    %7D%0A%0A    /**%0A     * Remove the currently set request ID, if any.%0A     */%0A    public void unset() %7B%0A        RequestContextHolder%0A                .currentRequestAttributes()%0A                .removeAttribute(REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST
 );%0A 

store the request ID using Spring RequestContextHolder