Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Former Member

Many of you may have noticed a gap in the documentation of Hana Cloud Platform development. There is a description of UI5 and how to build nice UIs with this HTML5 technology. And there is a description of how to build backend java based applications which starts with servlet technology?! Wouldn't it be nice to have UI5 and let it communicate with the Java backend and not to build servlets anymore?

In fact if HCP would support Java EE 7 Web Profile instead of version 6 you would get JAX-RS support out of the box and can use the JSONModel in UI5 to communicate with your HCP backend. With version 6 you can still use JAX-RS but you have to include it yourself in your application.

I want to describe here as an overview whats need to get this done. As normal you need a dynamic Web project in your Eclipse as a start point. I have successfully used Jersey/Jackson as the implementation of the JAX-RS 2.0 standard. If you have a maven project inlude the dependencies as described on Jersey project page. If you don't use maven just include the libs in WebContent/WEB-INF/lib as you would normally do.

So what do you need for JAX-RS to work for you? Lets assume you want to create one service class which responds to a HTTP GET on the relative path "/rest/ping" where "rest" shall be the path of all rest based calls and ping the specific part.

So you have to do some work in your web.xml first:


This defines a special servlet that you have to write later on and defines that all your REST based services are reachable under the path of "/rest/*" as we wanted to do.

So lets create the class which has to extend, a standard class of JAX-RS. It should look like the following:

import java.util.HashSet;
import java.util.Set;

* JAX-RS Application
public class MyApplication extends Application {

  public Set<Class<?>> getClasses() {
    Set<Class<?>> s = new HashSet<Class<?>>();
    return s;

Here you have to add EVERY service class you write. Normally you would divide your services in several classes. We now have to write the PingService thats added there.

import javax.servlet.ServletException;
* JAX-RS Service for ping
public class PingService {
  public Response ping() throws ServletException {
    return Response.ok().entity("pong").build();

So this service listens on everything on the relative path "/ping". Together with the declaration in web.xml the relative path is now: /rest/ping/*

It has one method that is called on a HTTP GET request and it produces plain text. Normally you would produce JSON but thats something I will keep for part two. Just a hint in the return you can add any object in the entity call instead of a static string that gets transformed to JSON automatically!

Thats it you created your first REST service.

In Part 2 we add salt to the soup - EJBs to access your Database as described in the other tutorials!