Java Reference
In-Depth Information
Using
a
JAXB-Annotated
Instance
in
a
SOAP
Message
Problem
You want to work with an object view of the contents of your SOAP request, rather than work-
ing with low-level XML plumbing to build messages. You have a Java object that was created
from a JAXB-annotated class. You want to want to automatically marshal this into XML and
use it as the child element of the body of a SOAP request.
Solution
Generate the client-side objects with a tool such as wsimport (or, if using Apache Axis, the
WSDL2Java tool). Then use the generated object model normally. All of the necessary XML
is hidden from you.
Discussion
The important aspect of this recipe is that it shows you that with JAX-WS, it's almost as easy
to use complex types as it is to use primary types for service operation parameters.
In this example, you'll use a catalog service that represents a database of topics, as shown in
the following code:
@WebService(serviceName="CatalogService", name="Catalog",
targetNamespace="http://ns.soacookbook.com/ws/catalog")
@Stateless
@Local
public class CatalogEJB {
@WebMethod
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.BARE)
public @WebResult(name="searchResults",
targetNamespace="http://ns.soacookbook.com/catalog")
SearchResults
authorSearch(
@WebParam(name="author",
targetNamespace="http://ns.soacookbook.com/catalog") Author
author)
Search WWH ::




Custom Search