OpenDDR Java Save

Java Implementation of OpenDDR-Simple-API

Project README


Dear OpenDDR user,

In the follow the description of directory tree:

  • lib: contains necessary libraries to run OpenDDR-Simple-API;
  • src: contains java source code and the file. Please configure the file with the right path of the resources.

A basic explanation of the properties in

  • Path of the file that explain how to identify the devices. In this, for each builder, are specified the devices id that the builder handle and the identification rules
  • Path of the device datasource
  • Path of the patch file for the builder file
  • Path of the patch file for the device data source
  • Path of the browser data source
  • Path of the operating system data source
  • ddr.vocabulary.core.path: Path of the W3C vocabulary file
  • oddr.vocabulary.path: Path of OpenDDR vocabulary
  • Path of the reduced vocabulary. This vocabulary is usefull to limitate the memory load. It can be safely left unspecified.
  • oddr.vocabulary.device: IRI of the default vocabulary. It is the target namespace specified in a vocabulary
  • oddr.threshold: Identification threshold. It is used to balance the request evaluation time and identification matching.

This is a java example on how to integrate OpenDDR in a servlet Filter:

	package org.openddr.samplewebapp.filter;

	import java.util.Properties;
	import javax.servlet.Filter;
	import javax.servlet.FilterChain;
	import javax.servlet.FilterConfig;
	import javax.servlet.ServletContext;
	import javax.servlet.ServletException;
	import javax.servlet.ServletRequest;
	import javax.servlet.ServletResponse;
	import javax.servlet.http.HttpServletRequest;
	import org.openddr.simpleapi.oddr.ODDRService;
	import org.openddr.simpleapi.oddr.model.ODDRHTTPEvidence;
	import org.w3c.ddr.simple.Evidence;
	import org.w3c.ddr.simple.PropertyRef;
	import org.w3c.ddr.simple.PropertyValue;
	import org.w3c.ddr.simple.PropertyValues;
	import org.w3c.ddr.simple.Service;
	import org.w3c.ddr.simple.ServiceFactory;
	import org.w3c.ddr.simple.exception.NameException;

	public class IdentificationFilter implements Filter {

	    private Service identificationService = null;

	    public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("Initialize filter");
		Properties initializationProperties = new Properties();
		ServletContext context = filterConfig.getServletContext();                

		try {
		    identificationService = ServiceFactory.newService("org.openddr.simpleapi.oddr.ODDRService", initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);

		} catch (Exception ex) {
		    throw new RuntimeException(ex);

	    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		PropertyRef vendorRef;
		PropertyRef modelRef;
		PropertyRef displayWidthRef;
		PropertyRef displayHeightRef;

		try {
		    vendorRef = identificationService.newPropertyRef("vendor");
		    modelRef = identificationService.newPropertyRef("model");
		    displayWidthRef = identificationService.newPropertyRef("displayWidth");
		    displayHeightRef = identificationService.newPropertyRef("displayHeight");

		} catch (NameException ex) {
		    throw new RuntimeException(ex);

		PropertyRef[] propertyRefs = new PropertyRef[] {vendorRef, modelRef, displayWidthRef, displayHeightRef};
		Evidence e = new ODDRHTTPEvidence();
		e.put("User-Agent", ((HttpServletRequest)request).getHeader("User-Agent"));

		try {
		    PropertyValues propertyValues = identificationService.getPropertyValues(e, propertyRefs);
		    PropertyValue vendor = propertyValues.getValue(vendorRef);
		    PropertyValue model = propertyValues.getValue(modelRef);
		    PropertyValue displayWidth = propertyValues.getValue(displayWidthRef);
		    PropertyValue displayHeight = propertyValues.getValue(displayHeightRef);

		    if (vendor.exists() && model.exists() && displayWidth.exists() && displayHeight.exists()) {
		        ((HttpServletRequest)request).setAttribute("vendor", vendor.getString());
		        ((HttpServletRequest)request).setAttribute("model", model.getString());
		        ((HttpServletRequest)request).setAttribute("displayWidth", displayWidth.getInteger());
		        ((HttpServletRequest)request).setAttribute("displayHeight", displayHeight.getInteger());


		} catch (Exception ex) {
		    throw new RuntimeException(ex);

		chain.doFilter(request, response);

	    public void destroy() {
		System.out.println("Destroy Filter");
Open Source Agenda is not affiliated with "OpenDDR Java" Project. README Source: OpenDDRdotORG/OpenDDR-Java
Open Issues
Last Commit
9 years ago

Open Source Agenda Badge

Open Source Agenda Rating