/** * Returns the <code>Accept</code> header on the request. * * <p> * Content-Types that are acceptable for the response. * * <h5 class='figure'>Example:</h5> * <p class='bcode w800'> * Accept: text/plain * </p> * * @return The parsed <code>Accept</code> header on the request, or <jk>null</jk> if not found. */ public Accept getAccept() { return Accept.forString(getString("Accept")); }
/** * Returns the <code>Accept</code> header on the request. * * <p> * Content-Types that are acceptable for the response. * * <h5 class='figure'>Example:</h5> * <p class='bcode w800'> * Accept: text/plain * </p> * * @return The parsed <code>Accept</code> header on the request, or <jk>null</jk> if not found. */ public Accept getAccept() { return Accept.forString(getString("Accept")); }
/** * Returns the <code>Accept</code> header on the request. * * <p> * Content-Types that are acceptable for the response. * * <h5 class='figure'>Example:</h5> * <p class='bcode w800'> * Accept: text/plain * </p> * * @return The parsed <code>Accept</code> header on the request, or <jk>null</jk> if not found. */ public Accept getAccept() { return Accept.forString(getString("Accept")); }
return sm; Accept a = Accept.forString(acceptHeader); int match = a.findMatch(mediaTypeRanges); if (match >= 0) {
return sm; Accept a = Accept.forString(acceptHeader); int match = a.findMatch(mediaTypeRanges); if (match >= 0) {
return sm; Accept a = Accept.forString(acceptHeader); int match = a.findMatch(mediaTypeRanges); if (match >= 0) {
@Test public void testReversed() throws Exception { Accept accept = Accept.forString(this.accept); MediaType[] mt = JsonParser.DEFAULT.parse(mediaTypes, MediaType[].class); Collections.reverse(Arrays.asList(mt)); int r = accept.findMatch(mt); int expected2 = expectedReverse == -1 ? -1 : mt.length-expectedReverse-1; TestUtils.assertEquals(expected2, r, "{0} failed", label); } }
@Test public void test() throws Exception { Accept accept = Accept.forString(this.accept); MediaType[] mt = JsonParser.DEFAULT.parse(mediaTypes, MediaType[].class); int r = accept.findMatch(mt); TestUtils.assertEquals(expected, r, "{0} failed", label); }
@Test public void testHasSubtypePart() { Accept accept = Accept.forString("text/json+x,text/foo+y;q=0.0"); assertTrue(accept.hasSubtypePart("json")); assertTrue(accept.hasSubtypePart("x")); assertFalse(accept.hasSubtypePart("foo")); assertFalse(accept.hasSubtypePart("y")); } }
accept = Accept.forString("text/json"); mr = accept.asRanges().get(0); assertTextEquals("text/json", mr); accept = Accept.forString("foo,bar"); mr = accept.asRanges().get(0); assertTextEquals("foo", mr); accept = Accept.forString(" foo , bar "); mr = accept.asRanges().get(0); assertTextEquals("foo", mr); accept = Accept.forString("text/json;a=1;q=0.9;b=2"); mr = accept.asRanges().get(0); assertTextEquals("text/json;a=1;q=0.9;b=2", mr); accept = Accept.forString("text/json;a=1;a=2;q=0.9;b=3;b=4"); mr = accept.asRanges().get(0); assertTextEquals("text/json;a=1;a=2;q=0.9;b=3;b=4", mr); accept = Accept.forString("text/json;a=1"); mr = accept.asRanges().get(0); assertTextEquals("text/json;a=1", mr); accept = Accept.forString("text/json;a=1;"); mr = accept.asRanges().get(0); assertTextEquals("text/json;a=1", mr); accept = Accept.forString("text/json;q=0.9");