Skip to Content
Author's profile photo Former Member

Creating mobile apps on top of SAP – Part2


Welcome to the second part of our mobile
SAP tutorial! Let’s quickly sum up the overall goal which is creating so called
“instant value mobile applications” in terms of lightweight mobile
solutions which do not require a fully blown Sybase stack – of course the
Sybase stack can not be replaced based on this simple stack, but as already
mentioned, there might be requirements which could be solved in a more
efficient manner using a lightweight approach…

In the first part of this tutorial series
we chalked out how to expose a SAP BAPI as a Web Service. We used the common
known FLIGHT BAPI so at the current state of the tutorial we have a Web Service
up and running providing a simple method called “Flight Get List”. If
you should have missed the first part of the tutorial, here’s a link to the
first part:

[ |]

notice as well: if you should have a different Web Service instead of FLIGHT
BAPI, no matter, the following steps apply to any SAP Web Service – it’s
completely up to you whether you wanna show up some flights or some CRM data on
your mobile device.


h3. 1          Sum

Ok, last tutorial has been released couple
of weeks before this part, so we will start with a quick sum up in order to get
you up to date on what has been achieved as well as what will be achieved
today. As already mentioned, we have a simple Web Service up and running
providing SAP related data based on several input parameters. This is always
kind of basic step before you actually start thinking about the client layout,
technology etc.; as already mentioned, you can use any Web Service from your
SAP system and do not require our FLIGHT BAPI Web Service.

We suggest, you use SOAPUI and test your
Web Service before you continue with our implementation, at this state you
should have an accessible Web Service which returns some data from your SAP
system when executing a dry run within the SOAPUI environment (SOAPUI is free
of charge and can be downloaded here: Our Web Service
for example returns 15 flights when passing in the “LH” (Lufthansa)
carrier, see screenshot below:


Ok, so this should have been achieved after
the last part of the tutorial so let’s switch to the next chapter and see what
we will achieve within this second part of the tutorial.


h3. 2          Outlook – what we will achieve

Please remind the big picture (see below) –
the grey box is up and running for now so let’s focus the blue box above: on
the one hand the blue box provides UI stuff to our mobile client (this is NOT
covered within this 2nd tutorial part), on the other hand the blue box connects
the Web Service – which is what we will do today. It is important to connect
the Web Services using Java language as the client interface (vaadin) will be
created based on Java as well – so if we have the Web Services accessible
through Java we can easily use these within our mobile client.

The Web Services will be connected via
Apache Axis 2 – the cool thing about Axis: Axis will translate the WSDL to Java
classes automatically so all you need to know is how to invoke Axis on your Web
Service. After generation there will be a Java stack available enabling you to
access your Web Services easily.




h3. 2.1       Requirements/installations

In order to
generate the Java stubs on top of your Web Service (as well as for the vaadin
UI creation in the next part of the tutorial), you require several tools:


    Eclipse IDE for
    Java EE developers (3.6): (!!! MAKE SURE YOU  CHOSE THE “IDE FOR JAVA EE DEVELOPERS” !!!!)

    Download Eclipse
    IDE as well as Apache Axis, next fire up Eclipse and your are close to implementing/generating
    the Web Service stubs.

    You can create a
    new workspace (Eclipse will ask you when launching first time), just give it a
    name such as myMobileSapWorkspace and
    wait until Eclipse finished loading. There is one important configuration issue
    which needs to be achieved in order to run Axis2 as Eclipse by default ships
    with the old Axis1 – using the old Axis would work as well but as there have
    been huge changes from Axis1 to Axis2 you should link in Axis2:HttpTransportProperties.Authenticator
    auth = new HttpTransportProperties.Authenticator();<br />
    auth.setUsername(“username”);<br />



    4) here’s what the whole block should look


    org.apache.axis2.client.OperationClient _operationClient = serviceClient.createClient(operations[0].getName());+



    auth = new HttpTransportProperties.Authenticator();+

    +               auth.setUsername(“username”);+


    _operationClient.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);+



    This adds security credentials to the
    request before the request is actually being send to the Web Service, if you
    have no security on top of your Web Service you can skip this step.


    h3. 3.1       Using Java Web Service Stub

    Ok, the whole Web Service stub is ready for
    usage right now – which means, we can create a very simple demo app (simply add
    new Class to your src directoy), the class could look like this:


    public class TestService


    +       public static void main(String[] args)+

                  throws Exception

    +       {+

    +              onSearch(“FRANKFURT”, “TOKYO”);+

    +       }+


    +       private static void onSearch(String
    fromCity,String toCity)+

                  throws Exception

    +       {+

    +              Z_get_flight_listStub
    stub = new

    +              Z_get_flight_listStub.ZFlightGetlist
    request = *new                                                *Z_get_flight_listStub.ZFlightGetlist();+


    +              // from+

    +              Char20
    from = new Char20();+

    +              from.setChar20(fromCity);+

    +              request.setImwCityFrom(from);+


    +              // to+

    +              Char20
    to = new Char20();+

    +              to.setChar20(toCity);+

    +              request.setImwCityTo(to);+


    +              // fire request+

    +              final
    Z_get_flight_listStub.ZFlightGetlistResponse resp =                                                stub.zFlightGetlist(request);+


    +              // extract

    +              int numberOfItems =


    +              System.out.println(“Found
    flights: ” numberOfItems);

    +       }+



    You are done! Test the service by simply
    running this class – in our case the service returns 15 flights from Frankfurt
    to Tokyo which have been looked up within the SAP system.

    Let’s sum up what we are doing within this

    1) Instantiate sup and create request on
    top of stub:


    +Z_get_flight_listStub stub = new

    Z_get_flight_listStub.ZFlightGetlist request = *new *Z_get_flight_listStub.ZFlightGetlist();

    2) Use the generated datatype classes and
    populate these – datatype classes? you might wonder…Axis is pretty clever –
    Axis checks automatically the datatypes required by your Web Service and
    creates datatype classes – this ensures you do ot push String longer than
    expected/allowed to the Web Service, it’s a nice and efficient manner to
    prevent you from checking “what dataytpe and which length is expected at
    the service…?”. (Char20 means datatype Char, maxlength 20)


    // from

    Char20 from = new Char20();




    // to

    Char20 to = new Char20();



    3) fire request and process results…:


    // fire request

    +final Z_get_flight_listStub.ZFlightGetlistResponse resp
    =                                  stub.zFlightGetlist(request);+


    // extract results…

    int numberOfItems = resp.getExtFlights().getItem().length;

    4) done! you just accessed you SAP Web Service
    through a Java Axis layer, this Axis layer now can connect to any Java related
    mobile UI technology – which is great and enables us to create a nice vaadin
    iPhone UI on top of this stub within the next tutorial…!

    h3. 4          Next

    The next tutorial will get you in touch
    with development of mobile UI based on vaadin. As vaadin is plain Java there
    will be no difficulties to connect the stubs created within this tutorial part.
    Basically the “boiler plate stuff” is done at this point of the
    tutorial, next thing is the really exciting (and funny!) part , which is
    creating the iPhone UI…!



    Assigned Tags

        You must be Logged on to comment or reply to a post.
        Author's profile photo Naimesh Patel
        Naimesh Patel
        Thanks for step by step guide.

        Naimesh Patel

        Author's profile photo Jørn Thomassen
        Jørn Thomassen
        Very interesting blog!
        Looking forward to part 3 as well.