Setting Up the Web Service
Xignite has several web services available for demonstration and testing purposes. The XigniteQuotes service
used here provides delayed quotes for US Equities as well as the current status of major indices. The service exposes several operations; the GetQuickQuotes
operation seems like a good fit for getting the simplest solution working for this example. Retrieve the WSDL by accessing the URL http://www.xignite.com/xQuotes.asmx?WSDL
. Save a copy as xQuotes.wsdl
and place it in the
directory you created earlier.
You can download the code
that accompanies this article to follow along.
WebLogic Workshop has a great utility for creating web service clients that makes it easy to start using web services. Select File --> New --> Other, and then choose the Web Service Client wizard. Figure 3
shows the dialog.
|Figure 3. Select a Wizard: Select the Web Service Client wizard to create a Java class to connect to a web service.|
Follow the wizard, accepting the default values. When prompted to enter a reference to your WSDL, select the xQuotes.wsdl
file you saved to the /WebContent/wsclient/
folder earlier. The wizard converts the Xignite WSDL into java classes, placing the generated code in a com.xignite.www.services
package. Although the package contains more than one class, for this article, you'll need the XigniteQuotesSoap class. The interface exposes a getQuickQuotes
method, which represents the GetQuickQuotes
operation of the web service. The method returns an ArrayOfQuickQuote object that holds an array of quotes returned from the web service.
The code that invokes the Xignite Web Service is located in the StockQuotesPortlet's processAction()
method. You saw it referenced earlier in the commented code lines:
XigniteQuotes objQuotesService = new XigniteQuotesLocator();
XigniteQuotesSoap objQuotesPort =
The portlet sets up a XigniteQuotes service object and retrieves a XigniteQuotesSoapStub object, which it then upcasts to the XigniteQuotesSoap interface. Take a look at the XigniteQuotesSoapStub implementation class to get a better understanding of how the calls to the web service are being made.
Xignite has several authentication implementation options available for you to use. The sample application passes the authentication credentials in the SOAP message header. Be sure to enter the login credentials you supplied during registering at Xignite's site into the portlet preferences section of the portlet.xml file.
|Authors' Note: There are limitations on the number of requests you can make on the web service within a specified time frame, so make certain you manage the number of times you access the service during development. This limitation only applies to the free demonstration version, not to those who have purchased Xignite's web services.
The next line of code casts the XigniteQuotesSoap object to the org.apache.axis.Stub object. The Stub object contains methods that provide access to the SOAP headers so you can manipulate authentication credentials:
org.apache.axis.client.Stub stub = (Stub) objQuotesPort;
method adds the authentication credentials to the SOAP header. A detailed discussion of what happens in the code is outside the scope of this article; however, you can review the code to gain a deeper understanding of how to manipulate the SOAP message header:
addAuthenticationHeader(username, password, stub);
Finally, the portal invokes the web service:
ArrayOfQuickQuote objQuickQuote =
The XigniteQuotesSoap object's getQuickQuotes()
method takes a list of stock symbols or indices as an argument and returns an ArrayOfQuickQuote object containing an array of com.xignite.www.services.QuickQuote objects. These objects are used to pass the resulting data to the user interface for display.
The final step in the process is to prepare the data for presentation:
if (objQuickQuote.getQuickQuote(0).getOutcome() ==
List<Quote> quotes = new ArrayList<Quote>();
for (int i = 0; i < objQuickQuote.getQuickQuote().length; i++)
quote = new Quote();
throw new Exception(
.toString() + ": " +
The JSP page remains free of any implementation-specific code by using a custom Quote object. The Quote object is a simple bean used to hold record values. You can certainly skip this step for simplicity by accessing the implementation objects directly in the JSP if you so desire.
If errors occur during a web service call, the returned ArrayOfQuickQuote object will contain outcome types that can assist with debugging the service calls. As the preceding code shows, calling the getOutcome()
method returns an OutcomeTypes object indicating the result of the operation. Possible outcome types include:
- Success: invoking the web service is successful and no errors were detected.
- SystemError: the web service provider did not execute properly.
- RequestError: the SOAP message request had problems when delivered to the web service.
- RegistrationError: there was a problem with the authentication credentials, or something is wrong with your account. (Hint: check that your login credentials are correct in the portlet.xml file.)