Skip to content

Instantly share code, notes, and snippets.

@dlabey
Created June 21, 2024 17:02
Show Gist options
  • Save dlabey/e0eea7f3f78d1a59447f5225761426f7 to your computer and use it in GitHub Desktop.
Save dlabey/e0eea7f3f78d1a59447f5225761426f7 to your computer and use it in GitHub Desktop.
Get Path Parameter
package com.sony.sie.payments.paas.apigateway;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public final class Utils {
private static final String PATH_SEPARATOR = "/";
private Utils() {
throw new IllegalStateException("Utility class");
}
public static String getPathParameter(String pathTemplate, String path, String paramTemplate) {
String pathTemplateDelimiter = Pattern.quote(paramTemplate);
String[] pathTemplatePieces = pathTemplate.split(pathTemplateDelimiter);
int pathTemplateSeparatorPosition = StringUtils.countMatches(pathTemplatePieces[0], PATH_SEPARATOR);
String[] pathPieces = path.split(PATH_SEPARATOR);
String param = null;
if (pathTemplateSeparatorPosition <= pathPieces.length) {
param = pathPieces[pathTemplateSeparatorPosition];
}
return param;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment