Java Reference
In-Depth Information
3. The application generates an XML document representing the web service
request (often referred to as marshalling data for the request).
4. Using HTTP, the application transmits the XML document to the remote web
service via a POST request.
5. Using HTTP, the application receives a response XML document from the remote
web service.
6. The application parses the resulting XML document to obtain values of interest
for the application or user (often referred to as unmarshalling the response).
7. The application uses the data it obtained from parsing the resulting XML
document.
Thus, web services pose three common programming tasks for Java ME developers
that are amenable to generalization across multiple applications through the addition of
new APIs:
• Interaction with a remote server using HTTP (as you saw in Chapter 12, the GCF
and the HttpConnection and HttpsConnection handle this)
• Generation of an XML document—typically represented as an instance of
String —from Java objects
• Parsing of an XML document to obtain values to place in fields of one or more
Java objects
The GCF ably addresses the first problem; in addition, there's support for encapsulat-
ing the GCF functionality in the J2ME Web Services Specification, which I say more about
in the “Introducing the J2ME Web Services Specification” section later in this chapter.
XML generation in Java ME—the second problem—typically takes one of two forms: sim-
ple concatenation using template components and an instance of the StringBuffer class,
or use of the SOA-supporting J2ME Web Services Specification. I discuss each of these in
subsequent sections of this chapter. You can solve the third problem—parsing XML—in
one of two ways, by either relying on the optional Web Services Specification or including
a lightweight parser like kXML in your application.
XML parsers come in three varieties: DOM parsers, push parsers, and pull parsers.
DOM parsers parse an entire document and return an instance of a document tree
that lets you query for elements of the tree using its methods; they are typically expen-
sive both to implement and represent the document tree, and they're generally not
used in the Java ME environment. Push parsers call a client interface's methods with
XML events, such as the definition of a tag; in essence, they “push” data from the XML
 
Search WWH ::




Custom Search