creating mobile applications on top of sap%2c part 2

Upload: rajesh-reghu-nadh-nadh

Post on 02-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    1/13

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 1

    Creating Mobile Applications ontop of SAP, Part 2

    Applies to:

    SAP ERP 6.0, Netweaver > 7.10. For more information, visit theMobile homepage.

    Summary

    Welcome to the second part of our mobile SAP tutorial! Let's quickly sum up the overall goal which iscreating so called "instant value mobile applications" in terms of lightweight mobile solutions which do notrequire a fully blown Sybase stack - of course the Sybase stack can not be replaced based on this simplestack, but as already mentioned, there might be requirements which could be solved in a more efficientmanner 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 andrunning providing a simple method called "Flight Get List". If you should have missed the first part of thetutorial, here's a link to the first part:

    http://www.resource.ch/userfiles/medien/blog/SAP_mobile01.pdf

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

    Author: Florian Mller

    Company: Resource AG

    Created on: 22 of Dec. 2010

    Author Bio

    Florian Mller works as a Solution Architect for Resource AG, one of the leading SAP consultingcompanies within Switzerland. Florian focuses on SAP UI technologies in first place, especiallymobile UI technologies are part of his daily SAP business. Furthermore Florian is founder ofrichability (http://www.richability.com) and frequent author for several magazines and books withinthe space of Java & UI Technologies.

    https://www.sdn.sap.com/irj/sdn/nw-mobilehttps://www.sdn.sap.com/irj/sdn/nw-mobilehttps://www.sdn.sap.com/irj/sdn/nw-mobilehttps://www.sdn.sap.com/irj/sdn/nw-mobile
  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    2/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 2

    Table of Contents

    Sum Up ............................................................................................................................................................... 3Outlook - What We will Achieve ......................................................................................................................... 4

    Requirements/ Installations ............................................................................................................................. 5Create the Java Web Service Stubs ................................................................................................................... 6

    Using Java Web Service Stub ...................................................................................................................... 10Next Steps ........................................................................................................................................................ 11Related Content ................................................................................................................................................ 12Disclaimer and Liability Notice .......................................................................................................................... 13

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    3/13

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    4/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 4

    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 boxabove: on the one hand the blue box provides UI stuff to our mobile client (this is NOT covered within this2nd 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 becreated 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 theWSDL 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.

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    5/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 5

    Requirements/ Installations

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

    Eclipse IDE for Java EE developers (3.6): http://www.eclipse.org/downloads/ (!!! MAKESURE YOU CHOSE THE "IDE FOR JAVA EE DEVELOPERS" !!!!)

    Apache Axis (2.1.5.2): http://axis.apache.org/axis2/java/core/

    Download Eclipse IDE as well as Apache Axis, next fire up Eclipse and your are close toimplementing/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 asmyMobileSapWorkspace and wait until Eclipse finished loading. There is one important configuration issuewhich needs to be achieved in order to run Axis2 as Eclipse by default ships with the old Axis1 - using theold Axis would work as well but as there have been huge changes from Axis1 to Axis2 you should link inAxis2:

    Fire up the Eclipse Preferences (Eclipse Preferences) and switch to the Axis2 Preferences - next enter thepath to your downloaded Axis 2 package, see screenshot below...

    Ok - now you are ready to generate the Java stub - congrats! We will create a little demo project (without anyUI stuff) which will access the FLIGHT BAPI Web Service, get some flights and print the results to theconsole window - if we can print Flight BAPI results to the console windows it's just a very little step in thethird part of the tutorial in order to display results on a mobile device (see blow).

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    6/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 6

    Flight BAPI in action

    Create the Java Web Service Stubs

    Ok, let's create a Java access layer to our Web Service which basically enables us to do sth. similar to:

    FlightWebService flightService = new FlightWebService();

    List flights = flightService.getFlights("LH");

    for (int i=0; i

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    7/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 7

    2) Specify project name (e.g. "MySAPService"), and select dynamic web module version 2.5 instead of 3.0(Axis2 works with 2.5 only!). DONT miss this step of switching web module version to 2.5! Then press Next -Next - Next - Finish or Finish directly.

    3) Next thing we have to do is adding the Web Service stuff to our project. Select the newly created projectwithin the project tree at the left, select "New - Other"; a popup comes up, select "Web Services - WebService Client"

    4) A Web Service configuration popup comes up, in the first field, drop your Web Service which should besth. similar to:

    http://riagsrv.riagdom2.resource.ch:9999/sap/bc/srt/wsdl/bndg_DFE5C490AA519FF18F410050569D2CAD/wsdl11/allinone/ws_policy/document?sap-client=300

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    8/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 8

    Then, chose the Web Service runtime (Apache Axis by default and set it to Apache Axis 2): (dont mind ifthere is no server runtime displayed within your project, this entry is not required...)

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    9/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 9

    5) Axis2 will start its work immediately and present the service stub detected behind the Web Service in thenext screen, you can click Finish at this state.

    Have a look into your project (expand the src Folder), you will notice two classes which have been created,these classes will enable you to access your Web Service:

    Before we start using and exploring these classes we have to apply a very little change to this generatedclass manually, since Axis2 by default ignores security credentials which have been placed on top of a WebService (in our case simple authentication based on username and password). I'm pretty sure there is a way

    of generating security stuff directly but as we could not figure out directly we decided to present thisworkaround which is basically adding the required security stuff.

    1) Open the File with the "...Stub" extension (Z_get_flight_listStub.java)

    2) Search for the following string: "_serviceClient.createClient(_operations[0].getName());"

    3) Add the following snippet after the line:

    HttpTransportProperties.Authenticator

    auth = new HttpTransportProperties.Authenticator();

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    10/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 10

    auth.setUsername("username");

    auth.setPassword("*******");

    _operationClient.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstan

    ts.AUTHENTICATE, auth);

    4) Here's what the whole block should look like;

    try{org.apache.axis2.client.OperationClient _operationClient =

    _serviceClient.createClient(_operations[0].getName());

    HttpTransportProperties.Authenticator

    auth = new HttpTransportProperties.Authenticator();

    auth.setUsername("username");

    auth.setPassword("********");

    _operationClient.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstan

    ts.AUTHENTICATE, auth);

    _operationClient.getOptions().setAction("urn:sap-

    com:document:sap:soap:functions:mc-style:z_get_flight_list:ZFlightGetlistRequest");

    _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);

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

    Using Java Web Service Stub

    Ok, the whole Web Service stub is ready for usage right now - which means, we can create a very simpledemo 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();

    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 results...

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

    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 fromFrankfurt to Tokyo which have been looked up within the SAP system.

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    11/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG 11

    Let's sum up what we are doing within this class:

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

    Z_get_flight_listStub stub = new Z_get_flight_listStub();

    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 ispretty clever - Axis checks automatically the datatypes required by your Web Service and creates datatypeclasses - this ensures you do ot push String longer than expected/allowed to the Web Service, it's a nice andefficient manner to prevent you from checking "what dataytpe and which length is expected at theservice...?". (Char20 means datatype Char, maxlength 20)

    // from

    Char20 from = new Char20();

    from.setChar20(fromCity);

    request.setImwCityFrom(from);

    // to

    Char20 to = new Char20();

    to.setChar20(toCity);

    request.setImwCityTo(to);

    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;

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

    Next Steps

    The next tutorial will get you in touch with development of mobile UI based on vaadin. As vaadin is plain Javathere will be no difficulties to connect the stubs created within this tutorial part. Basically the "boiler platestuff" is done at this point of the tutorial, next thing is the really exciting (and funny!) part , which is creatingthe iPhone UI...!

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    12/13

  • 7/27/2019 Creating Mobile Applications on Top of SAP%2c Part 2

    13/13

    Creating Mobile Applications on top of SAP, Part 2

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    Disclaimer and Liability Notice

    This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is notsupported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,and anyone using these methods does so at his/her own risk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article orcode sample, including any liability resulting from incompatibility between the content within this document and the materials andservices offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of thisdocument.