@Test public void testExtractAcceptHeaders() throws Exception { List<String> result = RestUtil.extractAcceptHeaders("application/atom+xml, application/xml"); Assert.assertEquals(2, result.size()); Assert.assertEquals("application/atom+xml", result.get(0)); Assert.assertEquals("application/xml", result.get(1)); result = RestUtil.extractAcceptHeaders("application/atom+xml, application/xml"); Assert.assertEquals(2, result.size()); Assert.assertEquals("application/atom+xml", result.get(0)); Assert.assertEquals("application/xml", result.get(1)); result = RestUtil.extractAcceptHeaders( "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,**", result.get(4)); }
public static List<String> extractAcceptHeaders(final String acceptHeader) { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); if (acceptHeader != null && !acceptHeader.isEmpty()) { List<String> list = Arrays.asList(acceptHeader.split(REG_EX_FIELD_VALUE_SEPARATOR)); for (String accept : list) { Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept); if (matcher.find()) { String headerValue = matcher.group(1); double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d; acceptTree.add(new Accept(headerValue, qualityFactor)); } } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } return acceptHeaders; }
RestUtil { public static List<String> extractAcceptHeaders(final String acceptHeader) { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); if (acceptHeader != null && !acceptHeader.isEmpty()) { List<String> list = Arrays.asList(acceptHeader.split(REG_EX_FIELD_VALUE_SEPARATOR)); for (String accept : list) { Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept); if (matcher.find()) { String headerValue = matcher.group(1); double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d; acceptTree.add(new Accept(headerValue, qualityFactor)); } } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } return acceptHeaders; } }
RestUtil { public static List<String> extractAcceptHeaders(final String acceptHeader) { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); if (acceptHeader != null && !acceptHeader.isEmpty()) { List<String> list = Arrays.asList(acceptHeader.split(REG_EX_FIELD_VALUE_SEPARATOR)); for (String accept : list) { Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept); if (matcher.find()) { String headerValue = matcher.group(1); double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d; acceptTree.add(new Accept(headerValue, qualityFactor)); } } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } return acceptHeaders; }  }
RestUtil { public static List<String> extractAcceptHeaders(final String acceptHeader) { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); if (acceptHeader != null && !acceptHeader.isEmpty()) { List<String> list = Arrays.asList(acceptHeader.split(REG_EX_FIELD_VALUE_SEPARATOR)); for (String accept : list) { Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept); if (matcher.find()) { String headerValue = matcher.group(1); double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d; acceptTree.add(new Accept(headerValue, qualityFactor)); } } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } return acceptHeaders; }  static ContentType extractRequestContentType(final String contentType); static Map<String, String> extractQueryParameters(final String queryString); static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding); static List<Locale> extractAcceptableLanguage(final String acceptableLanguageHeader); static List<String> extractAcceptHeaders(final String acceptHeader); @SuppressWarnings("unchecked") static Map<String, List<String>> extractHeaders(final HttpServletRequest req); static PathInfo buildODataPathInfo(final HttpServletRequest req, final int pathSplit); }
RestUtil { public static List<String> extractAcceptHeaders(final String acceptHeader) { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); if (acceptHeader != null && !acceptHeader.isEmpty()) { List<String> list = Arrays.asList(acceptHeader.split(REG_EX_FIELD_VALUE_SEPARATOR)); for (String accept : list) { Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept); if (matcher.find()) { String headerValue = matcher.group(1); double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d; acceptTree.add(new Accept(headerValue, qualityFactor)); } } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } return acceptHeaders; }  static ContentType extractRequestContentType(final String contentType); static Map<String, String> extractQueryParameters(final String queryString); static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding); static List<Locale> extractAcceptableLanguage(final String acceptableLanguageHeader); static List<String> extractAcceptHeaders(final String acceptHeader); @SuppressWarnings("unchecked") static Map<String, List<String>> extractHeaders(final HttpServletRequest req); static PathInfo buildODataPathInfo(final HttpServletRequest req, final int pathSplit);  }