This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
The results of detection can be accessed by using a FlowDataProvider which is responsible for managing the lifecycle of the flowData - do NOT dispose
package fiftyone.devicedetection.examples.web;
import fiftyone.devicedetection.shared.DeviceData;
import fiftyone.pipeline.core.configuration.PipelineOptions;
import fiftyone.pipeline.core.configuration.PipelineOptionsFactory;
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.web.services.FlowDataProviderCore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import static fiftyone.common.testhelpers.LogbackHelper.configureLogback;
import static fiftyone.devicedetection.examples.web.HtmlContentHelper.*;
import static fiftyone.pipeline.util.FileFinder.getFilePath;
public class GettingStartedWebOnPrem extends HttpServlet {
private static final long serialVersionUID = 1734154705981153540L;
public static String resourceBase = "device-detection.examples/web/getting-started" +
".onprem/src/main/webapp";
public static Logger logger = LoggerFactory.getLogger(GettingStartedWebOnPrem.class);
public static void main(String[] args) throws Exception {
configureLogback(getFilePath("logback.xml"));
logger.info("Running Example {}", GettingStartedWebOnPrem.class);
EmbedJetty.runWebApp(resourceBase, 8081);
}
FlowDataProviderCore flowDataProvider = new FlowDataProviderCore.Default();
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws Exception {
FlowData flowData = flowDataProvider.getFlowData(request);
DeviceData device = flowData.get(DeviceData.class);
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
doHtmlPreamble(out, "Web Integration On-Premise Example");
doStaticText(out, resourceBase + "/WEB-INF/html/example-description.html");
doStaticText(out, resourceBase + "/WEB-INF/html/client-side-js-include.html");
PipelineOptions pipelineOptions =
PipelineOptionsFactory.getOptionsFromFile(getFilePath(resourceBase) +
"/WEB-INF/51Degrees-OnPrem.xml");
doDeviceData(out, device, flowData,
pipelineOptions.findAndSubstitute("DeviceDetectionHashEngine", "DataFile"));
doStaticText(out, resourceBase + "/WEB-INF/html/apple-detection.html");
doEvidence(out, request, flowData);
doResponseHeaders(out, response);
doHtmlPostamble(out);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
response.setStatus(200);
} catch (Exception e) {
e.printStackTrace();
response.setStatus(500);
}
}
}