Class CorrelationIdUtils

java.lang.Object
com.sap.cds.services.utils.CorrelationIdUtils

public class CorrelationIdUtils extends Object
Utility for retrieving or generating a correlation id.
  • Field Details

  • Method Details

    • mdcHasEntry

      public static boolean mdcHasEntry()
      Checks whether there's a correlation id entry in the MDC.
      Returns:
      true, if there's an entry under the key "correlation_id"
    • putInMDC

      public static void putInMDC(String correlationId)
      Puts the provided correlation id into the MDC under the key "correlation_id".
      Parameters:
      correlationId - the correlation id
    • getFromMDC

      public static String getFromMDC()
      Gets a correlation id value from the MDC, if existing, or null otherwise.
      Returns:
      a correlation id
    • clearMDC

      public static void clearMDC()
      Removes the correlation id field from the MDC.
    • getOrGenerateCorrelationId

      public static String getOrGenerateCorrelationId(ParameterInfo parameterInfo)
      Returns the correlation id if already existing, or generates a new one otherwise. Tries to retrieve an existing correlation id from a MDC field, or the parameter info headers, in that specific order.
      Parameters:
      parameterInfo - parameter info to fall back to if correlation id does not exist in MDC
      Returns:
      a correlation id
    • getCorrelationId

      public static String getCorrelationId(ParameterInfo parameterInfo)
      Returns the correlation id if already existing, or null if not.
      Parameters:
      parameterInfo - parameter info to fall back to if correlation id does not exist in MDC, nullable
      Returns:
      a correlation id