1 16 package samples.jms.stub; 17 18 import samples.jms.stub.xmltoday_delayed_quotes.*; 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.utils.Options; 21 import org.apache.axis.transport.jms.JMSTransport; 22 import org.apache.axis.transport.jms.SimpleJMSListener; 23 import java.util.HashMap ; 24 25 import junit.framework.AssertionFailedError; 26 import junit.framework.TestCase; 27 28 import java.rmi.RemoteException ; 29 30 import javax.xml.rpc.ServiceException ; 31 import javax.xml.rpc.Stub ; 32 33 41 42 public class JMSURLStubTest extends TestCase { 43 public JMSURLStubTest(String name) { 44 super(name); 45 } 46 47 public static Float getQuote(String ticker) throws AxisFault { 48 float quote = -1.0F; 49 50 GetQuoteServiceLocator locator = new GetQuoteServiceLocator(); 51 GetQuote getQuote; 52 53 try { 54 getQuote = locator.getGetQuote(); 55 } 56 catch (ServiceException e) { 57 throw new AxisFault("JAX-RPC ServiceException caught: ", e); 58 } 59 assertTrue("getQuote is null", getQuote != null); 60 61 try { 62 quote = getQuote.getQuote(ticker); 63 System.out.println("quote: " + quote); 64 65 String endptAddr = locator.getGetQuoteAddress(); 68 JMSTransport.closeMatchingJMSConnectors(endptAddr, null, null); 69 } 70 catch (RemoteException e) { 71 throw new AxisFault("Remote Exception caught: ", e); 72 } 73 return new Float (quote); 74 } 75 76 public static void printUsage() 77 { 78 System.out.println("JMSURLStubTest: Tests JMS transport by obtaining stock quote using wsdl2java-generated stub classes"); 79 System.out.println(" Usage: JMSURLStubTest <symbol 1> <symbol 2> <symbol 3> ..."); 80 System.out.println(" Opts: -? this message"); 81 System.out.println(); 82 System.out.println(" -c connection factory properties filename"); 83 System.out.println(" -d destination"); 84 System.out.println(" -t topic [absence of -t indicates queue]"); 85 System.out.println(); 86 System.out.println(" -u username"); 87 System.out.println(" -w password"); 88 System.out.println(); 89 System.out.println(" -s single-threaded listener"); 90 System.out.println(" [absence of option => multithreaded]"); 91 92 System.exit(1); 93 } 94 95 98 public static void main(String [] args) throws Exception 99 { 100 Options opts = new Options( args ); 101 102 if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0)) 104 printUsage(); 105 106 String username = opts.getUser(); 107 String password = opts.getPassword(); 108 109 HashMap connectorMap = SimpleJMSListener.createConnectorMap(opts); 110 HashMap cfMap = SimpleJMSListener.createCFMap(opts); 111 String destination = opts.isValueSet('d'); 112 113 args = opts.getRemainingArgs(); 114 if ( args == null || args.length == 0) 115 printUsage(); 116 117 SimpleJMSListener listener = new SimpleJMSListener(connectorMap, 119 cfMap, 120 destination, 121 username, 122 password, 123 false); 124 listener.start(); 125 126 JMSURLStubTest stubTest = new JMSURLStubTest("JMS URL static stub test"); 127 128 for (int i = 0; i < args.length; i++) 129 { 130 try 131 { 132 Float quote = stubTest.getQuote(args[i]); 133 System.out.println(args[i] + ": " + quote); 134 } 135 catch(AxisFault af) 136 { 137 System.out.println(af.dumpToString()); 138 } 139 } 140 141 listener.shutdown(); 142 143 System.exit(1); 144 } 145 } 146 | Popular Tags |