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


Quoter sources are avalaible here.

Creating J2SE project

  • Go to File - New Project - General - Java Application
  • Specify Quotes as Project Name
  • Specify project's directory
  • Specify org.netbeans.end2end.quoter.Main as 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?WSDL as 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-RPC as 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 of geQuote node
  • Click Submit
  • You should see quotation in Results area
  • Test several others invokations
  • Click Close
  • Implementing main class

    • Open org.netbeans.end2end.quoter.Main in 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 the Main class and invoke Web Service Client Resources - Call Web Service Operation
    • Select getQuote and click OK button - 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:

    Project Features

    About this Project

    QA was started in November 2009, is owned by Jiří Kovalský, and has 97 members.
    By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
     
     
    Close
    loading
    Please Confirm
    Close