DispatchCriteriaHelper { public static String extractFromURIParams(String paramsRule, String uri){ Map<String, String> criteriaMap = new TreeMap<String, String>(); if (uri.contains("?") && uri.contains("=")) { String parameters = uri.substring(uri.indexOf("?") + 1); for (String parameter : parameters.split("&")){ String[] pair = parameter.split("="); try { String key = URLDecoder.decode(pair[0], "UTF-8"); String value = URLDecoder.decode(pair[1], "UTF-8"); criteriaMap.put(key, value); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } StringBuilder result = new StringBuilder(); for (String criteria : criteriaMap.keySet()){ if (paramsRule.contains(criteria)) { result.append("?").append(criteria).append("=").append(criteriaMap.get(criteria)); } } return result.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 testExtractFromURIParams(){ String requestPath = "/v2/pet/findByDate/2017/01/04?user_key=998bac0775b1d5f588e0a6ca7c11b852&status=available"; String dispatchCriteria = DispatchCriteriaHelper.extractFromURIParams("user_key", requestPath); assertEquals("?user_key=998bac0775b1d5f588e0a6ca7c11b852", dispatchCriteria); dispatchCriteria = DispatchCriteriaHelper.extractFromURIParams("user_key && status", requestPath); assertEquals("?status=available?user_key=998bac0775b1d5f588e0a6ca7c11b852", dispatchCriteria); }