KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > multibinding > client > stub > Run


1 package multibinding.client.stub;
2
3 import org.apache.wsif.WSIFService;
4 import org.apache.wsif.WSIFServiceFactory;
5 import org.apache.wsif.WSIFException;
6 import java.rmi.RemoteException JavaDoc;
7 import multibinding.client.stub.com.themindelectric.www.NetXmethodsServicesStockquoteStockQuotePortType;
8
9 /**
10  * Simple class that Runs the multibinding sample using a pregenerated stub interface
11  * To use this class, provide a company stock symbol and an optional port preference
12  * on the command line. WSIF should then invoke the service with this information,
13  * using the appropriate port and returning with a recent stockquote.
14  * @author Nirmal K. Mukhi (nmukhi@us.ibm.com)
15  */

16
17 public class Run {
18     
19     public static void main(String JavaDoc[] args) {
20         try {
21
22             if (args.length != 2 && args.length!= 3) {
23                 System.out.println(
24                     "Usage: java multibinding.client.stub.Run <wsdl location> <company symbol> [StockQuoteJavaPort|StockQuoteSOAPPort]");
25                 System.exit(1);
26             }
27
28             // create a service factory
29
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
30
31             // parse WSDL
32
WSIFService service =
33                 factory.getService(
34                     args[0],
35                     null,
36                     null,
37                     "http://www.themindelectric.com/wsdl/net.xmethods.services.stockquote.StockQuote/",
38                     "net.xmethods.services.stockquote.StockQuotePortType");
39             // create the stub
40
// check if the user specified a preferred port
41
NetXmethodsServicesStockquoteStockQuotePortType stub = null;
42         if (args[2]!=null)
43         stub = (NetXmethodsServicesStockquoteStockQuotePortType)
44             service.getStub(args[2],NetXmethodsServicesStockquoteStockQuotePortType.class);
45         else
46         stub = (NetXmethodsServicesStockquoteStockQuotePortType)
47             service.getStub(NetXmethodsServicesStockquoteStockQuotePortType.class);
48
49             // do the invocation
50
// args[1] is the company symbol
51
float quote = stub.getQuote(args[1]);
52             System.out.println(quote);
53
54         } catch (WSIFException we) {
55             System.out.println(
56                 "Error while executing sample, received an exception from WSIF; details:");
57             we.printStackTrace();
58         } catch (RemoteException JavaDoc re) {
59             System.out.println(
60                 "Error while executing sample, received an exception due to remote invocation; details:");
61             re.printStackTrace();
62         }
63     }
64 }
65
Popular Tags