FeaturesPluginsDocs & SupportCommunityPartners

Quoter end to end scenario

Author: Lukas Jungmann
Last update: $Date: 2006/07/15 02:35:25 $, $Revision: 1.5 $
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:
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by