Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Java libraries do HTTP Accept Header Parsing? [closed]

Which Java libraries parse HTTP Accept header?

like image 901
yegor256 Avatar asked Oct 09 '11 19:10

yegor256


2 Answers

You should read this article : http://www.xml.com/pub/a/2005/06/08/restful.html

The article uses Python but it's not a problem : at the end, the following link is shared : http://code.google.com/p/mimeparse

As you can see, "mimeparse" is :

Basic functions for handling mime-types in Erlang, JavaScript, Perl, PHP, Python, Ruby, Java

According to the home page :

List<String> mimeTypesSupported = Arrays.asList(StringUtils.split(
            "application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");
like image 77
Sandro Munda Avatar answered Oct 17 '22 05:10

Sandro Munda


Have a look at the HttpClient Util.parseHeader method.


Edit: (trying to make this answer worth being accepted post-factum)

The spring framework provides this functionality within its MediaType component.

If you are already using Spring MVC you can simply request for a @RequestHeader-annotated parameter of type HttpHeaders and access the list of accepted media types by simply calling HttpHeaders.getAccept().

like image 23
Costi Ciudatu Avatar answered Oct 17 '22 05:10

Costi Ciudatu