HttpServletRequest#getHeader("User-Agent") returns null browser name
String browserName = requestProvider.get().getHeader("User-Agent");
null
means whoever sent the request didn't include a "User-Agent" header.
String ipAdd = requestProvider.get().getRemoteAddr();
is unlikely to return null under normal circumstances, but there are reports the it may do so in edge cases, like after the response has already been sent. Regardless, "get IP address of the machine on which my application is running" doesn't sound like what getRemoteAddr()
is for. It's for getting the address of the most recent client or proxy that sent the request.
Is there any alternate way to get IP address & browser name every time?
No. You're entirely dependent on the behavior of the HTTP client and/or any intervening proxies to get information like this.