eu.bitwalker.useragentutils.Browser Java Examples
The following examples show how to use
eu.bitwalker.useragentutils.Browser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoginController.java From MyShopPlus with Apache License 2.0 | 6 votes |
/** * 发送登录日志 * * @param request {@link HttpServletRequest} */ private void sendAdminLoginLog(String username, HttpServletRequest request) { UmsAdmin umsAdmin = umsAdminService.get(username); if (umsAdmin != null) { // 获取请求的用户代理信息 Browser browser = UserAgentUtils.getBrowser(request); String ip = UserAgentUtils.getIpAddr(request); String address = UserAgentUtils.getIpInfo(ip).getCity(); UmsAdminLoginLogDTO dto = new UmsAdminLoginLogDTO(); dto.setAdminId(umsAdmin.getId()); dto.setCreateTime(new Date()); dto.setIp(ip); dto.setAddress(address); dto.setUserAgent(browser.getName()); messageService.sendAdminLoginLog(dto); } }
Example #2
Source File: UEMServiceGFHandler.java From uavstack with Apache License 2.0 | 6 votes |
/** * getUA * * @param fdata * @param request */ private void getUA(StringBuilder fdata, HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); String bwrVersion = userAgent.getBrowserVersion().getMajorVersion(); Browser bwr = userAgent.getBrowser(); String bwrType = bwr.getBrowserType().getName(); String bwrName = bwr.getName(); String bwrEngine = bwr.getRenderingEngine().name(); fdata.append(bwrName).append(";"); fdata.append(bwrType).append(";"); fdata.append(bwrEngine).append(";"); fdata.append(bwrVersion).append(";"); OperatingSystem os = userAgent.getOperatingSystem(); String osName = os.getName(); String deType = os.getDeviceType().getName(); fdata.append(osName).append(";"); fdata.append(deType).append(";"); }
Example #3
Source File: URLUtil.java From boubei-tss with Apache License 2.0 | 6 votes |
public static String parseBrowser(String useragent) { useragent = (useragent + "").toLowerCase(); if(useragent.indexOf(browsers[0]) >= 0 && useragent.indexOf(browsers[1]) < 0) { // 微信客户端,注意区分QQ浏览器 return QQ_WX; } String origin = useragent; try { UserAgent userAgent = UserAgent.parseUserAgentString( useragent ); Browser browser = userAgent.getBrowser(); OperatingSystem opsys = userAgent.getOperatingSystem(); // 访问设备系统 Version browserVersion = userAgent.getBrowserVersion(); // 详细版本 String version = browserVersion.getMajorVersion(); // 浏览器主版本 origin = browser.getGroup().getName() + version + "-" + opsys; } catch(Exception e) { } for(String _b : browsers) { if(useragent.indexOf(_b) >= 0) { origin += "," + _b; break; } } return origin.toLowerCase(); }
Example #4
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取浏览器组: CHROME、IE * * @param request * @return */ public static String getBorderGroup(String userAgent) { Browser browser = getBrowser(userAgent); String browerGroup = browser.getGroup().getName(); logger.info("browerGroup is:{}", browerGroup); return browerGroup; }
Example #5
Source File: LogInterceptor.java From jboot-admin with Apache License 2.0 | 5 votes |
@Override public void intercept(Invocation inv) { if (inv.getController() instanceof BaseController) { BaseController c = (BaseController) inv.getController(); User user = AuthUtils.getLoginUser(); UserAgent userAgent = UserAgent.parseUserAgentString(c.getRequest().getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); Log log = new Log(); log.setUid(user.getId()); log.setBrowser(browser.getName()); log.setOperation(c.getRequest().getMethod()); log.setFrom(c.getReferer()); log.setIp(c.getIPAddress()); log.setUrl(c.getRequest().getRequestURI()); log.setCreateDate(new Date()); log.setLastUpdAcct(user.getId() == null ? "guest" : user.getName()); log.setLastUpdTime(new Date()); log.setNote("记录日志"); try { LogService logService = Jboot.service(LogService.class); logService.save(log); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } finally { inv.invoke(); } } else { inv.invoke(); } }
Example #6
Source File: HttpContextUtils.java From plumemo with Apache License 2.0 | 5 votes |
/** * 获取发起请求的浏览器版本号 */ public static String getBrowserVersion(HttpServletRequest request) { try{ String header = request.getHeader("User-Agent"); UserAgent userAgent = UserAgent.parseUserAgentString(header); Browser browser = userAgent.getBrowser();// 获取浏览器信息 Version version = browser.getVersion(header);// 获取浏览器版本号 return version.getVersion(); }catch (Exception e){ return "not found version"; } }
Example #7
Source File: HttpContextUtils.java From plumemo with Apache License 2.0 | 5 votes |
/** * 获取发起请求的浏览器名称 */ public static String getBrowserName(HttpServletRequest request) { try{ String header = request.getHeader("User-Agent"); UserAgent userAgent = UserAgent.parseUserAgentString(header); Browser browser = userAgent.getBrowser(); return browser.getName(); }catch (Exception e){ return "not found name"; } }
Example #8
Source File: HttpRequestUtil.java From charging_pile_cloud with MIT License | 5 votes |
/** * 获取系统设备类型信息 * @param request * @return */ public static String getSystemDevice(HttpServletRequest request){ String info = ""; try{ Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser(); //获取浏览器版本号 Version version = browser.getVersion(request.getHeader("User-Agent")); info = browser.getName() + "/" + version.getVersion(); }catch (Exception e){ log.info("获取系统设备信息失败:"+ ExceptionUtils.getStackTrace(e)); } return info; }
Example #9
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取浏览器版本 * * @param request * @return */ public static String getBrowserVersion(String userAgent) { Browser browser = getBrowser(userAgent); Version Version = browser.getVersion(userAgent); if (null == Version) { return ""; } return Version.getVersion(); }
Example #10
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取浏览器使用的渲染引擎 * * @param request * @return */ public static String getBorderRenderingEngine(String userAgent) { Browser browser = getBrowser(userAgent); String renderingEngine = browser.getRenderingEngine().name(); logger.info("renderingEngine is:{}", renderingEngine); return renderingEngine; }
Example #11
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取浏览器的生产厂商 * * @param request * @return */ public static String getBrowserManufacturer(String userAgent) { Browser browser = getBrowser(userAgent); String browserManufacturer = browser.getManufacturer().getName(); logger.info("browserManufacturer is:{}", browserManufacturer); return browserManufacturer; }
Example #12
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取浏览器的类型 * * @param request * @return */ public static String getBorderType(String userAgent) { Browser browser = getBrowser(userAgent); String borderType = browser.getBrowserType().getName(); logger.info("borderType is:{}", borderType); return borderType; }
Example #13
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 5 votes |
/** * 获取browser name * * @param request * @return */ public static String getBorderName(String userAgent) { Browser browser = getBrowser(userAgent); String borderName = browser.getName(); logger.info("borderName is:{}", borderName); return borderName; }
Example #14
Source File: BizCommentServiceImpl.java From OneBlog with GNU General Public License v3.0 | 5 votes |
/** * 保存当前评论时的设备信息 * * @param comment */ private void setCurrentDeviceInfo(Comment comment) { String ua = RequestUtil.getUa(); UserAgent agent = UserAgent.parseUserAgentString(ua); Browser browser = agent.getBrowser(); String browserInfo = browser.getName(); Version version = agent.getBrowserVersion(); if (version != null) { browserInfo += " " + version.getVersion(); } comment.setBrowser(browserInfo); OperatingSystem os = agent.getOperatingSystem(); comment.setOs(os.getName()); comment.setIp(RequestUtil.getIp()); }
Example #15
Source File: UserAgent.java From proctor with Apache License 2.0 | 4 votes |
@Nonnull public Browser getBrowser() { return userAgent.getBrowser(); }
Example #16
Source File: StringUtils.java From eladmin with Apache License 2.0 | 4 votes |
public static String getBrowser(HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); return browser.getName(); }
Example #17
Source File: UserAgentUtils.java From Shop-for-JavaWeb with MIT License | 4 votes |
/** * 是否IE版本是否小于等于IE8 * @param request * @return */ public static boolean isLteIE8(HttpServletRequest request){ Browser browser = getBrowser(request); return Browser.IE5.equals(browser) || Browser.IE6.equals(browser) || Browser.IE7.equals(browser) || Browser.IE8.equals(browser); }
Example #18
Source File: StringUtils.java From sk-admin with Apache License 2.0 | 4 votes |
public static String getBrowser(HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); return browser.getName(); }
Example #19
Source File: UserAgentAnalysis.java From bbs with GNU Affero General Public License v3.0 | 4 votes |
/** * 解析 * String ua = request.getHeader("User-Agent"); * @param ua 请求头字段包含有关发起请求的用户代理的信息 */ public static AccessInfo analysis(String ua){ if(ua != null && !"".equals(ua.trim())){ //转成UserAgent对象 UserAgent userAgent = UserAgent.parseUserAgentString(ua); if(userAgent != null){ AccessInfo accessInfo = new AccessInfo(); //获取浏览器信息 Browser browser = userAgent.getBrowser(); if(browser != null){ String browserName = browser.getName();// 浏览器名称 accessInfo.setBrowserName(browserName);//浏览器名称 if(browser.getGroup() != null){ String group = browser.getGroup().getName();// 浏览器大类 accessInfo.setGroup(group);//浏览器大类 } } Version browserVersion = userAgent.getBrowserVersion();// 详细版本 if(browserVersion != null){ String version = browserVersion.getMajorVersion();// 浏览器主版本 accessInfo.setBrowserVersion(browserVersion.getVersion());//详细版本 accessInfo.setVersion(version);//浏览器主版本 } // System.out.println("浏览器名称 "+browserName); // System.out.println("浏览器大类 "+group); // System.out.println("详细版本 "+browserVersion); // System.out.println("浏览器主版本 "+version); // System.out.println("访问设备系统 "+userAgent.getOperatingSystem());// 访问设备系统 //系统名称 // String system = userAgent.getOperatingSystem().getName(); // System.out.println("访问设备类型 "+userAgent.getOperatingSystem().getDeviceType());// 访问设备类型 // System.out.println("访问设备制造厂商 "+userAgent.getOperatingSystem().getManufacturer());// 访问设备制造厂商 if(userAgent.getOperatingSystem() != null){ accessInfo.setOperatingSystem(userAgent.getOperatingSystem().toString());//访问设备系统 if(userAgent.getOperatingSystem().getDeviceType() != null && userAgent.getOperatingSystem().getDeviceType().getName() != null){ if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Computer")){ accessInfo.setDeviceType("电脑");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Mobile")){ accessInfo.setDeviceType("手机");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Tablet")){ accessInfo.setDeviceType("平板");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Game console")){ accessInfo.setDeviceType("游戏机");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Digital media receiver")){ accessInfo.setDeviceType("数字媒体接收器");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Wearable computer")){ accessInfo.setDeviceType("可穿戴设备");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Unknown")){ accessInfo.setDeviceType("未知设备");//访问设备类型 } } } return accessInfo; } } return null; }
Example #20
Source File: StringUtils.java From yshopmall with Apache License 2.0 | 4 votes |
public static String getBrowser(HttpServletRequest request){ UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); return browser.getName(); }
Example #21
Source File: UserAgentUtils.java From frpMgr with MIT License | 4 votes |
/** * 是否IE版本是否小于等于IE8 * @param request * @return */ public static boolean isLteIE8(HttpServletRequest request){ Browser browser = getBrowser(request); return Browser.IE5.equals(browser) || Browser.IE6.equals(browser) || Browser.IE7.equals(browser) || Browser.IE8.equals(browser); }
Example #22
Source File: RequestListener.java From Spring-Boot-Book with Apache License 2.0 | 4 votes |
@Override public void requestDestroyed(ServletRequestEvent arg0) { System.out.println("监听器初始化..."); Integer count = null;//请求数量 Object requestCount = arg0.getServletContext().getAttribute("requestCount"); if (requestCount == null) { count = 0; } else { count = Integer.valueOf(requestCount.toString()); } count++; System.out.println("当前请求数:" + count.toString()); arg0.getServletContext().setAttribute("requestCount", count); /*用户信息*/ /*用户信息*/ HttpServletRequest servletRequest = (HttpServletRequest) arg0.getServletRequest(); //requestURL String requestURL = servletRequest.getRequestURL().toString(); //queryString String queryString = servletRequest.getQueryString(); RequestLog requestLog = new RequestLog(); requestLog.setIpaddr(IpUtils.getIpAddr(servletRequest)); requestLog.setSessionId(servletRequest.getRequestedSessionId()); requestLog.setReferer(servletRequest.getHeader("Referer")); requestLog.setAccept(servletRequest.getHeader("accept")); requestLog.setMethod(servletRequest.getMethod()); requestLog.setUrl(requestURL); requestLog.setQuerystring(queryString); /*UserAgent 工具类*/ UserAgent userAgent = UserAgent.parseUserAgentString(servletRequest.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); Version version = browser.getVersion(servletRequest.getHeader("User-Agent")); String browserInfo = null; try { browserInfo = browser.getName() + "/" + version.getVersion(); } catch (Exception e) { e.printStackTrace(); } OperatingSystem os = userAgent.getOperatingSystem(); /*UserAgent 工具类*/ requestLog.setOs(os.getName()); requestLog.setBrowser(browserInfo); requestLog.setCreationTimes(System.currentTimeMillis()); /* SecurityContextImpl securityContextImpl = (SecurityContextImpl) servletRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT"); requestLog.setLoginName( securityContextImpl.getAuthentication().getName());*/ requestLogRepository.save(requestLog); }
Example #23
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 2 votes |
/** * 获取浏览器对象 * * @param request * @return */ public static Browser getBrowser(String agent) { UserAgent userAgent = UserAgent.parseUserAgentString(agent); Browser browser = userAgent.getBrowser(); return browser; }
Example #24
Source File: UserAgentUtils.java From frpMgr with MIT License | 2 votes |
/** * 获取浏览类型 * @param request * @return */ public static Browser getBrowser(HttpServletRequest request){ return getUserAgent(request).getBrowser(); }
Example #25
Source File: UserAgentUtils.java From Shop-for-JavaWeb with MIT License | 2 votes |
/** * 获取浏览类型 * @param request * @return */ public static Browser getBrowser(HttpServletRequest request){ return getUserAgent(request).getBrowser(); }
Example #26
Source File: UserAgentUtils.java From MyShopPlus with Apache License 2.0 | 2 votes |
/** * 获取用户浏览器 * * @param request {@link HttpServletRequest} * @return {@link Browser} */ public static Browser getBrowser(HttpServletRequest request) { return getUserAgent(request).getBrowser(); }