Professional Documents
Culture Documents
Build J2ME Web Services Application With A1200: Technical Article
Build J2ME Web Services Application With A1200: Technical Article
Services Application
with A1200
July 7, 2006
TECHNICAL ARTICLE
Build your J2ME Web Services Application with A1200
By
MOTODEV Staff
owadays, XML is the standard way clients to interact with backend servers so as to use the remote
N services. The Motorola A1200 handset supports JSR 172 optional packages, J2ME Web services,
which includes two independent parts: the JAX-RPC and JAXP. J2ME JAX-RPC APIs subset
solves how to access the SOAP/XML Web services and JAXP APIs subset solves how to processes the
XML messages.
In this article, we first introduce some basic concepts in J2ME Web services and show its limitations
compared to standard J2SE JAXP and JAX-RPC; then we build a little J2ME Web services application
with the Motorola SDK, SUN WTK2.2 stub generator and Apache Axis.
Basic concepts
JSR172 stipulates a set of lightweight APIs to be used in resource-limited devices. It provides access to
Web services available in J2ME and Web services processing the on the client side. Compared to its
corresponding J2SE super set, it has many limitations.
The JSR172 JAX-RPC APIs (a subset of J2SE’s JAX-RPC) do not support the server end; the handset
can only consume Web services but can’t supply them. It does not support UDDI, which means it can’t
discover Web services. It does not support SAAJ (SOAP with Attachment API for Java). It does not
support dynamic proxies or dynamic invocation interface (DII).
The JSR172 JAXP APIs (a subset of J2SE’s JAXP) do not support DOM, because the DOM is
considered to be too heavy for handset. It does not support XSLT. Also, SOAP message handlers are not
supported.
Example
A J2ME-based service client uses generated stub classes to access a Web service. The following steps
show how a J2ME JAX-RPC Subset client interacts with a Web service endpoint. Tomcat is a
JSP/Servlet container and Axis is an implementation of SOAP that is used to offer Web services.
J2ME application
JAX-RPC stub
SOAP/XML
MIDP/CLDC
Download Tomcat 5.5.17 and Axis 1.4 from the URL below and install
http://mirror.vmmatrix.net/apache/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.5.17.zip
http://apache.justdn.org/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.5.17-admin.zip
http://mirror.vmmatrix.net/apache/ws/axis/1_4/axis-bin-1_4.zip
Please view the installation guides for Apache and Tomcat for details on installation. After installation,
test Tomcat and Axis with the URL below (For this example, we’ll use 18080 as the TCP port for
Tomcat)
http://localhost:18080
http://localhost:18080/axis
Create the java class of the Web service and deploy it on the server side
AXIS_HOME = C:\axis-1_4
AXIS_LIB = %AXIS_HOME%\lib
AXISCLASSPATH = %AXIS_LIB%\axis.jar; %AXIS_LIB%\commons-discovery-0.2.jar;
%AXIS_LIB%\commons-logging-1.0.4.jar; %AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;
%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\xml-apis.jar; %AXIS_LIB%\xercesImpl.jar
package servicepack;
public class ResponseService {
public String helloClient() {
return "Hello Client, this is server!" ;
}
}
</deployment>
Generate the WSDL file of the Web service in document/literal style from java class
Then click the urn:helloClient (wsdl) hyperlink to generate the WSDL file of the Web service.
The helloClient service can also be tested by inputting the URL below, which will generate the SOAP
response.
http://localhost:18080/axis/services/urn:helloClient?method=helloClient
In the Sun Wireless Tool Kit 2.2 Utilities, select Stub Generator.
Four files were generated in the com.mot.WSDemo package:
ResponseService.java,
ResponseService.class,
ResponseService_Stub.java,
ResponseService_Stub.class
Figure 3: WTK 2.2 stub generator dialog
Import the stub files into the J2ME package, instantiate an instance of the stub and invoke methods on
the stub corresponding to the service endpoints
Package the stub with the J2ME client application and run it on the Motorola emulator
Figure 4: Calling the Web service from J2ME Client in Motorola Emulator
Conclusion
The JSR172 APIs are powerful and easy to use, but a lack of dynamic proxies and dynamic invocation
interface (DII) support makes the J2ME application less flexible. Because not all handsets support
JSR172 (Motorola began supporting JSR172 in the A1200 and ROKR E2 handsets), sometimes the open
source J2ME software like KSOAP is still a good alternative.
Sample Application
WSDemo.zip
References
JSR 172: J2ME Web Services Specification
Apache web services-Axis
Apache Tomcat
J2EE Web Services – The Ultimate Guide, Richard Monson-Haefel