Generic Synchronization  |  Data containers  |  Wrapper functions

 

Generic Synchronization Example - First Steps

Reading user information from the "backend"

In this example we will use the Generic Sync API to read your own user information from the "backend" and display them in a JSP page.

The example is based on the event handling example from the Getting started section. It uses the same user interface but instead of displaying data about the Mobile Infrastructure installation the example displays your user information requested from the Web AS.

This example has the following requirements to the Web AS:

  • Wrapper function module MDK_SUSR_USER_ADDRESS_READ needs to exist. It is shipped with the Web AS 6.20 as of Support Package 18.
  • A mapping entry for this function module needs to exist in table BWAFMAPP. The mapping entry has the values { METHOD = MDK_USER_INFO_READ, FUNCTION = MDK_SUSR_USER_ADDRESS_READ }. It is shipped with the Web AS 6.20 as of Support Package 19.

If above objects do not exist in your Web Application Server, you need to create the function module in the ABAP/4 Workbench (transaction SE80) and the mapping entry via the Data Browser (transaction SE16).

 

Scenario

The Generic Sync API provides methods to call function modules on a SAP system and process the response data. The servlet collects your user name, creates an outbound container and starts immediate synchronization. The inbound processor (that is registered by the servlet at initialization), retrieves the user information and stores it in a user information object. The servlet reads the user information from this object and stores it in a bean. The JSP is called by the servlet, retrieves the data from the bean and displays it in tabular form.

The MDK provides a template for this example. Click here to Download template.

The example uses following packages:

import com.sap.ip.me.api.conf.Configuration;
import com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet;
import com.sap.ip.me.api.services.Log;
import com.sap.ip.me.api.sync.*

The coding of this example is very similar to the event example in the Getting Started section. The following parts are added:

  1. The servlet has a new method getUserInfo that creates an outbound container for the given user name and starts immediate synchronization.
  2. A new class UserInformation that holds the user information that the Web AS delivered. It is filled by the class InboundProcessing class and read from the bean.
  3. A new class InboundProcessing that processes data from the Web AS
  4. The InboundProcessing class is registered as InboundProcessor during the initialization of the servlet
  5. Constants have been added to the interface Constants.
  6. The loadBean method retrieves the user information from the UserInformation class and stores it in the bean.

Click here to learn more about Generic Synchronization.

Components for this scenario

Java

Description
GenericSyncExample.java Implementation of the servlet. It registers the inbound processor, requests the user information from the Web AS and fills the bean.
Constants.java Interface with all necessary constants.
InboundProcessing.java Processes the inbound containers from Web AS and fills the UserInformation instance.
UserInformation.java Singleton that holds the user information delivered by the Web AS.
TableViewBean.java Implementation of the bean that is loaded by the servlet and read by the JSP.

JSP

Description
welcome.jsp Initial JSP displaying an input field and a submit button.
tableView.jsp JSP to display the user information.

 

Implemented classes for this example

We create a class GenericSyncExample that extends the class AbstractMEHttpServlet and implements Constants. Constants is an interface in which we define all relevant variables for the application. All variables used in Constants are written in uppercase characters. So anytime you see an uppercase variable used in class GenericSyncExample you will find the definition in interface Constants.

The class GenericSyncExample extends AbstractMEHttpServlet which extends javax.servlet.http.HttpServlet itself. GenericSyncExample implements the methods:

Now the JSP, defined in nextJSP, is called.

 

InboundProcessing.java

Implements the InboundProcessor. The method process is called whenever a inbound container arrives. The methodprocess is implemented in the way that every inbound container is stored in the UserInformation bean.

 

Bean

UserInformation.java
Is called be the InboundProcessing class. It contains the user information.

TableViewBean.java
The bean serves as data bag. It has a string, a string array and two variables that define the length and width of the string array. All variables have get and set methods.

You can also implement this example using only one bean. We have chosen this model, because the UserInformation.java contains the data according to the structure of the inbound processor. The TableViewBean.java represents the data in tabular form in preparation to be displayed by the tableView.jsp.

 

JSP

welcome.jsp
Displays a welcome message and allows to enter a user name. The JSP contains a "Submit" button to send the page.

tableView.jsp
The JSP gets the bean from the session context with the useBean command. It displays the the title and then uses the HTML grid (<td>, <tr> ...) to format the data in the bean. There are two for loops that display the the rows (outer loop) and the columns (inner loop).