Why Ocelotds, and what Ocelotds do ?

Without Ocelotds

Actually, when you write java back-end and javascript front-end, you probably do something like that :

You write your business layer :

Some entities/DTO


public class MyObject {  
   String prop1; // with getter setter of course, cause JSON librairy (java) use them.
   boolean prop2;
}
	

Some services


public class MyService { // EJB, CDI, Spring
   public Result getResult(String str, MyObject arg2) {
      ...
   }
}
	

REST Services

But at this time, your service is not reachable from the front-end.
So You have to write a web component for access it, for example a JAX-RS REST Service.


@Path("/myservice")
public class MyRestService { 
   @POST
   @Produces("text/json")
   @Consumes("application/x-www-form-urlencoded")
   @Path("/{str}")
   public Result method(@PathParam("str") String str, @FormParam("arg") MyObject arg2) {
      retrun myService.getResult(str, arg2); // normaly myService is avalable by injection
   }
}
	

Some calls from front-end

Finally in javascript you have to write code for access to the rest service.
Of course you can use helpers for that like jquery or other.


var req = new XMLHttpRequest();
req.onreadystatechange = function() {
   if (req.status == 200) {
      var result = JSON.parse(req.responseText);
      // do something
   } else {
      // Error handler
   }
}
req.open("POST", "/myservice/foo", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send("{\"prop1\":\"foo\",\"prop2\":true}");
	

About the previous code :

Finally, it should be nicer if we could write a similar javascript code to Java code.

Now with Ocelotds

So you write your business layer like previously :

Always some entities/DTO


public class MyObject { 
   String prop1; // with getter setter of course, cause JSON librairy (java) use them.
   boolean prop2;
}
	

Always some services

Just add an annotation indicate all publics methods are exposed on the web layer, and the proper resolver


@DataService(resolver = Constants.Resolver...) // use the correct resolver
public class MyService { // EJB, CDI, Spring
   public Result getResult(String str, MyObject arg2) {
      ...
   }
}
	

For java layer, it's finish. Now in javascript :

Calls from front-end


myService.getResult("foo", {"prop1":"foo","prop2":true}).then(function(res) { // You wrote MyService in java, you use myService in javascript, marvelous
   // do something with res
});
	

That's all, your front-end communicate elegantly with the back-end, with less boilerplate codes. Ocelot framework allow to call differents services directly from simple classes methods call, like you can do in the back-end.

And more :

Enjoy...