X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Frest%2FCommonRestController.java;fp=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Frest%2FCommonRestController.java;h=eadd8d34f3fd7856e3c68b59c9029746e81b2e88;hb=6438ef61e253f5071a5539c0c8de8890260d4f58;hp=ef288e47feae3bcb6d75ce1a7ed501755979b088;hpb=22d211f6df78363d61192057d7cd03534ff7d1c9;p=policy%2Fapi.git diff --git a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java index ef288e47..eadd8d34 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ package org.onap.policy.api.main.rest; +import java.util.Objects; import java.util.UUID; import org.onap.policy.api.main.exception.PolicyApiRuntimeException; import org.onap.policy.common.utils.coder.Coder; @@ -107,12 +108,10 @@ public class CommonRestController { * @return the response builder, with version logging */ public static ResponseEntity.BodyBuilder addLoggingHeaders(ResponseEntity.BodyBuilder respBuilder, UUID requestId) { - if (requestId == null) { - // Generate a random uuid if client does not embed requestId in rest request - return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID().toString()); - } + // Generate a random uuid if client does not embed requestId in rest request + return respBuilder.header(REQUEST_ID_NAME, + Objects.requireNonNullElseGet(requestId, UUID::randomUUID).toString()); - return respBuilder.header(REQUEST_ID_NAME, requestId.toString()); } /**