'How to pass "X-CorrelationID" and "Source Id" from NextJs(front-end) to Springboot(back-end)

I am pretty new to app development. We have an app that uses Springboot microservice as backend and NextJs as front end. we are using correlation ID in the backend for logging purpose. when we test using postman, we have to give some random values as this "sourceID" and " correlationId" to get success message. so how can we pass/generate this IDs from NextJs(frontend) API? Here's the backend code

public ResponseEntity<ServiveApiResponse> login(@RequestBody LoginRequest dto, @RequestHeader("X-CORRELATION-ID") String corrId,@RequestHeader("SOURCE-ID") String sourceId)
            throws ValidationException, ResourceNotFoundException {
        ApiContextResponse apiContextResponse = new ApiContextResponse();
        apiContextResponse.setCorrelationId(corrId);
        apiContextResponse.setSourceSystemId(sourceId);


Solution 1:[1]

you can solve this problem using LinkedHashSet or Regex.
1. LinkedHashSet
public static void main(String[] args) {
        String sentence, result = "";
        String allWords[];
        
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter your sentence: "); 
        sentence = sc.nextLine().toLowerCase();  //convert to lower case
        
        allWords = sentence.split(" ");
        
        LinkedHashSet<String> set = new LinkedHashSet<String>( Arrays.asList(allWords) );
        
        for(String word: set) {
            result = result + word + " ";
        }
        System.out.println("Sentence after removing duplicate words: " + result);

    }

2.Regex
Required regex = "\\b(\\w+)(?:\\W+\\1\\b)+";

public static void main(String[] args) {
        String sentence, regex;
        
        Scanner sc = new Scanner(System.in); 
        System.out.print("Enter your sentence: "); 
        sentence = sc.nextLine();
        // Define regex 
        regex = "\\b(\\w+)(?:\\W+\\1\\b)+";
        // Define pattern to compile regex
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        // Match whether regex matching with sentence or not
        Matcher match = pattern.matcher(sentence);
        // Use while loop to find and replace duplicate words
        while(match.find()) {
            sentence = sentence.replace(match.group(), match.group(1));
        }
        System.out.println("Sentence after removing duplicate words: " + sentence);

    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammad Mehran