1 16 17 package samples.jms; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.client.Call; 21 import org.apache.axis.client.Service; 22 import org.apache.axis.configuration.XMLStringProvider; 23 import org.apache.axis.deployment.wsdd.WSDDConstants; 24 import org.apache.axis.encoding.XMLType; 25 import org.apache.axis.transport.jms.JMSConstants; 26 import org.apache.axis.transport.jms.JMSTransport; 27 import org.apache.axis.transport.jms.SimpleJMSListener; 28 import org.apache.axis.utils.Options; 29 30 import javax.xml.namespace.QName ; 31 import javax.xml.rpc.ParameterMode ; 32 import java.util.HashMap ; 33 34 48 49 public class JMSTest { 50 static final String wsdd = 51 "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " + 52 "xmlns:java=\"" + WSDDConstants.URI_WSDD_JAVA + "\">\n" + 53 " <transport name=\"JMSTransport\" pivot=\"java:org.apache.axis.transport.jms.JMSSender\"/>\n" + 54 " <service name=\"" + WSDDConstants.URI_WSDD + "\" provider=\"java:MSG\">\n" + 55 " <parameter name=\"allowedMethods\" value=\"AdminService\"/>\n" + 56 " <parameter name=\"className\" value=\"org.apache.axis.utils.Admin\"/>\n" + 57 " </service>\n" + 58 "</deployment>"; 59 60 public static void main(String args[]) throws Exception { 61 Options opts = new Options( args ); 62 63 if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0)) 65 printUsage(); 66 67 HashMap connectorMap = SimpleJMSListener.createConnectorMap(opts); 68 HashMap cfMap = SimpleJMSListener.createCFMap(opts); 69 String destination = opts.isValueSet('d'); 70 String username = opts.getUser(); 71 String password = opts.getPassword(); 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 Service service = new Service(new XMLStringProvider(wsdd)); 86 87 JMSTransport transport = new JMSTransport(connectorMap, cfMap); 89 90 Call call = (Call) service.createCall(); 92 93 call.setOperationName( new QName ("urn:xmltoday-delayed-quotes", "getQuote") ); 94 call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); 95 call.setReturnType( XMLType.XSD_FLOAT ); 96 call.setTransport(transport); 97 98 107 call.setProperty(JMSConstants.DESTINATION, destination); 108 call.setTimeout(new Integer (10000)); 109 110 Float res = new Float (0.0F); 111 112 for (int i = 0; i < args.length; i++) 114 { 115 try 116 { 117 res = (Float ) call.invoke(new Object [] {args[i]}); 118 System.out.println(args[i] + ": " + res); 119 } 120 catch(AxisFault af) 121 { 122 System.out.println(af.dumpToString()); 123 } 124 } 125 126 listener.shutdown(); 128 transport.shutdown(); 129 } 130 131 public static void printUsage() 132 { 133 System.out.println("JMSTest: Tests JMS transport by obtaining stock quote"); 134 System.out.println(" Usage: JMSTest <symbol 1> <symbol 2> <symbol 3> ..."); 135 System.out.println(" Opts: -? this message"); 136 System.out.println(); 137 System.out.println(" -c connection factory properties filename"); 138 System.out.println(" -d destination"); 139 System.out.println(" -t topic [absence of -t indicates queue]"); 140 System.out.println(); 141 System.out.println(" -u username"); 142 System.out.println(" -w password"); 143 System.out.println(); 144 System.out.println(" -s single-threaded listener"); 145 System.out.println(" [absence of option => multithreaded]"); 146 147 System.exit(1); 148 } 149 } 150 | Popular Tags |