Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
hofmann
Active Contributor

NetWeaver Cloud – or NW Cloud – is available and it comes with a free (FREE!) trial account for everyone interested. NW Cloud (I am sure I will type this name several times again, so let me just call it Neo) is Java. Pure Java in the sense that you can finally reuse your Java knowledge acquired somewhere else for SAP projects. Neo works nicely with all the other tools Java developers are used to, like Maven, Ivy, Jenkins, Sonar, or what else you use for your other Java code projects. No more NWDI or SCs, DCs, public / private parts and activities. You can use the code revision as well as the build and dependency system you want, no need to set up anymore a separate infrastructure. The SDK is Eclipse and now you are free to choose which Eclipse you want to use: it is not the same as with the closed NWDS that is Eclipse based, but at the same time forces you to stay with an old Eclipse version.

Short: Neo is good news for Java developers on SAP projects!

The mobile application

To show a benefit of Neo, let me create a Java application for storing and retrieving information about persons. To make things easy, I used as a starting point the Neo tutorial for JPA and Dagfinn Parnas’ blog about Jersey for Neo apps.

Neo is cloud, implying that you do not have any more to worry on how to access your internal system from somewhere else. Once the application is deployed on Neo, you can already start using it by other services, be it internal or cloud. Mobility is everywhere and with a public available service that understands JSON and REST in a way most Javascript frameworks expect it, let's create a mobile application using another cloud service (and at the same time eagerly waiting for VC5 and App Designer).


The servlet for providing the data

The data to be stored in the database is easy: some general information about a person, one Java object, one database table.

To make it easier for starting from scratch every time the servlet is deployed the database will be created from scratch:

Creating methods for retrieving and storing information via REST and JSON:

public List<Person> getAllPersons()
public Person getPerson(@QueryParam("id") long personId)
public Person createPerson(Person person)

Mobile User Interface

For the UI you are free to use whatever you want, as long as your frontend can access the servlet running inside Neo. Free really means free: Neo comes with SAPUI5, but you are not forced to use it (as you are in “normal” SAP Java with Web Dynpro). As the service is already available publicly in the cloud, accessing it by a HTML5 app is not a problem at all. The problem is to create the HTML5 app.

Just to show that you are not bound to use SAP and because I do not have mobile UI tools from SAP at my fingertips right now, let’s use a tiggzi. As soon as SAP releases VC5 or AppDesigner to people like me, for sure I’ll use these tools. As for right now, these are not available; I had to choose another tool.

Creating a UI in tiggzi is done by drag and drop, making it easy to create a HTML5 app.

Services for data consumption are created via drag and drop, as well as assigning input and output elements (reminds me of Visual Composer).

Tiggzi does not give you much choice when it comes to REST services. Either you are able to adopt your service to work with tiggzi, or you cannot use it. For instance, data is sent in JSON in a specific format and values are passed as parameters. While you can specify that a parameter should be included in the header, adding it as a part of the path is not possible. Here you have to adjust your service to (the limitation of) the frontend. Thankfully, in Neo it is up to you to define the service, so you have total control.

Running the HTML5 app inside a browser

The save button triggers the service to POST the data to the servlet running in Neo.

To get a list of available persons, click the “Load Persons” button. This sends a GET request to the service and receives a list of all persons found in the database. Selecting a person in the select box shows then the information about that specific person.

How does this work on a mobile device

The run the application on a mobile device, you can either use the online version or install it as a hybrid application on the device. On a Galaxy Note the screens look like:

Next

Neois cloud with no limitations. It is offered by SAP, but you are free on how you use it. Combining Neo with other non-SAP software and cloud products is not a problem. You can host your services on Neo and use your other tools you are already used to; or vice versa. SO, what next? Using continuous integration for Neo projects.

Note

When in the web interface you cannot restart the app. You only can stop and then start the app:

In case you do not want to wait for the application to be stopped first (takes some time), use Eclipse. There you can restart the application:

Besides this, it takes some time for Neo to get up and running (local or cloud). Due to a copy & paste error, I had to stop the application several times. This is time consuming, as it took more than a minute for stopping, deploying, starting and be able to use the application. If you are used to NW Java development and data dictionary: the DB is created by JPA in the above example. You have to think how the existing DB is treated when deploying the servlet. Adding a new field means to first drop the DB. Did not expect me to say this: being able to create the DB in a separate deploy is a feature I miss.


The source code

The code is basically the same as used in the JPA tutorial and the Jersey code posted by Dagfinn. This code looks up all Persons saved in the database and returns a list of Person object in JSON format:

[Excerpt of the servlet]

@GET
@Produces({ MediaType.APPLICATION_JSON })
public List<Person> getAllPersons() {
  EntityManager em = emf.createEntityManager();
  try {
    @SuppressWarnings("unchecked")
    List<Person> resultList = em.createNamedQuery("AllPersons").getResultList();
    return resultList;
  }
[...]

Now, there is one small problem with Jersey and Neo: they do not work together. Looks like Jersey does not like OSGI, but there is a workaround available.

1. Create a new class:

package com.tobias.neo.api.rest;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyApplication extends Application {
  public Set<Class<?>> getClasses() {
    Set<Class<?>> s = new HashSet<Class<?>>();
    s.add(RestAPI.class);
    return s;
  }
}

2. In web.xml:

<servlet>
  <servlet-name>Jersey REST Service</servlet-name>
  <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <init-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>com.tobias.neo.api.rest.MyApplication</param-value>
  </init-param>
  <init-param>
    <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
    <param-value>com.tobias.neo.api.filter.ResponseCorsFilter</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

Calling the servlet under <appname>/api/person shows that Jersey is working under Neo:

{"person":[{"company":"Other","description":"SAP Mentor","firstName":"Tobias","id":"1","job":"Solution Architect","lastName":"Hofmann"}]}
9 Comments
Labels in this area