if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0)) {
printUsage();
}
// create the jms listener
SimpleJMSListener listener = new SimpleJMSListener(opts);
listener.start();
args = opts.getRemainingArgs();
if ( args == null ) {
printUsage();
}
int numArgs = args.length;
String[] symbols = new String[numArgs];
for (int i = 0; i < numArgs; i++) {
symbols[i] = args[i];
}
Service service = new Service(new XMLStringProvider(wsdd));
HashMap cfProps = new HashMap();
cfProps.put(SonicConstants.BROKER_URL, opts.isValueSet('b'));
cfProps.put(SonicConstants.DEFAULT_USERNAME, opts.getUser());
cfProps.put(SonicConstants.DEFAULT_PASSWORD, opts.getPassword());
// do we have a jndi name?
String jndiName = opts.isValueSet('n');
if (jndiName != null) {
// w/ a jndi name, we can get the appropriate connection factory
cfProps.put(JMSConstants.CONNECTION_FACTORY_JNDI_NAME, jndiName);
} else {
// w/o a jndi name, we default to using the Sonic-specific method
// for creating a connection factory, which is by specifying the
// appropriate connection factory class from SonicConstants.java
// topics or queues?
String cf = null;
if (opts.isFlagSet('t') > 0) {
cf = SonicConstants.TCF_CLASS;
} else {
cf = SonicConstants.QCF_CLASS;
}
cfProps.put(JMSConstants.CONNECTION_FACTORY_CLASS, cf);
}
// create the transport
JMSTransport transport = new JMSTransport(null, cfProps);
// create a new Call object
Call call = (Call) service.createCall();
call.setOperationName( new QName("urn:xmltoday-delayed-quotes", "getQuote") );
call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType( XMLType.XSD_FLOAT );
call.setTransport(transport);
// set additional params on the call if desired
//call.setUsername(opts.getUser() );
//call.setPassword(opts.getPassword() );
//call.setProperty(JMSConstants.WAIT_FOR_RESPONSE, Boolean.FALSE);
//call.setProperty(JMSConstants.PRIORITY, new Integer(5));
//call.setProperty(JMSConstants.DELIVERY_MODE,
// new Integer(javax.jms.DeliveryMode.PERSISTENT));
//call.setProperty(JMSConstants.TIME_TO_LIVE, new Long(20000));
call.setProperty(JMSConstants.DESTINATION, "SampleQ1");
call.setTimeout(new Integer(10000));
Float res = new Float(0.0F);
// invoke a call for each of the symbols and print out
for (int i = 0; i < symbols.length; i++) {
res = (Float) call.invoke(new Object[] {symbols[i]});
System.out.println(symbols[i] + ": " + res);
}
// shutdown
listener.shutdown();
transport.shutdown();
}