KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > jms > JMSTest


1 /*
2  * Copyright 2001, 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
31 import javax.xml.rpc.ParameterMode JavaDoc;
32 import java.util.HashMap JavaDoc;
33
34 /** Tests the JMS transport. To run:
35  * java org.apache.axis.utils.Admin client client_deploy.xml
36  * java org.apache.axis.utils.Admin server deploy.xml
37  * java samples.transport.FileTest IBM
38  * java samples.transport.FileTest XXX
39  *
40  * JMSTest is a simple test driver for the JMS transport. It sets up a
41  * JMS listener, then calls a delayed quote service for each of the symbols
42  * specified on the command line.
43  *
44  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
45  * @author Richard Chung (rchung@sonicsoftware.com)
46  * @author Dave Chappell (chappell@sonicsoftware.com)
47  */

48
49 public class JMSTest {
50     static final String JavaDoc 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 JavaDoc args[]) throws Exception JavaDoc {
61         Options opts = new Options( args );
62
63         // first check if we should print usage
64
if ((opts.isFlagSet('?') > 0) || (opts.isFlagSet('h') > 0))
65             printUsage();
66
67         HashMap JavaDoc connectorMap = SimpleJMSListener.createConnectorMap(opts);
68         HashMap JavaDoc cfMap = SimpleJMSListener.createCFMap(opts);
69         String JavaDoc destination = opts.isValueSet('d');
70         String JavaDoc username = opts.getUser();
71         String JavaDoc password = opts.getPassword();
72         // create the jms listener
73
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         // create the transport
88
JMSTransport transport = new JMSTransport(connectorMap, cfMap);
89
90         // create a new Call object
91
Call call = (Call) service.createCall();
92
93         call.setOperationName( new QName JavaDoc("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         // set additional params on the call if desired
99
//call.setUsername(username );
100
//call.setPassword(password );
101
//call.setProperty(JMSConstants.WAIT_FOR_RESPONSE, Boolean.FALSE);
102
//call.setProperty(JMSConstants.PRIORITY, new Integer(5));
103
//call.setProperty(JMSConstants.DELIVERY_MODE,
104
// new Integer(javax.jms.DeliveryMode.PERSISTENT));
105
//call.setProperty(JMSConstants.TIME_TO_LIVE, new Long(20000));
106

107         call.setProperty(JMSConstants.DESTINATION, destination);
108         call.setTimeout(new Integer JavaDoc(10000));
109
110         Float JavaDoc res = new Float JavaDoc(0.0F);
111
112         // invoke a call for each of the symbols and print out
113
for (int i = 0; i < args.length; i++)
114         {
115             try
116             {
117             res = (Float JavaDoc) call.invoke(new Object JavaDoc[] {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         // shutdown
127
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