Professional Documents
Culture Documents
Notes
Objectives
At the end of this presentation, the participant will
be able to:
Understand the role of JAXB as a web service data
binding solution.
Model data entities using JAXB annotations.
Understand the purpose and usage of the CXF
WSDL2Java tool.
Be able to use WSDL2Java to generate a client
proxy in a stand-alone Java application.
Be able to configure Spring to manage and consume
a generated WSDL2Java client proxy .
Introduction
In all software applications and data
management systems, languages are
necessary to describe the data and perform
instructions. A single language is rarely
adequate in real-world applications, certainly
not in the enterprise. Usually at least two
languages are necessary:
A language to describe the data for storage
or transfer.
A language to perform manipulations on that
data.
XML
Java
Streaming
An event-based API for operating on each piece of
the XML document individually and in sequence.
XML-to-Object Binding
XML types and elements are bound to Java types
and fields.
JAXB: Unmarshalling
JAXB: Marshalling
Demo
XML Output without JAXB Annotations
JAXB: Annotations
Annotations control many aspects of XML
marshalling:
The @XmlRootElement annotation is required for
classes that represent an XML document root
element. All other annotations are optional in most
cases, but useful nonetheless:
Other annotations tell JAXB whether to unmarshal a
field into an attribute or an element.
They can inform JAXB of ID fields, element order, and
other schema constraints.
They can be used to identify or customize schema
types, element names, attribute names, element
wrapping, and so forth.
The @XmlTransient annotation can tell JAXB to
Demo
XML Output with JAXB Annotations
WSDL to Java
Consuming 3rd Party Web Services
WSDL 2 Java
Third-party SOAP web services are typically
consumed in one of two ways:
Using a client JAR prepared by the service
provider.
Contains the necessary Java classes and stubs for
accessing the web service.
Demos
http://www.webservicex.net/geoipservice.asmx?wsdl
wsdl2java (CXF)
http://cxf.apache.org/docs/wsdl-to-java.html
When to use?
Need to customize what is generated
Want to avoid dependence on build tools
org.apache.cxf:cxf-codegen-plugin
Uses the CXF wsdl2java tool
When to use?
Need to stay up-to-date with a changing WSDL.
Dont need to tweak generated code
Dont want to own or manage the generated source
code.
Maven execution:
<execution>
<id>wsdl2java</id>
<phase>generate-sources</phase>
<goals><goal>wsdl2java</goal></goals>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${wsdlUrl}</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
endpoint
The published endpoint service address.
wam-authenticator, wam-cookie-resolver-ref
Provides authentication through WAM
ssl-trust-server
Specifies whether the servers SSL cert should be
automatically trusted.
Demo
Using an endpoint interface generated
by WSDL to Java in a Spring integration
test.
Conclusion
Resources
On the web:
http://cxf.apache.org
Java 6 API Documentation
JDK 6 Programmer Guides
Java Stack Documentation