### Build WURFL Microservice Client and Example with Maven Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md Commands to compile and package the WURFL Microservice Java client and its associated example project. Requires a running WURFL Microservice server for successful test execution. ```bash mvn clean install # After compiling the client: cd example mvn clean compile package ``` -------------------------------- ### GET /v2/os/{os}/versions Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves all known versions for a specific operating system. ```APIDOC ## GET /v2/os/{os}/versions ### Description Lists all versions for the specified operating system. ### Method GET ### Endpoint /v2/os/{os}/versions ### Parameters #### Path Parameters - **os** (string) - Required - The operating system name (e.g., Android) ### Response #### Success Response (200) - **versions** (array) - List of version strings. ### Response Example { "versions": ["13", "14"] } ``` -------------------------------- ### Retrieve WURFL Microservice Server Information (Java) Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Shows how to get server details like API version, WURFL file information, and available static/virtual capabilities. This is useful for debugging and verifying server setup. Requires `com.scientiamobile.wurfl.wmclient.Model` and `com.scientiamobile.wurfl.wmclient.WmClient`. ```java import com.scientiamobile.wurfl.wmclient.Model; import com.scientiamobile.wurfl.wmclient.WmClient; WmClient client = WmClient.create("http", "localhost", "8080", ""); Model.JSONInfoData info = client.getInfo(); System.out.println("WURFL API version: " + info.getWurflApiVersion()); System.out.println("WM server version: " + info.getWmVersion()); System.out.println("WURFL file info: " + info.getWurflInfo()); // Get available capabilities String[] staticCaps = info.getStaticCaps(); String[] virtualCaps = info.getVirtualCaps(); System.out.println("Available static capabilities: " + staticCaps.length); System.out.println("Available virtual capabilities: " + virtualCaps.length); ``` -------------------------------- ### Perform Device Detection and Server Interaction in Java Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md A complete Java example demonstrating how to initialize the WmClient, configure caching, request specific device capabilities, and perform user-agent lookups. It also shows how to retrieve server information and list device manufacturers. ```java package com.scientiamobile.wmclient.example; import com.scientiamobile.wurfl.wmclient.*; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import static java.lang.System.out; public class Example { public static void main(String[] args) { try { WmClient client = WmClient.create("http", "localhost", "8080", ""); Model.JSONInfoData info = client.getInfo(); client.setCacheSize(100000); client.setRequestedStaticCapabilities(new String[]{"brand_name", "model_name"}); client.setRequestedVirtualCapabilities(new String[]{"is_smartphone", "form_factor"}); String ua = "Mozilla/5.0 (Linux; Android 7.1.1; ONEPLUS A5000 Build/NMF26X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"; Model.JSONDeviceData device = client.lookupUseragent(ua); if (device.error == null || device.error.isEmpty()) { Map capabilities = device.capabilities; out.println("Detected device WURFL ID: " + capabilities.get("wurfl_id")); } } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Retrieve and Print Android OS Versions using WURFL Microservice Client Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This example shows how to retrieve all versions for a specific operating system (Android in this case) from the WURFL Microservice, sort them, and display them. It also includes client resource cleanup. ```java out.println("Print all versions for the Android OS"); String[] osVersions = client.getAllVersionsForOS("Android"); // Sort all Android version numbers and print them. Arrays.sort(osVersions); for (String ver : osVersions) { out.printf(" - %s\n", ver); } // Cleans all client resources. Any call on client API methods after this one will throw a WmException client.destroyConnection(); ``` -------------------------------- ### GET /v2/os Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves a list of all device operating system names available in the WURFL database. ```APIDOC ## GET /v2/os ### Description Lists all operating systems supported in the database. ### Method GET ### Endpoint /v2/os ### Response #### Success Response (200) - **os_list** (array) - List of operating system names. ### Response Example { "os_list": ["Android", "iOS", "Windows"] } ``` -------------------------------- ### GET /v2/makes/{make}/devices Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves all device models and their associated marketing names for a specific manufacturer. ```APIDOC ## GET /v2/makes/{make}/devices ### Description Returns a list of device models and marketing names for the specified brand. ### Method GET ### Endpoint /v2/makes/{make}/devices ### Parameters #### Path Parameters - **make** (string) - Required - The brand name (e.g., Apple) ### Response #### Success Response (200) - **devices** (array) - List of objects containing modelName and marketingName. ### Response Example { "devices": [ { "modelName": "iPhone 14", "marketingName": "iPhone 14" } ] } ``` -------------------------------- ### Get All Versions for an OS using Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves all known version numbers for a specified operating system. The returned list of versions is sorted. This functionality is provided by the `WmClient` class. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); String[] androidVersions = client.getAllVersionsForOS("Android"); Arrays.sort(androidVersions); System.out.println("Android versions:"); for (String version : androidVersions) { System.out.println(" - " + version); } ``` -------------------------------- ### Implement Device Detection Servlet Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt A complete Java Servlet example showing the lifecycle of a WURFL client, including initialization, capability configuration, and processing HTTP requests to return device metadata in JSON format. ```java import com.scientiamobile.wurfl.wmclient.Model; import com.scientiamobile.wurfl.wmclient.WmClient; import com.scientiamobile.wurfl.wmclient.WmException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.Map; @WebServlet("/detect") public class DeviceDetectorServlet extends HttpServlet { private WmClient wmClient; @Override public void init() throws ServletException { try { wmClient = WmClient.create("http", "localhost", "8080", ""); wmClient.setCacheSize(50000); wmClient.setRequestedStaticCapabilities(new String[]{"brand_name", "model_name", "device_os", "device_os_version", "resolution_width", "resolution_height", "is_tablet"}); wmClient.setRequestedVirtualCapabilities(new String[]{"is_smartphone", "is_mobile", "form_factor", "complete_device_name"}); } catch (WmException e) { throw new ServletException("WM Client initialization failed", e); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { Model.JSONDeviceData device = wmClient.lookupRequest(request); if (device.error != null && !device.error.isEmpty()) { response.setStatus(400); out.println("{\"error\": \"" + device.error + "\"}"); return; } Map caps = device.capabilities; out.println("{\"wurfl_id\": \"" + caps.get("wurfl_id") + "\", \"device_name\": \"" + caps.get("complete_device_name") + "\"}"); } catch (WmException e) { response.setStatus(500); out.println("{\"error\": \"Detection failed: " + e.getMessage() + "\"}"); } } @Override public void destroy() { if (wmClient != null) { try { wmClient.destroyConnection(); } catch (WmException e) { getServletContext().log("Error closing WM client", e); } } } } ``` -------------------------------- ### GET /v2/makes Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves a comprehensive list of all device brand names (makes) available in the WURFL database. ```APIDOC ## GET /v2/makes ### Description Fetches all device brand names available in the WURFL database. ### Method GET ### Endpoint /v2/makes ### Response #### Success Response (200) - **makes** (array) - A list of strings representing device brand names. ### Response Example { "makes": ["Apple", "Samsung", "Google", "Xiaomi"] } ``` -------------------------------- ### Get All Devices for a Make using Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves all device models and their marketing names for a specified brand. The results are sorted by model name. This function requires the `WmClient` and returns an array of `Model.JSONModelMktName` objects. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); Model.JSONModelMktName[] appleDevices = client.getAllDevicesForMake("Apple"); // Sort by model name Arrays.sort(appleDevices, (d1, d2) -> d1.modelName.compareTo(d2.modelName)); System.out.println("Apple devices: " + appleDevices.length); for (Model.JSONModelMktName device : appleDevices) { String marketingName = device.marketingName != null ? device.marketingName : ""; System.out.printf(" - Model: %s, Marketing Name: %s%n", device.modelName, marketingName); } ``` -------------------------------- ### GET /v2/devices/{wurflId} Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves device information and capabilities using a specific WURFL device identifier. ```APIDOC ## GET /v2/devices/{wurflId} ### Description Retrieves device information and requested capabilities using a known WURFL device identifier. ### Method GET ### Endpoint /v2/devices/{wurflId} ### Parameters #### Path Parameters - **wurflId** (string) - Required - The unique WURFL device identifier (e.g., apple_iphone_ver14_3) ### Response #### Success Response (200) - **capabilities** (object) - A map of requested device capabilities. - **error** (string) - Error message if the lookup failed. ### Response Example { "capabilities": { "brand_name": "Apple", "model_name": "iPhone 14", "is_smartphone": "true" }, "error": "" } ``` -------------------------------- ### Configure Maven Dependencies for WURFL Microservice Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Defines the required Maven dependencies for the WURFL Microservice client. Includes a standard configuration and an alternative setup for Jakarta EE 9 environments requiring the jakarta.servlet-api. ```xml com.scientiamobile.wurflmicroservice wurfl-microservice 2.1.9 ``` ```xml com.scientiamobile.wurflmicroservice wurfl-microservice 2.1.9 jakarta.servlet jakarta.servlet-api 5.0.0 provided ``` -------------------------------- ### Get All Device Makes (Brands) using Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves a list of all device brand names available in the WURFL database. The results are sorted alphabetically for easier processing. This method is part of the `WmClient` functionality. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); String[] deviceMakes = client.getAllDeviceMakes(); Arrays.sort(deviceMakes); System.out.println("Total brands: " + deviceMakes.length); System.out.println("First 10 brands:"); for (int i = 0; i < Math.min(10, deviceMakes.length); i++) { System.out.println(" - " + deviceMakes[i]); } ``` -------------------------------- ### Get All Operating Systems using Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves a list of all unique device operating system names present in the WURFL database. The output is sorted alphabetically. This method is accessed via the `WmClient` instance. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); String[] operatingSystems = client.getAllOSes(); Arrays.sort(operatingSystems); System.out.println("Operating Systems:"); for (String os : operatingSystems) { System.out.println(" - " + os); } ``` -------------------------------- ### Retrieve and Print OS Names using WURFL Microservice Client Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This snippet demonstrates how to fetch all operating system names from the WURFL Microservice, sort them alphabetically, and print them to the console. It also includes error handling for WMFExceptions. ```java out.println("Print the list of OSes"); String[] oses = client.getAllOSes(); // Sort and print all OS names Arrays.sort(oses); for (String os : oses) { out.printf(" - %s\n", os); } ``` -------------------------------- ### Configure Requested Device Capabilities (Java) Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Explains how to specify which device capabilities (static and virtual) the client should retrieve during detection requests. It also shows how to check for the availability of specific capabilities. Uses `WmClient`. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); // Set specific static capabilities to retrieve client.setRequestedStaticCapabilities(new String[]{ "brand_name", "model_name", "device_os", "device_os_version", "is_tablet", "resolution_width", "resolution_height" }); // Set specific virtual capabilities to retrieve client.setRequestedVirtualCapabilities(new String[]{ "is_smartphone", "is_mobile", "form_factor", "is_app", "complete_device_name" }); // Or set both at once (automatically categorizes them) client.setRequestedCapabilities(new String[]{ "brand_name", "model_name", "is_smartphone", "form_factor" }); // Check if a capability is available boolean hasSmartphone = client.hasVirtualCapability("is_smartphone"); boolean hasBrandName = client.hasStaticCapability("brand_name"); ``` -------------------------------- ### Create and Initialize WmClient Instance (Java) Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Demonstrates how to create and initialize a WmClient instance to connect to a WURFL Microservice server. It covers different connection types (HTTP, HTTPS, custom base URI) and cache configuration. Requires the `com.scientiamobile.wurfl.wmclient` package. ```java import com.scientiamobile.wurfl.wmclient.WmClient; import com.scientiamobile.wurfl.wmclient.WmException; try { // Create client connecting to local WM server WmClient client = WmClient.create("http", "localhost", "8080", ""); // For HTTPS connections WmClient secureClient = WmClient.create("https", "wm.example.com", "443", ""); // With custom base URI (useful for Docker/AWS deployments) WmClient customClient = WmClient.create("http", "localhost", "8080", "api/v2"); // Enable caching with 100,000 entries client.setCacheSize(100000); // Clean up when done client.destroyConnection(); } catch (WmException e) { System.err.println("Connection error: " + e.getMessage()); } ``` -------------------------------- ### Device Detection using HTTP Headers with WURFL Microservice Client Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This Java code snippet illustrates how to perform device detection by passing a map of HTTP headers to the WURFL Microservice client's `lookupHeaders` method. It populates a HashMap with various common HTTP headers. ```java Map headers = new HashMap(); headers.put("Accept-Encoding", "gzip, deflate"); headers.put("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1"); headers.put("Accept-Language", "en"); headers.put("Device-Stock-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36"); headers.put("Forwarded", "for=\"110.54.224.195:36350\""); headers.put("Save-Data", "on"); headers.put("Referer", "https://www.cram.com/flashcards/labor-and-delivery-questions-889210"); headers.put("User-Agent", "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16"); headers.put("X-Clacks-Overhead", "GNU ph"); headers.put("X-Forwarded-For", "110.54.224.195, 82.145.210.235"); headers.put("X-Operamini-Features", "advanced, camera, download, file_system, folding, httpping, pingback, routing, touch, viewport"); headers.put("X-Operamini-Phone", "Android #"); headers.put("X-Operamini-Phone-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36"); Model.JSONDeviceData device = client.lookupHeaders(headers); ``` -------------------------------- ### Detect Device by HTTP Headers in Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Performs device detection using a map of HTTP headers. This method leverages additional headers for more accurate detection. It initializes the WURFL client, sets requested capabilities, populates a map with relevant headers, and then looks up the device. ```java import java.util.HashMap; import java.util.Map; WmClient client = WmClient.create("http", "localhost", "8080", ""); client.setRequestedCapabilities(new String[]{"brand_name", "model_name", "is_smartphone", "form_factor"}); Map headers = new HashMap<>(); headers.put("Accept-Encoding", "gzip, deflate"); headers.put("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, */*;q=0.1"); headers.put("Accept-Language", "en"); headers.put("Device-Stock-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36"); headers.put("User-Agent", "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16"); headers.put("X-Forwarded-For", "110.54.224.195, 82.145.210.235"); headers.put("X-Operamini-Phone", "Android #"); headers.put("X-Operamini-Phone-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36"); Model.JSONDeviceData device = client.lookupHeaders(headers); if (device.error == null || device.error.isEmpty()) { Map caps = device.capabilities; System.out.println("Detected: " + caps.get("brand_name") + " " + caps.get("model_name")); System.out.println("Form Factor: " + caps.get("form_factor")); } ``` -------------------------------- ### Generate Code Coverage Report (Bash) Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This command generates a code coverage report for the project using Maven. It requires a running WURFL Microservice Server and the `-Pcoverage` profile to be activated. The report will be available at `target/site/jacoco/index.html`. ```bash mvn clean verify -Pcoverage ``` -------------------------------- ### Detect Device by User-Agent String in Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Performs device detection using a User-Agent string. It initializes the WURFL client, sets requested capabilities, looks up the device based on the provided User-Agent, and prints device information. Dependencies include the WURFL client library. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); client.setCacheSize(100000); client.setRequestedStaticCapabilities(new String[]{"brand_name", "model_name"}); client.setRequestedVirtualCapabilities(new String[]{"is_smartphone", "form_factor"}); String userAgent = "Mozilla/5.0 (Linux; Android 7.1.1; ONEPLUS A5000 Build/NMF26X) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"; Model.JSONDeviceData device = client.lookupUseragent(userAgent); if (device.error != null && !device.error.isEmpty()) { System.err.println("Detection error: " + device.error); } else { Map capabilities = device.capabilities; System.out.println("WURFL ID: " + capabilities.get("wurfl_id")); System.out.println("Brand: " + capabilities.get("brand_name")); System.out.println("Model: " + capabilities.get("model_name")); System.out.println("Form Factor: " + capabilities.get("form_factor")); System.out.println("Is Smartphone: " + capabilities.get("is_smartphone")); } ``` -------------------------------- ### Detect Device from HttpServletRequest in Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Performs device detection directly from a Java Servlet HttpServletRequest object, suitable for web applications. It initializes the WURFL client in the servlet's init method, sets requested capabilities, and uses the lookupRequest method in the doGet method to detect the device and write results to the response. ```java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; public class DeviceDetectionServlet extends HttpServlet { private WmClient wmClient; @Override public void init() throws ServletException { try { wmClient = WmClient.create("http", "localhost", "8080", ""); wmClient.setCacheSize(100000); wmClient.setRequestedCapabilities(new String[]{ "brand_name", "model_name", "is_smartphone", "is_tablet", "form_factor" }); } catch (WmException e) { throw new ServletException("Failed to initialize WM client", e); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Model.JSONDeviceData device = wmClient.lookupRequest(request); if (device.error == null || device.error.isEmpty()) { Map caps = device.capabilities; response.getWriter().println("Device: " + caps.get("brand_name") + " " + caps.get("model_name")); response.getWriter().println("Is Mobile: " + caps.get("is_smartphone")); } } catch (WmException e) { response.sendError(500, "Device detection failed: " + e.getMessage()); } } @Override public void destroy() { try { if (wmClient != null) { wmClient.destroyConnection(); } } catch (WmException e) { // Log error } } } ``` -------------------------------- ### Lookup Device by WURFL ID using Java Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Retrieves device information by its WURFL ID. This is useful when you have stored WURFL IDs and need to fetch the corresponding device capabilities. It requires the `WmClient` and `Model.JSONDeviceData` classes. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); client.setRequestedCapabilities(new String[]{ "brand_name", "model_name", "device_os", "device_os_version", "is_smartphone" }); // Look up a specific device by its WURFL ID String wurflId = "apple_iphone_ver14_3"; Model.JSONDeviceData device = client.lookupDeviceId(wurflId); if (device.error == null || device.error.isEmpty()) { Map caps = device.capabilities; System.out.println("Device: " + caps.get("brand_name") + " " + caps.get("model_name")); System.out.println("OS: " + caps.get("device_os") + " " + caps.get("device_os_version")); } ``` -------------------------------- ### Configure and Use Cache with Java Client Source: https://context7.com/wurfl/wurfl-microservice-client-java/llms.txt Enables and configures the LRU cache for the WURFL client to improve performance by storing detection results. This avoids repeated server requests for the same user agents. The cache size can be set, and actual cache usage can be queried. ```java WmClient client = WmClient.create("http", "localhost", "8080", ""); // Enable caching with 100,000 entry limit client.setCacheSize(100000); // Perform detections - subsequent lookups for the same UA will use cache String userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15"; // First call goes to server Model.JSONDeviceData device1 = client.lookupUseragent(userAgent); // Second call returns cached result (no server round-trip) Model.JSONDeviceData device2 = client.lookupUseragent(userAgent); // Check current cache sizes [deviceIdCache, userAgentCache] int[] cacheSizes = client.getActualCacheSizes(); System.out.println("Device ID cache entries: " + cacheSizes[0]); System.out.println("User-Agent cache entries: " + cacheSizes[1]); // Get client API version System.out.println("Client API version: " + client.getApiVersion()); ``` -------------------------------- ### Update Servlet API Dependency in pom.xml (XML) Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This snippet shows the necessary dependency update for the servlet API in the `pom.xml` file to ensure compatibility with Jakarta EE 9. It specifies the `jakarta.servlet-api` artifact with version `5.0.0` and a `provided` scope. ```xml jakarta.servlet jakarta.servlet-api 5.0.0 provided ``` -------------------------------- ### Comparator for Sorting ModelMktName by Model Name in Java Source: https://github.com/wurfl/wurfl-microservice-client-java/blob/master/README.md This Java code defines a custom Comparator to sort `Model.JSONModelMktName` objects based on their `modelName` property using natural string ordering. It handles null values appropriately. ```java class ByModelNameComparer implements Comparator { @Override public int compare(Model.JSONModelMktName o1, Model.JSONModelMktName o2) { if (o1 == null && o2 == null) { return 0; } if (o1 == null && o2 != null) { return 1; } if (o1 != null && o2 == null) { return -1; } return o1.modelName.compareTo(o2.modelName); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.