001: /*
002: * Copyright 2001, 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package samples.jms;
018:
019: import org.apache.axis.AxisFault;
020: import org.apache.axis.client.Call;
021: import org.apache.axis.client.Service;
022: import org.apache.axis.configuration.XMLStringProvider;
023: import org.apache.axis.deployment.wsdd.WSDDConstants;
024: import org.apache.axis.encoding.XMLType;
025: import org.apache.axis.transport.jms.JMSConstants;
026: import org.apache.axis.transport.jms.JMSTransport;
027: import org.apache.axis.transport.jms.SimpleJMSListener;
028: import org.apache.axis.utils.Options;
029:
030: import javax.xml.namespace.QName;
031: import javax.xml.rpc.ParameterMode;
032: import java.util.HashMap;
033:
034: /** Tests the JMS transport. To run:
035: * java org.apache.axis.utils.Admin client client_deploy.xml
036: * java org.apache.axis.utils.Admin server deploy.xml
037: * java samples.transport.FileTest IBM
038: * java samples.transport.FileTest XXX
039: *
040: * JMSTest is a simple test driver for the JMS transport. It sets up a
041: * JMS listener, then calls a delayed quote service for each of the symbols
042: * specified on the command line.
043: *
044: * @author Jaime Meritt (jmeritt@sonicsoftware.com)
045: * @author Richard Chung (rchung@sonicsoftware.com)
046: * @author Dave Chappell (chappell@sonicsoftware.com)
047: */
048:
049: public class JMSTest {
050: static final String wsdd = "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" "
051: + "xmlns:java=\""
052: + WSDDConstants.URI_WSDD_JAVA
053: + "\">\n"
054: + " <transport name=\"JMSTransport\" pivot=\"java:org.apache.axis.transport.jms.JMSSender\"/>\n"
055: + " <service name=\""
056: + WSDDConstants.URI_WSDD
057: + "\" provider=\"java:MSG\">\n"
058: + " <parameter name=\"allowedMethods\" value=\"AdminService\"/>\n"
059: + " <parameter name=\"className\" value=\"org.apache.axis.utils.Admin\"/>\n"
060: + " </service>\n" + "</deployment>";
061:
062: public static void main(String args[]) throws Exception {
063: Options opts = new Options(args);
064:
065: // first check if we should print usage
066: if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0))
067: printUsage();
068:
069: HashMap connectorMap = SimpleJMSListener
070: .createConnectorMap(opts);
071: HashMap cfMap = SimpleJMSListener.createCFMap(opts);
072: String destination = opts.isValueSet('d');
073: String username = opts.getUser();
074: String password = opts.getPassword();
075: // create the jms listener
076: SimpleJMSListener listener = new SimpleJMSListener(
077: connectorMap, cfMap, destination, username, password,
078: false);
079: listener.start();
080:
081: args = opts.getRemainingArgs();
082: if (args == null || args.length == 0)
083: printUsage();
084:
085: Service service = new Service(new XMLStringProvider(wsdd));
086:
087: // create the transport
088: JMSTransport transport = new JMSTransport(connectorMap, cfMap);
089:
090: // create a new Call object
091: Call call = (Call) service.createCall();
092:
093: call.setOperationName(new QName("urn:xmltoday-delayed-quotes",
094: "getQuote"));
095: call.addParameter("symbol", XMLType.XSD_STRING,
096: ParameterMode.IN);
097: call.setReturnType(XMLType.XSD_FLOAT);
098: call.setTransport(transport);
099:
100: // set additional params on the call if desired
101: //call.setUsername(username );
102: //call.setPassword(password );
103: //call.setProperty(JMSConstants.WAIT_FOR_RESPONSE, Boolean.FALSE);
104: //call.setProperty(JMSConstants.PRIORITY, new Integer(5));
105: //call.setProperty(JMSConstants.DELIVERY_MODE,
106: // new Integer(javax.jms.DeliveryMode.PERSISTENT));
107: //call.setProperty(JMSConstants.TIME_TO_LIVE, new Long(20000));
108:
109: call.setProperty(JMSConstants.DESTINATION, destination);
110: call.setTimeout(new Integer(10000));
111:
112: Float res = new Float(0.0F);
113:
114: // invoke a call for each of the symbols and print out
115: for (int i = 0; i < args.length; i++) {
116: try {
117: res = (Float) call.invoke(new Object[] { args[i] });
118: System.out.println(args[i] + ": " + res);
119: } catch (AxisFault af) {
120: System.out.println(af.dumpToString());
121: }
122: }
123:
124: // shutdown
125: listener.shutdown();
126: transport.shutdown();
127: }
128:
129: public static void printUsage() {
130: System.out
131: .println("JMSTest: Tests JMS transport by obtaining stock quote");
132: System.out
133: .println(" Usage: JMSTest <symbol 1> <symbol 2> <symbol 3> ...");
134: System.out.println(" Opts: -? this message");
135: System.out.println();
136: System.out
137: .println(" -c connection factory properties filename");
138: System.out.println(" -d destination");
139: System.out
140: .println(" -t topic [absence of -t indicates queue]");
141: System.out.println();
142: System.out.println(" -u username");
143: System.out.println(" -w password");
144: System.out.println();
145: System.out.println(" -s single-threaded listener");
146: System.out
147: .println(" [absence of option => multithreaded]");
148:
149: System.exit(1);
150: }
151: }
|