![JAR search and dependency download from the Maven repository](/logo.png)
io.convergence_platform.common.helpers.ConvergenceHelpers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of service-lib Show documentation
Show all versions of service-lib Show documentation
Holds the common functionality needed by all Convergence Platform-based services written in Java.
The newest version!
package io.convergence_platform.common.helpers;
import io.convergence_platform.services.observability.RequestLog;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.UUID;
public class ConvergenceHelpers {
public static UUID getParentRequestIdFromRequest(HttpServletRequest request) {
Enumeration iterator = request.getHeaderNames();
UUID value = null;
while (iterator.hasMoreElements()) {
String header = iterator.nextElement();
if (header.toLowerCase().equals(RequestLog.PARENT_REQUEST_ID_HEADER.toLowerCase())) {
value = UUID.fromString(request.getHeader(header));
break;
}
}
return value;
}
public static UUID getRequestIdFromRequest(HttpServletRequest request) {
return getRequestIdFromRequest(request, false);
}
public static UUID getRequestIdFromRequest(HttpServletRequest request, boolean nullIfMissing) {
String value = getGatewayHeaderFromRequest(RequestLog.REQUEST_ID_HEADER, request);
if (value == null && !nullIfMissing) {
return UUID.randomUUID();
} else if (value == null) {
return null;
}
return UUID.fromString(value);
}
public static String getGatewayHeaderFromRequest(String gatewayHeader, HttpServletRequest request) {
Enumeration iterator = request.getHeaderNames();
String value = null;
while (iterator.hasMoreElements()) {
String header = iterator.nextElement();
if (header.toLowerCase().equals(gatewayHeader.toLowerCase())) {
value = request.getHeader(header);
break;
}
}
return value;
}
public static String coalese(String... paths) {
String result = "";
for (String path : paths) {
if (path != null && !path.trim().equals("")) {
result = path;
break;
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy