Java Reference
In-Depth Information
//show result
System.out.println("Distance: " + result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
This code is doing a lot, so let's break it up a bit. Here you're getting a JAXB context on the
LicenseInfo class. That means that the JAXB runtime will “recognize” an instance of Li-
censeInfo and any classes it references. You then create a JAXBElement , parameterized on
the LicenseInfo class, which will allow you to marshal an instance of that class into XML,
even though it may not be annotated with @XmlRoot . You then create a DOM document in-
stance that will hold the XML tree of the license info object; the XML content is populated in
the DOM tree at the invocation of the marshal method.
Now that your headers are prepared, you downcast the port you get off of the proxy to an
instance of WSBindingProvider . This allows you to call the convenience method setOut-
boundHeaders . Because so far you only have the license info XML content that is bound in
your DOM document's root element, you need to wrap them as SOAP headers before setting
them on the port. You do that using the Headers.create method, which will wrap your XML
license info content into SOAP headers.
NOTE
You can read the JavaDoc for JAXB at https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/index.html .
So at this point, you are home free. All you have to do is continue to populate your generated
objects as you normally would, and invoke the addressToAddressDistance method on your
port, as you normally would. The WSBindingProvider has already taken care of setting the
headers for any outbound invocations off of that port, so you don't need to do anything further.
This is in contrast to the prior method of sending headers with a request; no holder is required,
and the operation invocation isn't as confusing. The downside, however, is that this client in-
vocation requires classes in the reference implementation, making your client less portable.
NOTE
You may need to add the webservices-rt.jarto your project's classpath in order to use the tools in the
com.sun.xml.ws packages.
Search WWH ::




Custom Search