Java Reference
In-Depth Information
The class in Example 6-9 shows how you construct a client that uses JAX-WS generated ob-
jects from that WSDL as well as the Headers.create reference implementation convenience
method to set a complex object into a header.
Example6-9.Setting a complex object into a SOAP header with JAXB and Headers.create
package headersclientsiaddress;
import com.sun.xml.ws.api.message.Headers;
import com.sun.xml.ws.developer.WSBindingProvider;
import javax.xml.namespace.QName;
import com.strikeiron.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* Creates a compound object (License) generated by JAX-WS as
* a JAXB object so we can marshall it into XML to attach as
* a SOAP header before invoking service.
*/
public class Main {
public static void main(String... args) {
try {
//instantiate JAX-WS service object and its port
AddressDistanceCalculator service =
new AddressDistanceCalculator();
AddressDistanceCalculatorSoap port =
service.getAddressDistanceCalculatorSoap();
//After registering, use your values here.
RegisteredUser registeredUser = new RegisteredUser();
registeredUser.setUserID("eben@example.com");
registeredUser.setPassword("secret");
LicenseInfo licenseInfo = new LicenseInfo();
licenseInfo.setRegisteredUser(registeredUser);
//setup a context to marshall our license header info
JAXBContext jaxbContext = JAXBContext.newInstance(
LicenseInfo.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
Search WWH ::




Custom Search