Java Code Examples for eu.bitwalker.useragentutils.Browser#getName()

The following examples show how to use eu.bitwalker.useragentutils.Browser#getName() . 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: UEMServiceGFHandler.java    From uavstack with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: UserAgentUtils.java    From momo-cloud-permission with Apache License 2.0 5 votes vote down vote up
/**
 * 获取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 3
Source File: HttpRequestUtil.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
/**
 * 获取系统设备类型信息
 * @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 4
Source File: HttpContextUtils.java    From plumemo with Apache License 2.0 5 votes vote down vote up
/**
 * 获取发起请求的浏览器名称
 */
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 5
Source File: BizCommentServiceImpl.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 保存当前评论时的设备信息
 *
 * @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 6
Source File: StringUtils.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
public static String getBrowser(HttpServletRequest request) {
    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    Browser browser = userAgent.getBrowser();
    return browser.getName();
}
 
Example 7
Source File: RequestListener.java    From Spring-Boot-Book with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: StringUtils.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public static String getBrowser(HttpServletRequest request){
    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    Browser browser = userAgent.getBrowser();
    return browser.getName();
}
 
Example 9
Source File: UserAgentAnalysis.java    From bbs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 解析
 * 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 10
Source File: StringUtils.java    From eladmin with Apache License 2.0 4 votes vote down vote up
public static String getBrowser(HttpServletRequest request) {
    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    Browser browser = userAgent.getBrowser();
    return browser.getName();
}