use of net.sf.uadetector.ReadableUserAgent in project ART-TIME by Artezio.
the class CheckSupportedBrowsersFilterTest method testParseUserAgent_ifHeaderParamUserAgentIsEmpty.
@Test
public void testParseUserAgent_ifHeaderParamUserAgentIsEmpty() {
expect(request.getHeader("User-Agent")).andReturn("");
replay(request);
ReadableUserAgent actual = filter.parseUserAgent(request);
verify(request);
assertSame(UserAgent.EMPTY, actual);
}
use of net.sf.uadetector.ReadableUserAgent in project apex-malhar by apache.
the class UserAgentExtractor method extractInformation.
@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;
}
use of net.sf.uadetector.ReadableUserAgent in project cryptonomica by Cryptonomica.
the class UserTools method registerLogin.
// end of ensureGoogleAuth method
public static Login registerLogin(final HttpServletRequest httpServletRequest, final User googleUser) {
// Register login of this Cryptonomica User:
Login login = new Login();
// IP
String userIP = httpServletRequest.getHeader("X-FORWARDED-FOR");
if (userIP == null) {
userIP = httpServletRequest.getRemoteAddr();
}
// Get an UserAgentStringParser and analyze the requesting client
// see example on: http://uadetector.sourceforge.net/usage.html
UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
ReadableUserAgent agent = parser.parse(httpServletRequest.getHeader("User-Agent"));
String userBrowser = agent.getName();
String userOS = agent.getOperatingSystem().getName();
//
String userProviderOrg = null;
String userProviderHost = null;
String country = null;
String region = null;
String city = null;
JSONObject ipInfoIoJSON = GetJSONfromURL.getIpInfoIo(userIP);
if (ipInfoIoJSON != null) {
try {
userProviderOrg = ipInfoIoJSON.getString("org");
} catch (JSONException e) {
userProviderOrg = e.getMessage();
}
try {
userProviderHost = ipInfoIoJSON.getString("hostname");
} catch (JSONException e) {
userProviderHost = e.getMessage();
}
try {
country = ipInfoIoJSON.getString("country");
} catch (JSONException e) {
country = e.getMessage();
}
try {
region = ipInfoIoJSON.getString("region");
} catch (JSONException e) {
region = e.getMessage();
}
try {
city = ipInfoIoJSON.getString("city");
} catch (JSONException e) {
city = e.getMessage();
}
}
login.setCryptonomicaUserKey(Key.create(CryptonomicaUser.class, googleUser.getUserId()));
login.setLoginEmail(new Email(googleUser.getEmail()));
login.setLoginDate(new Date());
login.setIP(userIP);
login.setUserBrowser(userBrowser);
login.setUserOS(userOS);
login.setHostname(userProviderHost);
login.setCity(city);
login.setRegion(region);
login.setCountry(country);
login.setProvider(userProviderOrg);
// --- save Login:
Key<Login> loginKey = ofy().save().entity(login).now();
login = ofy().load().key(loginKey).now();
return login;
}
use of net.sf.uadetector.ReadableUserAgent in project ART-TIME by Artezio.
the class CheckSupportedBrowsersFilterTest method testParseUserAgent.
@Test
public void testParseUserAgent() {
UserAgentStringParser parser = createMock(UserAgentStringParser.class);
PowerMock.mockStatic(UADetectorServiceFactory.class);
expect(request.getHeader("User-Agent")).andReturn("Mozilla/5.0");
expect(UADetectorServiceFactory.getResourceModuleParser()).andReturn(parser);
expect(parser.parse("Mozilla/5.0")).andReturn(userAgent);
PowerMock.replayAll(UADetectorServiceFactory.class, parser, request);
ReadableUserAgent actual = filter.parseUserAgent(request);
PowerMock.verifyAll();
assertSame(userAgent, actual);
}
Aggregations