At this point, doGet()
executes Source result = dispatch.invoke(null);
, passing null
instead of a Source
object as an argument because the provider's doGet()
method expects to receive its data as a query string. If an exception occurs during the invocation, a catch block outputs the exception information and exits doGet()
. Otherwise, the result object's XML content is transformed into a javax.xml.transform.dom.DOMResult
object, which is processed via XPath expressions to obtain result data, which is then output.
If you were to run LibraryClient
with Listing 9's doGet()
method (you'll need to insert --add-module java.xml.ws
on the javac
and java
command lines when using Java SE 9), and if you were to use the same book-related data presented in Part 3, you would observe the following output:
<?xml version="1.0" ?><response>book inserted</response>
<?xml version="1.0" ?><response>book inserted</response>
9781430210450
0201548550
Title: Advanced C+
Author: James O. Coplien
ISBN: 0201548550
Publication Year: 1992
Publisher: Addison Wesley
Title: Beginning Groovy and Grails
Author: Christopher M. Judd
Author: Joseph Faisal Nusairat
Author: James Shingler
ISBN: 9781430210450
Publication Year: 2008
Publisher: Apress
<?xml version="1.0" ?><response>book updated</response>
Title: Advanced C++
Author: James O. Coplien
ISBN: 0201548550
Publication Year: 1992
Publisher: Addison Wesley
<?xml version="1.0" ?><response>book deleted</response>
9781430210450
Conclusion
Now that you've completed this series on Web services in Java SE, I have some homework that will reinforce your understanding of what you've read:
- Create a SOAP-based Library Web service that recognizes two operations, expressed via methods
void addBook(String isbn, String title)
andString getTitle(String isbn)
. Create aLibraryClient
application that invokesaddBook()
followed bygetTitle()
to test this Web service. - Create a
LibraryClientSAAJ
application that uses SAAJ to perform the equivalent ofLibraryClient
's tasks. UseSOAPMessage
'swriteTo()
method to output each of the request and response messages for theaddBook
andgetTitle
operations. - The RESTful Web service described by Part 3's
Library
class is flawed in that thedoDelete()
method doesn't notify the client when requested to delete a nonexistent book. How might you modify this method to report this attempt?
You'll find the answers to these exercises in the answers\Library
directory of the code archive that accompanies this article. To gain the most benefit from this series, give the exercises an honest try before peeking at the answers.
The following software was used to develop the post's code:
- 64-bit JDK 9ea+181
The post's code was tested on the following platform(s):
- JVM on 64-bit Windows 10
This story, "Web services in Java SE, Part 4: SOAP with Attachments API for Java" was originally published by JavaWorld.