FILTERING XML AND JAX-WS
As always, you might be interested in processing only a portion of the XML data even when us-
ing JAXB. Normally, JAX-WS will translate all the XML into JAXB-created Java objects. That's
great from an ease-of-use perspective; it makes the application code much easier to write and
maintain. But if access is needed only to a portion of the XML, all that JAXB processing may be
too expensive, and all those JAXB objects may consume too much heap.
In this case, the XML data should be sent as an attachment to the SOAP message (using a MIME
type of application/xml ). The attachments are not translated into JAXB objects, and you can use
either a filtering DOM builder or a simple StAX parser to process only that part of the document
you are interested in.
1. For XML documents, producing Java objects via JAXB yields the simplest pro-
gramming model for accessing and using the data.
2. Creating the JAXB objects will be more expensive than creating a DOM object
3. Writing out XML data from JAXB objects will be faster than writing out a DOM
XML, JSON, and similar text-based formats are useful for exchanging data between different
kinds of systems. Between Java processes, data is typically exchanged by sending the serial-
ized state of an object. Although it is used extensively throughout Java, serialization has two
important considerations in Java EE:
▪ EJB calls between Java EE servers—remote EJB calls—use serialization to exchange
▪ HTTP session state is saved via object serialization, which enables HTTP sessions to be