Quoter end to end scenario
Author: Lukas Jungmann
Last update: $Date: 2009/10/29 16:50:43 $, $Revision: 1.1.1.1 $
Introduction:
This end to end scenario should test Web service client creation in J2SE project.
The scenario covers developing of simple web service client
The document is not intended as test specification for these
features but describes developing web service client in NetBeans 5.5
(version for NetBeans 5.0 can be found
here)
Table of Contents
- Creating J2SE project
- Creating web service client
- Testing web service
- Implementing main class
- Running application
Quoter sources are avalaible here.
Creating J2SE project
- Go to File - New Project - General - Java Application
- Specify
Quotesas Project Name - Specify project's directory
- Specify
org.netbeans.end2end.quoter.Mainas project main class - Click
Finish
Creating web service client
- Go to File - New File - Web services - Web Service Client - Next
- Specify
http://www.swanandmokashi.com/HomePage/WebServices/QuoteOfTheDay.asmx?WSDLas WSDL URL - Optional: if you're behind proxy check its settings via
Set Proxy ...button - Specify package for the client, eg.
org.netbeans.end2end.quoter.client - Choose
JAX-RPCas JAX version and - Click
Finish
Testing web service
- Go to Web Services References - QuoteofTheDay - QuoteofTheDaySoap - getQuote
in project logical view and invoke
Test Operation
from context menu ofgeQuotenode - Click
Submit - You should see quotation in
Resultsarea - Test several others invokations
- Click
Close
Implementing main class
- Open
org.netbeans.end2end.quoter.Mainin editor - Create new
private Quotes getRandomQuotation()method - Press
Shift+Alt+F- this will fix missing import of org.netbeans.end2end.quoter.client.Quotes. - Right-click inside the
getQuotation()method of theMainclass and invokeWeb Service Client Resources - Call Web Service Operation - Select
getQuoteand clickOKbutton - now IDE generates webservice invokation code:try { // This code block invokes the QuoteofTheDaySoap:getQuote operation on web service org.netbeans.end2end.quoter.client.QuoteofTheDay quoteofTheDay = new org.netbeans.end2end.quoter.client.QuoteofTheDay_Impl(); org.netbeans.end2end.quoter.client.QuoteofTheDaySoap quoteofTheDaySoap = quoteofTheDay.getQuoteofTheDaySoap(); quoteofTheDaySoap.getQuote(/* TODO enter operation arguments*/); } catch(javax.xml.rpc.ServiceException ex) { // TODO handle ServiceException } catch(java.rmi.RemoteException ex) { // TODO handle remote exception } catch(Exception ex) { // TODO handle custom exceptions here } - Tune this method a little so it will look like:
private Quotes getQuotation() { try { // This code block invokes the QuoteofTheDaySoap:getQuote operation on web service org.netbeans.end2end.quoter.client.QuoteofTheDay quoteofTheDay = new org.netbeans.end2end.quoter.client.QuoteofTheDay_Impl(); org.netbeans.end2end.quoter.client.QuoteofTheDaySoap quoteofTheDaySoap = quoteofTheDay.getQuoteofTheDaySoap(); return quoteofTheDaySoap.getQuote(); } catch(javax.xml.rpc.ServiceException ex) { // TODO handle ServiceException ex.printStackTrace(System.out); } catch(java.rmi.RemoteException ex) { // TODO handle remote exception ex.printStackTrace(System.out); } catch(Exception ex) { // TODO handle custom exceptions here ex.printStackTrace(System.out); } return null; } - And don't forget to implement main method:
public static void main(String[] args) { // TODO code application logic here Main m = new Main(); Quotes quote = m.getQuotation(); if (quote != null) { System.out.println(quote.getQuoteOfTheDay()); System.out.println("--" + quote.getAuthor()); } else { System.out.println("There was some error while talking to service."); } }
Running application
- Now we've done our application and we can run it. Here's sample
output:
