In my database I have a long list of user agents that I require a translation of them, a very promising tool is WURFL, but it has no gradle support and is not very well documented. All of the examples I could recover explained how to implement it using a java servlet, but in my case I don't have a servlet or an http request\response just a long list of user agents that need translation, is there a simple way to query WURFL database using a simple java program?
3 Answers
The best solution is to compile the wurfl-cloud-client-java jar yourself (Maven), it can be found in: https://github.com/WURFL/wurfl-cloud-client-java there is no jar\maven\gradle available elsewhere.
Then import it to your project and run the following:
@Test(groups = "unit")
public class CloudClientUserAgentQueryTest extends Loggable{
private static final String ua = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/30.0.1599.12 Mobile/11A465 Safari/8536.25 (3B92C18B-D9DE-4CB7-A02A-22FD2AF17C8F)";
private ICloudClientManager ICloudClient;
private AbstractDevice device;
private String[] capabilities;
private String mobile;
@BeforeClass
public void setup() throws Exception {
CloudClientLoader loader = new CloudClientLoader(null, "/DefaultTest.properties");
ICloudClient = loader.getClientManager();
}
@BeforeMethod
public void setupDevice() {
device = ICloudClient.getDeviceFromUserAgent(ua, capabilities);
Object mobile = device.get("is_wireless_device");
this.mobile = mobile != null ? mobile.toString() : "unknown";
}
@Test
public void testClient() {
assertTrue(mobile.equals("true"));
}
}

- 2,074
- 22
- 26
The easiest way to do it is just using plain old WURFL Java API, which can work with a simple executable Java class. You just have to put it in your classpath (or import it with maven, in case you use it) and do something like this:
public static void main(String[] args) {
String ua = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/30.0.1599.12 Mobile/11A465 Safari/8536.25 (3B92C18B-D9DE-4CB7-A02A-22FD2AF17C8F)";
WURFLEngine engine = new GeneralWURFLEngine("path/to/wurfl.zip");
Device device = engine.getDeviceForRequest(ua);
System.out.println("Device id: " + device.getId());
System.out.println("Capability preferred_markup: " + device.getCapability("preferred_markup"));
System.out.println("Device name: " + device.getCapability("device_name"));
System.out.println("Brand: " + device.getCapability("brand_name"));
}
Please notice that you will need a wurfl file. If you don't have it (current file versions are distributed by Scientiamobile under a commercial license), the previously mentioned cloud client Java can also work.

- 117
- 1
- 10
51Degrees Java API supports offline processing of lists of User-Agents. I have seen an explanation of how to use this feature on their website.
However, as a large number of User-Agents contain commas, I would suggest changing the output CSV separator in the code from the above link to something else to avoid confusion.
This method uses a list of User-Agents as an input with one User-Agent per line.
Hope that helps.
-
1Thank you but I need to use the WURFL one. – Adi Nov 24 '15 at 13:44