1 package samples.jms.dii; 2 3 import org.apache.axis.AxisFault; 4 import org.apache.axis.client.Call; 5 import org.apache.axis.client.Service; 6 import org.apache.axis.configuration.XMLStringProvider; 7 import org.apache.axis.deployment.wsdd.WSDDConstants; 8 import org.apache.axis.encoding.XMLType; 9 import org.apache.axis.transport.jms.JMSConstants; 10 import org.apache.axis.transport.jms.JMSTransport; 11 import org.apache.axis.transport.jms.SimpleJMSListener; 12 import org.apache.axis.utils.Options; 13 14 import javax.xml.namespace.QName ; 15 import javax.xml.rpc.ParameterMode ; 16 import java.util.HashMap ; 17 18 26 27 public class JMSURLTest { 28 static final String wsdd = 29 "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " + 30 "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" + 31 " <transport name=\"JMSTransport\" pivot=\"java:org.apache.axis.transport.jms.JMSSender\"/>\n" + 32 " <service name=\"" + WSDDConstants.URI_WSDD + "\" provider=\"java:MSG\">\n" + 33 " <parameter name=\"allowedMethods\" value=\"AdminService\"/>\n" + 34 " <parameter name=\"className\" value=\"org.apache.axis.utils.Admin\"/>\n" + 35 " </service>\n" + 36 "</deployment>"; 37 38 static String sampleJmsUrl = "jms:/MyQ?" + 40 "vendor=JNDI" + 41 "&java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory" + 42 "&java.naming.provider.url=file:///c:/JNDIStore" + 43 "&ConnectionFactoryJNDIName=MyCF" + 44 "&deliveryMode=persistent" + 45 "&priority=5" + 46 "&ttl=10000" + 47 "&debug=true"; 48 57 58 public static void main(String args[]) throws Exception { 59 Options opts = new Options( args ); 60 61 if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0)) 63 printUsage(); 64 65 String username = opts.getUser(); 66 String password = opts.getPassword(); 67 68 HashMap connectorMap = SimpleJMSListener.createConnectorMap(opts); 69 HashMap cfMap = SimpleJMSListener.createCFMap(opts); 70 String destination = opts.isValueSet('d'); 71 72 SimpleJMSListener listener = new SimpleJMSListener(connectorMap, 74 cfMap, 75 destination, 76 username, 77 password, 78 false); 79 listener.start(); 80 81 args = opts.getRemainingArgs(); 82 if ( args == null || args.length == 0) 83 printUsage(); 84 85 for (int i = 0; i < args.length; i++) 86 { 87 try 88 { 89 Float res = getQuote(args[i], username, password); 90 System.out.println(args[i] + ": " + res); 91 } 92 catch(AxisFault af) 93 { 94 System.out.println(af.dumpToString()); 95 } 96 } 97 98 listener.shutdown(); 100 101 JMSTransport.closeMatchingJMSConnectors(sampleJmsUrl, username, password); 104 105 System.exit(1); 106 } 107 108 public static Float getQuote(String ticker, String username, String password) 109 throws javax.xml.rpc.ServiceException , AxisFault 110 { 111 Float res = new Float (-1.0); 112 113 Service service = new Service(new XMLStringProvider(wsdd)); 114 115 Call call = (Call) service.createCall(); 117 call.setOperationName( new QName ("urn:xmltoday-delayed-quotes", "getQuote") ); 118 call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); 119 call.setReturnType( XMLType.XSD_FLOAT ); 120 121 try 122 { 123 java.net.URL jmsurl = new java.net.URL (sampleJmsUrl); 124 call.setTargetEndpointAddress(jmsurl); 125 126 call.setUsername(username); 128 call.setPassword(password); 129 call.setTimeout(new Integer (30000)); 130 131 res = (Float ) call.invoke(new Object [] {ticker}); 132 } 133 catch (java.net.MalformedURLException e) 134 { 135 throw new AxisFault("Invalid JMS URL", e); 136 } 137 catch (java.rmi.RemoteException e) 138 { 139 throw new AxisFault("Failed in getQuote()", e); 140 } 141 142 return res; 143 } 144 145 public static void printUsage() 146 { 147 System.out.println("JMSURLTest: Tests JMS transport by obtaining stock quote"); 148 System.out.println(" Usage: JMSURLTest <symbol 1> <symbol 2> <symbol 3> ..."); 149 System.out.println(" Opts: -? this message"); 150 System.out.println(); 151 System.out.println(" -c connection factory properties filename"); 152 System.out.println(" -d destination"); 153 System.out.println(" -t topic [absence of -t indicates queue]"); 154 System.out.println(); 155 System.out.println(" -u username"); 156 System.out.println(" -w password"); 157 System.out.println(); 158 System.out.println(" -s single-threaded listener"); 159 System.out.println(" [absence of option => multithreaded]"); 160 161 System.exit(1); 162 } 163 } 164 | Popular Tags |