Features

Some of the important features of the Leo are are mentioned below:

Leo is designed taking under consideration of easy service development.

Minimal configuration

Configuration of Leo is simple in order to configure first setup web.xml file and install LeoServlet in it.

A sample configuration file is posted below.

			
	<servlet>
		<servlet-name>leo</servlet-name>
		<servlet-class>org.leo.rest.servlet.LeoServlet</servlet-class>
		<init-param>
			<param-name>packageName</param-name>
			<param-value>com.service</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>leo</servlet-name>
		<url-pattern>/rest/*</url-pattern>
	</servlet-mapping>

		

Spring integration

Spring integration is like the following:

			
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener> 
			
			

Service

Service class will be recognized only if resides in correct package provided in config. On server startup service package will be loaded.
For GET:
Service method can return data as list, String, Stream or a File.
Objects returned from service method need to implement org.leo.serializer.LeoSerializable or need annotation of type org.leo.rest.annotations.Serializable resources can be fetched through console as following. curl http://localhost:8080/LeoTest/rest/ProductProvider/electronics -H authToken:J/Zywd8kibbTgQrE3hSzng== > ~/Desktop/ab.json
For POST:
Posted resource will be injected to service method by calling getStream() method. Stream then can be converted to file or json resources can be posted through console as following. curl -H authToken:J/Zywd8kibbTgQrE3hSzng== -H Content-Type:application/json -X POST -d @/home/divyank/Desktop/ab.json http://localhost:8080/LeoTest/rest/ProductProvider/product/electronics/add

			
package com.service;



@Service(name="ProductProvider")
public class ProductProvider extends LeoService{

	@Path(urlPath="/product/")
	public int getProduct(){
		return 2000;
	}
	
	
	@Path(urlPath="/product/electronics")
	public List getElectronicProducts(){
		Prodcty p3=new Prodcty();
		List list=new ArrayList();
		list.add(p3);
		return list;
	}
	
	/*
	 * 
	 * While returning an object in order for it to be serialize 
	 * it need to implements org.leo.serializer.LeoSerializable
	 * 		        OR
	 * instance of File,InputStream,Array,List or Map
	 * While returning collection objects should be of above types
	 * 
	 */
	@Path(urlPath="/product/all")
	public Product getAllProduct(){
		return null;
	}
	
	@Path(urlPath="/product/prodId")
	public File getProductById(){
		Blob blob =null;
		File file=new File("abc.jpg");
		return file;
	}
	
}

		

Authentication

Setup config as shown below.

			
	<servlet>
		<servlet-name>leo</servlet-name>
		<servlet-class>org.leo.rest.servlet.LeoServlet</servlet-class>
		<init-param>
			<param-name>packageName</param-name>
			<param-value>com.service</param-value>
		</init-param>
		
		<!-- Set up custom authenticator for authtoken -->
		<init-param>
			<param-name>authenticator</param-name>
			<param-value>com.abc.SampleAuthenticator</param-value>
		</init-param>
		
		<!-- location for key file -->
		<init-param>
			<param-name>keyFile</param-name>
			<param-value>keyFile</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>leo</servlet-name>
		<url-pattern>/rest/*</url-pattern>
	</servlet-mapping>

		
The custom authenticator class can help user to validate incoming token.
It is optional to implement an authenticator if not given it will be construed as the will be no auth token for the services.
Token in the incoming message initially be encrypted and before passing to authenticator it will be decrypted.
An example of custom authenticator is given below.

			
	package com.abc;

	import org.leo.rest.auth.Authenticator;
	
	public class SampleAuthenticator implements Authenticator{
	
		@Override
		public boolean validate(String auth) {
			dao.validateUserId(auth);
			return true;
		}
	}