/** * Searches the group for a parser that can handle the specified <l>Content-Type</l> header value. * * <p> * The returned object includes both the parser and media type that matched. * * @param contentTypeHeader The HTTP <l>Content-Type</l> header value. * @return The parser and media type that matched the content type header, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(String contentTypeHeader) { ParserMatch pm = cache.get(contentTypeHeader); if (pm != null) return pm; ContentType ct = ContentType.forString(contentTypeHeader); int match = ct.findMatch(mediaTypes); if (match >= 0) { pm = new ParserMatch(mediaTypes[match], mediaTypeParsers[match]); cache.putIfAbsent(contentTypeHeader, pm); } return cache.get(contentTypeHeader); }
/** * Searches the group for a parser that can handle the specified <l>Content-Type</l> header value. * * <p> * The returned object includes both the parser and media type that matched. * * @param contentTypeHeader The HTTP <l>Content-Type</l> header value. * @return The parser and media type that matched the content type header, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(String contentTypeHeader) { ParserMatch pm = cache.get(contentTypeHeader); if (pm != null) return pm; ContentType ct = ContentType.forString(contentTypeHeader); int match = ct.findMatch(mediaTypes); if (match >= 0) { pm = new ParserMatch(mediaTypes[match], mediaTypeParsers[match]); cache.putIfAbsent(contentTypeHeader, pm); } return cache.get(contentTypeHeader); }
/** * Searches the group for a parser that can handle the specified <l>Content-Type</l> header value. * * <p> * The returned object includes both the parser and media type that matched. * * @param contentTypeHeader The HTTP <l>Content-Type</l> header value. * @return The parser and media type that matched the content type header, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(String contentTypeHeader) { ParserMatch pm = cache.get(contentTypeHeader); if (pm != null) return pm; ContentType ct = ContentType.forString(contentTypeHeader); int match = ct.findMatch(mediaTypes); if (match >= 0) { pm = new ParserMatch(mediaTypes[match], mediaTypeParsers[match]); cache.putIfAbsent(contentTypeHeader, pm); } return cache.get(contentTypeHeader); }
@Test public void test() throws Exception { ContentType ct = ContentType.forString(this.contentType); MediaType[] mt = JsonParser.DEFAULT.parse(mediaTypes, MediaType[].class); int r = ct.findMatch(mt); TestUtils.assertEquals(expected, r, "{0} failed", label); } }