Home
People
Publications
Events
Teaching
Projects
Resources
Contact
Community
Blog

 

 

 

Tutorials
Software
Docs

:: Research Group Embedded Interaction :: Media Informatics :: Ludwig-Maximilians-University Munich


Using JSR-172 on any J2ME-enabled mobile phone

What many programmers do not know is that it is possible to use Sun’s reference implementation of JSR-172 (Sun’s Web Service API – WSA) to use web services on any J2ME mobile phone or PDA that is not equipped with the optional J2ME API. This may save the programmer a lot of work as no additional tools like kSOAP are required and the written program is already compatible to the emerging devices containing the additional web service API

Used Hardware

  • Siemens CX-70 mobile phone

Used Software

  1. Retrieve the WSDL-file of the web service
    If you use Tomcat and AXIS to deploy your web services you can obtain the WSDL-file by opening Tomcat’s web interface (http://localhost:8080/). Then open the Tomcat Manager and click onto “/axis”. After that click onto “List” and a list of the deployed web services will appear. Now simply click onto the link after the desired web service to save the WSDL file onto your computer.

  2. Create the J2ME stub classes
    Open Sun’s WTK 2.2 and create a new project. creating new project with wtk 2.2
  3. This is necessary to use the built-in Stub Generator. You do not need to use the WTK after the generation of the stub classes.

    Now open Project -> Stub Generator:
    create new stub with wtk's stub generator

    Chose the WSDL file you downloaded from the Tomcat web interface beforehand (or retrieved from another source) and enter the package the generated stub classes should be defined in.
    Now simple click onto “OK” and the stub classes are generated in the source folder of the WTK-project.
    If the web service is called Test_WS the WTK will create the classes Test_WS, Test_WS_Stub and two classes for every public method.

  4. Using the web service from the MIDlet
    Download Sun’s WSA from
    http://www.sun.com/software/communitysource/j2me/wsa/download.xml
    The downloaded file j2me_web_services-1_0-src.zip contains the two archives j2me_rpc_ri.jar and j2me_xml_ri.jar in the lib-directory. These two archives must be added to your Eclipse project. This can be done by selecting “Project -> Properties -> Java Build Path -> Add external JARs”.

    In you Eclipse project create a new package that matches the package you entered in step 2 in the WTK (e.g. test.stub).

    Go to the WTK-project’s source-folder and drag the generated stub classes into the corresponding package in your Eclipse project.

    To use a method from the web service from within your MIDlet you simply have to instantiate the class Test_WS and call the desired method (here public int getNumber()).

    Test_WS_Stub stub = new Test_WS_Stub();
    int result = stub.getNumber();

Further Reading

http://developers.sun.com/techtopics/mobility/apis/articles/wsa/index.html
JSR172 Demo project in Sun’s WTK 2.2