Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you expose a Grails domain model using OData?

Ideally there would be a plugin that automatically exposed the Grails domain model as OData but I can't see one.

There is OData4j which will let you expose POJOs or JPA as OData however it uses JAX-RS and Jersey under the covers and I'm not sure how to use that inside a Grails application.

like image 934
Peter Kelley Avatar asked May 13 '13 03:05

Peter Kelley


1 Answers

I would use Apache Olingo. Follow their Java example and modify for Groovy/Grails like such:

class DataController {
    def action() {
        // create odata handler and configure it with DemoEdmProvider and Processor
        def odata = OData.newInstance()
        def edm = odata.createServiceMetadata(new DemoEdmProvider(), [])
        def handler = odata.createHandler(edm)
        handler.register(new DemoEntityCollectionProcessor())

        // let the handler do the work
        handler.process(request, response)
        return false
    }
}
like image 76
Ken Geis Avatar answered Nov 06 '22 21:11

Ken Geis