本文整理汇总了Java中net.sf.uadetector.ReadableUserAgent类的典型用法代码示例。如果您正苦于以下问题:Java ReadableUserAgent类的具体用法?Java ReadableUserAgent怎么用?Java ReadableUserAgent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadableUserAgent类属于net.sf.uadetector包,在下文中一共展示了ReadableUserAgent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
List<String> keys = !configuration.getKeys().isEmpty() ? configuration.getKeys() : singletonList(DEFAULT_KEY);
if (request instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String userAgentString = httpServletRequest.getHeader("User-Agent");
ReadableUserAgent userAgent = userAgentParser.parseUserAgentString(userAgentString);
keys.stream()
.map(key -> evaluatePattern(userAgent, key, httpServletRequest))
.map(this::formatKey)
.map(key -> COUNTER_PREFIX + key)
.forEach(counterService::increment);
}
}
开发者ID:lukashinsch,项目名称:spring-boot-actuator-user-agent-metrics,代码行数:19,代码来源:UserAgentMetricFilter.java
示例2: it_should_resolved_arguments_with_correct_class
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Test
public void it_should_resolved_arguments_with_correct_class() throws Exception {
Class klass = ReadableUserAgent.class;
when(methodParameter.getParameterType()).thenReturn(klass);
String userAgent = "foo";
when(nativeWebRequest.getHeader("User-Agent")).thenReturn(userAgent);
when(parser.parse(userAgent)).thenReturn(readableUserAgent);
Object argument = readableUserAgentResolver.resolveArgument(methodParameter, nativeWebRequest);
assertThat(argument)
.isNotNull()
.isSameAs(readableUserAgent);
verify(methodParameter).getParameterType();
verify(nativeWebRequest).getHeader("User-Agent");
verify(parser).parse(userAgent);
}
示例3: it_should_parse_value_once
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Test
public void it_should_parse_value_once() throws Exception {
String ua = "foo";
when(parser.parse(ua)).thenReturn(userAgent);
EhCacheCache cache = new EhCacheCache(ehCache, parser);
ReadableUserAgent r1 = cache.get("foo");
ReadableUserAgent r2 = cache.get("foo");
Ehcache internalCache = (Ehcache) readField(cache, "cache", true);
assertThat(internalCache.getSize()).isNotZero().isEqualTo(1);
assertThat(r1).isNotNull().isSameAs(r2).isSameAs(userAgent);
verify(parser, times(1)).parse(ua);
}
示例4: it_should_parse_user_agent
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Test
public void it_should_parse_user_agent() throws Exception {
String userAgent = "foo";
when(request.getHeader("User-Agent")).thenReturn(userAgent);
when(parser.parse(userAgent)).thenReturn(readableUserAgent);
Object object = readableUserAgentFactoryBean.getObject();
assertThat(object)
.isNotNull()
.isInstanceOf(ReadableUserAgent.class)
.isSameAs(readableUserAgent);
verify(request).getHeader("User-Agent");
verify(parser).parse(userAgent);
}
示例5: onAuthenticationSuccess
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
final String userAgent = getUserAgent(request);
ListenableFuture<String> future = service.submit(() -> {
ReadableUserAgent ua = parser.parse(userAgent);
String key = "NA";
if(ua != null) {
String browser = ua.getName();
logger.info("login user agent is {}", browser);
SpringUserDetails user = (SpringUserDetails) authentication.getPrincipal();
logger.info("login user id: {}", user.getUserId());
}
return key;
});
Futures.addCallback(future, new FutureCallback<String>() {
@Override public void onSuccess(String s) {
if(s != null && !s.equals("NA")) {
logger.info("successfully log metric: {}", s);
}
}
@Override public void onFailure(Throwable throwable) {
logger.error("Failed to log metric", throwable);
}
});
super.onAuthenticationSuccess(request, response, authentication);
}
示例6: parseUserAgent
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
private static void parseUserAgent(XmTimeline timeline) {
if (MapUtils.isNotEmpty(timeline.getRequestHeaders())) {
String ua = timeline.getRequestHeaders().get("user-agent");
if (StringUtils.isNotBlank(ua)) {
ReadableUserAgent agent = parser.parse(ua);
timeline.setBrowser(agent.getName() + " " + agent.getVersionNumber().toVersionString());
timeline.setOpSystem(agent.getOperatingSystem().getName() + " "
+ agent.getOperatingSystem().getVersionNumber().toVersionString());
}
}
}
示例7: setUserAgent
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
private void setUserAgent () {
try {
final String userAgent = this.header.getUserAgent();
if (StringObjectUtils.isValid(userAgent)) {
final ReadableUserAgent agent = UA_PARSER.parse(userAgent);
this.setUserBrower(agent);
this.setUserOs(agent);
this.setUserDevice(agent);
}
} catch (Exception ex) {
ES_CONSUMER_LOGGER.error("Sorry. parsing failed. ("+ex.toString()+")");
}
}
示例8: setUserBrower
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
private void setUserBrower (final ReadableUserAgent agent) {
this.clientBrower = new HashMap<String, String>();
this.clientBrower.put("browserType", agent.getType().getName());
this.clientBrower.put("browserName", agent.getName());
final VersionNumber browserVersion = agent.getVersionNumber();
this.clientBrower.put("browserVersion", browserVersion.toVersionString());
this.clientBrower.put("browserVersionMajor", browserVersion.getMajor());
this.clientBrower.put("browserVersionMinor", browserVersion.getMinor());
this.clientBrower.put("browserVersionBugFix", browserVersion.getBugfix());
this.clientBrower.put("browserVersionExtension", browserVersion.getExtension());
this.clientBrower.put("browserProducer", agent.getProducer());
}
示例9: setUserOs
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
private void setUserOs (final ReadableUserAgent agent) {
this.clientOs = new HashMap<String, String>();
final OperatingSystem os = agent.getOperatingSystem();
this.clientOs.put("osName", os.getName());
this.clientOs.put("osProducer", os.getProducer());
final VersionNumber osVersion = os.getVersionNumber();
this.clientOs.put("osVersion", osVersion.toVersionString());
this.clientOs.put("osVersionMajor", osVersion.getMajor());
this.clientOs.put("osVersionMinor", osVersion.getMinor());
this.clientOs.put("osVersionBugFix", osVersion.getBugfix());
this.clientOs.put("osVersionExtension", osVersion.getExtension());
}
示例10: parse
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Override
public ReadableUserAgent parse(final String userAgentString)
{
ReadableUserAgent result = cache.getIfPresent(userAgentString);
if (result == null) {
result = parser.parse(userAgentString);
cache.put(userAgentString, result);
}
return result;
}
示例11: extractInformation
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@Override
public Map<String, Object> extractInformation(Object value)
{
Map<String, Object> m = new HashMap<String, Object>();
ReadableUserAgent agent = parser.parse(value.toString());
m.put("browser", agent.getName());
m.put("os", agent.getOperatingSystem().getName());
return m;
}
示例12: main
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
public static void main(String[] args) {
String userAgentString = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101 Firefox/41.0";
ReadableUserAgent userAgent = getUADetectorExample(userAgentString);
System.out.println(userAgent);
UserAgent userAgent2 = UserAgent.parseUserAgentString(userAgentString);
System.out.println(userAgent2);
}
示例13: connect
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
@WampCallListener("connect")
public void connect(CallMessage callMessage, UserConnection newUser) {
ReadableUserAgent ua = this.parser.parse(newUser.getBrowser());
if (ua != null) {
newUser.setBrowser(ua.getName() + " " + ua.getVersionNumber().getMajor());
}
newUser.setSessionId(callMessage.getWebSocketSessionId());
this.socketIdToUserMap.put(callMessage.getWebSocketSessionId(), newUser);
this.eventMessenger.sendToAll("connected", newUser);
}
示例14: parseUserAgent
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
private void parseUserAgent(final Requests request) {
final String agentString = request.getUserAgent();
userAgents.put(agentString);
if (agentString != null) {
final ReadableUserAgent agent = uaParser.parse(agentString);
browsers.put(agent.getName());
os.put(agent.getOperatingSystem().getName());
}
}
示例15: Browser
import net.sf.uadetector.ReadableUserAgent; //导入依赖的package包/类
/**
* Create browser object.
*/
public Browser() {
Optional<String> userAgent = BaseUITest.getUserAgent();
if (userAgent.isPresent() && !userAgent.get().isEmpty()) {
// Try to parse the UA
UserAgentStringParser uaParser = UADetectorServiceFactory.getResourceModuleParser();
ReadableUserAgent agent = uaParser.parse(userAgent.get());
// Set the params based on this agent
this.name = agent.getName();
this.version = agent.getVersionNumber().toVersionString();
this.device = agent.getDeviceCategory().getName();
this.platform = agent.getOperatingSystem().getName();
this.platformVersion = agent.getOperatingSystem().getVersionNumber().toVersionString();
} else {
// Fall-back to the Property class
if (BROWSER.isSpecified()) {
this.name = BROWSER.getValue().toLowerCase();
} else {
this.name = DriverSetup.DEFAULT_BROWSER.toString();
}
if (BROWSER_VERSION.isSpecified()) {
this.version = BROWSER_VERSION.getValue();
}
if (DEVICE.isSpecified()) {
this.device = DEVICE.getValue();
}
if (PLATFORM.isSpecified()) {
this.platform = PLATFORM.getValue();
}
if (PLATFORM_VERSION.isSpecified()) {
this.platformVersion = PLATFORM_VERSION.getValue();
}
}
}