/OData

Play! module that enables exposing REST APIs for Open Data clients

Primary LanguageJava

OData Play! Module

A module that enables exposing REST APIs for Open Data clients.

Open Data

The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today.

Preamble

OData for Play! makes use of odata4j toolkit which incorporates Jersey as its REST engine. I wished to use the existing play-jersey module by Piero Sartini, unfortunately it hasn’t been possible because the version of jersey that includes odata4j is 1.1.5, plus some issues related to class scanning and context path resolution.

Configuration

These are the default values that you can override in conf/application.conf

# OData module
# ~~~~~

# Context path for OData service
# odata.context.path=/OData/

# Resources configuration class
# odata.resource.config.class=com.sun.jersey.api.core.ClasspathResourceConfig

# Authenticator
# Class that implements play.modules.odata.auth.Authenticator
# odata.authenticator.class=package.MyCoolAuthenticator

# Producer factory
# Class that implements org.odata4j.producer.ODataProducerFactory
# odata.producer.class=play.modules.odata.JPAProducerFactory

# OData JPA producer factory settings
# odata.jpa.namespace=Play
# odata.jpa.maxresults=50

Basic Usage

  1. Create your model.
  2. Import OData routes in conf/routes. Add the following line: * / module:odata
  3. Start your application.
  4. Browse http://127.0.0.1:9000/OData/ you will see the list of your entities

Security

By default all your entities are exposed without any kind of authentication mechanism. To control the access to the OData services you must implement an Authenticator. If your security needs are low you can extend BasicAuthenticator, an Authenticator for http basic that requires login for all http methods except for GET and HEAD.

public class MyBasicAuthenticator extends BasicAuthenticator {
   @Override
   protected Principal login(String user, String password) {
      return (User.login(user, password))? new GenericPrincipal(user) : null;
   }	
}

//