• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

parsing the user-agent to get OS version

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I need to get the OS version and Browser Version from the user-agent HTTP header. Is there any standard API which should parse it and return? One more question. What is OS_TEXT, OS_CODE, BROWSER_TEXT, BROWSER_CODE in this context?

Thanks for your suggestions,

Mahendran
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.servlet.http.HttpServletRequest contains methods to get the headers. Not sure what those values are, where did you come accross them?
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Through HttpServletRequest I could only get the user agent string, But I require browser version and os version which any way is part of user_agent. But my question is there any method which will return something like this



Thanks,
Mahendran.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. But if you have the User-Agent header you've got all you need don't you? The HTTP specification only requires a list of product/product-version tokens, it doesn't specify what those should be so there is nothing the Servlet specification can do to parse it.
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Is there any other standard API other than Servlet specification to do the parsing and return accordingly(Browser Version, Os Version etc)?

Thanks,
Mahendran.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be utility classes out there - I don't know any.

This may be a futile excercise anyway since some browsers do not follow the standard and others deliberately spoof this header (Opera for example can be configured to pretend it is IE). Why do you need to know the browser? What do you need to do with this information?
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

In the database there is field to store the browser version, os version. I have requested to fill that data. That's it. No idea about why are we storing it.

Thanks,
Mahendran
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which case could you not just change the database table and store the contents of the User-Agent header itself? Then whatever needs to report on this can do the logic to workout what the data means.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest to find out why this is done. Knowing that generally allows someone to make more intelligent decisions about their work.

Much good information on the subject of browser detection can be found at http://www.texsoft.it/index.php?c=software&m=sw.php.useragent&l=it, and if you search for "java browser detection source code" or something like that I'm sure you can find lots of ready-to-use code.
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul and Ulf,

Is this looks alright?



Thanks,
Mahendran.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks waaaaaaay obsolete. No Firefox? No IE 7 and 8? No XP? No Opera? No Safari? No Vista? And who cares about Netscape 4.0 vs. Netscape 4.7 these days?

Also note that the UA string can contain both "MSIE 5" and "Mozilla", a case not being handled by that code.

I can only repeat: You need to understand WHY this information is being collected; only then can you make informed decisions about what is and is not important.

Paul's suggestion also is a good one. If you save the UA string in full, then you can later dissect it as required (even as the requirements, and your understanding of UA strings, changes) in addition to doing any analysis on the spot.
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

Currently I am handling those missing as you pointed out. But I will get more information regarding this and I will ask to make a database change if possible.

Thanks,
Mahendran.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For benefit of others, here is what I found up to date as per todays browser needs. Still doesnt talk about the OS and other details but I guess can be built.
Detecting User-agent for a browser

Have you seen Google Analytics report about the type of browsers and Operating systems accessing a web page. Thats possibly one of the reasons why you would want to store user-agent.

We are also storing user-agent for similar statistics, it gives more details about the type of users accessing your web site and based on that you can decide some future strategies.

I hope this helps.
 
Priyanka Dandekar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing I forgot to mention is, we are storing the User-agent field in a single database field. The logic for parsing the different field values need not be their on the storing application as their can be many applications logging the same information . Only the reporting module needs to be able to understand and parse the user-agent.

Imagine a scenario when you have used this in 5 different applications and a new browser version comes up. If the logic of parsing is present on reporting side then you need to just upgrade the reporting module not all 5 applications.

 
reply
    Bookmark Topic Watch Topic
  • New Topic