Java Reference
In-Depth Information
Date --> 4/16/2014
Time --> 4:01pm
Change --> -0.62
Open --> 197.77
High --> 198.71
Low --> 195.00
Volume --> 8527415
MktCap --> 204.5B
PreviousClose --> 197.02
PercentageChange --> -0.31%
AnnRange --> 172.19 - 211.98
Earns --> 14.942
P-E --> 13.19
Name --> International Bus
Take some time to explore the code you've written at your own leisure. Try experimenting with dif-
ferent stock symbols, or if you feel up to it, try selecting one of the other provided web services at
WebserviceX.NET and see whether you can get it to work (the “Global Weather” service— http://
www.webservicex.net/ws/WSDetails.aspx?CATID=12&WSID=56 —works nicely).
In this section, you've been accessing SOAP services in a very ad hoc manner, constructing SOAP
messages by hand and parsing the responses manually. You had to look up the correct endpoint URI
and hostname to use, and had to deal with picky server error messages. Luckily, many SOAP web
services also provide a so‐called WSDL file that describes the operations the service offers, together
with the ways they can be accessed. JAX‐WS contains a handy feature to automatically construct a
set of service‐interacting classes from this WSDL file, as you'll see in the following section.
First, however, this section ends with a hands‐on Try It Out. It shows you how to clean up the code
you've written some more, if you're up for it.
A true Object‐Oriented SOAp Client
try it out
The code you wrote to access a SOAP client does not really look like clean, object‐oriented Java code.
In fact, the code has more similarities to a procedural scripting language, with one big main method
delegating some tasks to other static methods.
For building a quick prototype—e.g., when you're just starting out and trying to see if you can get your
SOAP client to work—this is fine, but in real‐life applications, you'll want to clean up your code to be
more in line with the object‐oriented paradigm.
Let's see how you can do this for the stock quote client. The goal is to abstract away the complexity of
SOAP interaction and to provide an object structure for your applications to work with.
1.
Create a new package called withoutwsdlobjectoriented to hold your classes (feel free to pick a
more suitable or creative name, but this one will match the code provided with this topic). As you
know by now, when you think about objects and classes, you want your classes to represent your
domain concepts. What is your most primary concept in a stock quote application? Naturally, a
class representing a stock symbol and its information. As such, create a Stock class as follows:
package withoutwsdlobjectoriented;
import java.util.Date;
Search WWH ::




Custom Search