Source code: mobile/jndi/LookupMid.java
1 // javadoc status: done
2
3 /*
4 * This class shoud be run under midp.
5 * After invokation, does test suit for TalkingWithProxy
6 *
7 *
8 */
9
10 package mobile.jndi;
11 import javax.microedition.midlet.*;
12 import javax.microedition.lcdui.*;
13 import mobile.jmsapi.*;
14 import mobile.jndi.*;
15
16 /**
17 * <p>
18 * A TalkingWithProxy testing tool. Invokes test cases on kvm.
19 * </p>
20 */
21 public class LookupMid
22 extends MIDlet
23 implements CommandListener {
24
25 private Command exitCommand;
26 private Display display;
27 private TextBox t = null;
28 private String proxyAddress="http://localhost:8080/page";
29 private void log(String s){
30 System.out.println(s);
31 }
32
33 /**
34 * Default constructor.
35 */
36 public LookupMid()
37 {
38 QueueConnectionFactory qcf;
39 TopicConnectionFactory tcf = null;
40 Queue q;
41 Topic t;
42 Context cnx;
43 TopicConnection tConn = null;
44 QueueConnection qConn = null;
45 QueueSession qSes = null;
46 QueueSender qSen = null;
47 QueueReceiver qRec = null;
48 TextMessage mesg;
49
50 TopicSession tSes = null;
51 TopicPublisher tPub = null;
52
53 cnx = new Context();
54 qcf = (QueueConnectionFactory) cnx.lookup("JQCF");
55 log("MIDLET DOSTAL QCF!!!!!!!!!");
56 if (qcf != null)
57 log("I TO NA DODATEK NIE NULL");
58 else
59 log("niestety null");
60
61 // qcf = (QueueConnectionFactory) cnx.lookup("JQCF");
62 // log("MIDLET DOSTAL QCF po raz drugi !!!!!!!!!");
63 // if (qcf != null)
64 // log("I TO NA DODATEK NIE NULL");
65 // else
66 // log("niestety null");
67
68 // tcf = (TopicConnectionFactory) cnx.lookup("JTCF");
69 // log("MIDLET DOSTAL TCF!!!!!!!!!");
70 // if (tcf != null)
71 // log("I TO NA DODATEK NIE NULL");
72 // else
73 // log("niestety null");
74
75 q = (Queue) cnx.lookup("sampleQueue");
76 log("MIDLET DOSTAL Q!!!!!!!!!");
77
78
79 // t = (Topic) cnx.lookup("sampleTopic");
80 // log("MIDLET DOSTAL T!!!!!!!!!");
81
82 // try{
83 // tConn = tcf.createTopicConnection();
84 // log("MIDLET DOSTAL TC!!!!!!!!!");
85 // if(tConn != null) log("I TO NA DODATEK NIE NULL");
86 // else log("niestety null");
87 //
88 // }
89 // catch(JMSException e){
90 // log("exception w createTC");
91 // }
92 //
93 // try{
94 // tConn.start();
95 // }
96 // catch(JMSException e){
97 // log("exception w QC.start()");
98 // }
99 //
100 // log("CONNECTION STARTED");
101 // try{
102 // tSes = tConn.createTopicSession(false, 0);
103 // log("MIDLET DOSTAL TS!!!!!!!!!");
104 // if(tSes != null) log("I TO NA DODATEK NIE NULL");
105 // else log("niestety null");
106 // }
107 // catch(JMSException e){
108 // log("exception w createTS");
109 // }
110 //
111 // try{
112 // tPub = tSes.createTopicPublisher(t);
113 // log("MIDLET DOSTAL TPUB!!!!!!!!!");
114 // if(tPub != null) log("I TO NA DODATEK NIE NULL");
115 // else log("niestety null");
116 //
117 // }
118 // catch(JMSException e){
119 // log("exception w TPub");
120 // }
121 //
122
123
124
125 try{
126 qConn = qcf.createQueueConnection();
127 log("MIDLET DOSTAL QC!!!!!!!!!");
128 if(qConn != null) log("I TO NA DODATEK NIE NULL");
129 else log("niestety null");
130 }
131 catch(JMSException e){
132 log("exception w createQC");
133 }
134
135 try{
136 qConn.start();
137 }
138 catch(JMSException e){
139 log("exception w QC.start()");
140 }
141
142 log("CONNECTION STARTED");
143 try{
144 qSes = qConn.createQueueSession(false, 0);
145 log("MIDLET DOSTAL QS!!!!!!!!!");
146 if(qSes != null) log("I TO NA DODATEK NIE NULL");
147 else log("niestety null");
148 }
149 catch(JMSException e){
150 log("exception w createQS");
151 }
152
153 // try{
154 // qSen = qSes.createQueueSender(q);
155 // log("MIDLET DOSTAL QSender!!!!!!!!!");
156 // if(qSen != null) log("I TO NA DODATEK NIE NULL");
157 //else log("niestety null");
158 //
159 // }
160 // catch(JMSException e){
161 // log("exception w createQSender");
162 // }
163
164 try{
165 qRec = qSes.createQueueReceiver(q);
166 log("MIDLET DOSTAL QRec!!!!!!!!!");
167 if(qSes != null) log("I TO NA DODATEK NIE NULL");
168 else log("niestety null");
169
170 }
171
172 catch(JMSException e){
173 log("exception w createQReceiver");
174 }
175
176
177 // try{
178 // mesg = qSes.createTextMessage();
179 // log("wiadomosc stworzona");
180 // mesg.setText("ala ma kota");
181 // qSen.send(q,mesg);
182 // log("wiadomosc wyslana");
183 // }
184 // catch(JMSException e){
185 // log("exception w sendMesg:" + e.getMessage());
186 // }
187
188 log("przed receive - timeout");
189 try{
190 mesg = (TextMessage) qRec.receive(12000);
191 if (mesg != null) log("dostalem WIADOMOSC: " + mesg.getText());
192 else log("dostalem null");
193 }
194
195
196 catch(JMSException e){
197 log("exception w receive:" + e.getMessage());
198 }
199
200 log("po receive - timeout");
201
202 log("przed receive");
203 try{
204 mesg = (TextMessage) qRec.receive();
205 if (mesg != null) log("dostalem WIADOMOSC: " + mesg.getText());
206 else log("dostalem null");
207 }
208
209
210 catch(JMSException e){
211 log("exception w receive:" + e.getMessage());
212 }
213
214 log("po receive");
215
216
217
218 // TalkingWithProxy twp = new TalkingWithProxy(proxyAddress,1);
219
220 // if (rp.getData() != msg)
221 // System.out.println("malformed data");
222 }
223
224 /**
225 * This method overides the one from super class. See MIDlet Documentation for details.
226 */
227 public void startApp()
228 {
229 // display.setCurrent(t);
230 }
231
232 /**
233 * This method overides one form super class. Declared, but the body is left ompty. See MIDlet Documentation for details.
234 */
235 public void pauseApp() { }
236
237 /**
238 * This method overides one form super class. Declared, but the body is left ompty. See MIDlet Documentation for details.
239 */
240 public void destroyApp(boolean unconditional) { }
241
242 /**
243 * This method overides one form super class. Declared, but the body is left ompty. See MIDlet Documentation for details.
244 */
245 public void commandAction(Command c, Displayable s)
246 {
247 // if (c == exitCommand)
248 // {
249 //destroyApp(false);
250 // notifyDestroyed();
251 // }
252 };
253
254 private void debug(String s1, String s2){
255 System.out.print("tester:");
256 System.out.print(s1);
257 System.out.println(s2);
258 }
259
260 private void debug(String s){
261 System.out.print("tester:");
262 System.out.println(s);
263 }
264
265
266
267 }