DispatchCriteriaHelper { public static String extractPartsFromURIPattern(String pattern){ if (pattern.contains("?")) { pattern = pattern.substring(0, pattern.indexOf('?')); } if (pattern.contains("{{") && pattern.contains("}}")) { pattern = pattern.replaceAll("\\{\\{", ""); pattern = pattern.replaceAll("\\}\\}", ""); } String partsPattern = null; if (pattern.contains("/{")) { partsPattern = pattern.replaceAll("(\\{[^\\}]+\\})", "\\\\{(.+)\\\\}"); } else if (pattern.contains("/:")) { partsPattern = pattern.replaceAll("(/:[^:^/]+)", "\\/:(.+)"); } if (partsPattern != null) { Pattern partsP = Pattern.compile(partsPattern); Matcher partsM = partsP.matcher(pattern); if (partsM.matches()) { StringBuilder parts = new StringBuilder(); for (int i = 1; i < partsM.groupCount() + 1; i++) { parts.append(partsM.group(i)); if (i < partsM.groupCount()) { parts.append(" && "); } } return parts.toString(); } } return ""; }  static String extractParamsFromURI(String uri); static String extractCommonPrefix(List<String> uris); static String extractCommonSuffix(List<String> uris); static String extractPartsFromURIs(List<String> uris); static String extractPartsFromURIPattern(String pattern); static String extractFromURIPattern(String pattern, String realURI); static String buildFromPartsMap(Map<String, String> partsMap); static String buildFromParamsMap(String paramsRule, Map<String, String> paramsMap); static String extractFromURIParams(String paramsRule, String uri);  }
@Test public void testExtractPartsFromURIPattern(){ String operationName = "/deployment/byComponent/{component}/{version}?{{param}}"; String dispatchCriteria = DispatchCriteriaHelper.extractPartsFromURIPattern(operationName); assertEquals("component && version", dispatchCriteria); }