001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.nclient;
022
023 import java.util.Enumeration;
024
025 import javax.jms.ExceptionListener;
026 import javax.jms.JMSException;
027 import javax.jms.Message;
028 import javax.jms.MessageListener;
029 import javax.jms.Queue;
030 import javax.jms.QueueBrowser;
031
032 import org.apache.qpid.client.AMQConnection;
033 import org.apache.qpid.client.AMQQueue;
034 import org.apache.qpid.client.AMQTopic;
035 import org.apache.qpid.framing.AMQShortString;
036
037 public class JMSTestCase
038 {
039
040 public static void main(String[] args)
041 {
042
043 try
044 {
045 javax.jms.Connection con = new AMQConnection("qpid:password=pass;username=name@tcp:localhost:5672");
046 con.start();
047
048 javax.jms.Session ssn = con.createSession(false, 1);
049
050 javax.jms.Destination dest = new AMQQueue(new AMQShortString("direct"),"test");
051 javax.jms.MessageProducer prod = ssn.createProducer(dest);
052 QueueBrowser browser = ssn.createBrowser((Queue)dest, "Test = 'test'");
053
054 javax.jms.TextMessage msg = ssn.createTextMessage();
055 msg.setStringProperty("TEST", "test");
056 msg.setText("Should get this");
057 prod.send(msg);
058
059 javax.jms.TextMessage msg2 = ssn.createTextMessage();
060 msg2.setStringProperty("TEST", "test2");
061 msg2.setText("Shouldn't get this");
062 prod.send(msg2);
063
064
065 Enumeration enu = browser.getEnumeration();
066 for (;enu.hasMoreElements();)
067 {
068 System.out.println(enu.nextElement());
069 System.out.println("\n");
070 }
071
072 javax.jms.MessageConsumer cons = ssn.createConsumer(dest, "Test = 'test'");
073 javax.jms.TextMessage m = null; // (javax.jms.TextMessage)cons.receive();
074 cons.setMessageListener(new MessageListener()
075 {
076 public void onMessage(Message m)
077 {
078 javax.jms.TextMessage m2 = (javax.jms.TextMessage)m;
079 try
080 {
081 System.out.println("headers : " + m2.toString());
082 System.out.println("m : " + m2.getText());
083 System.out.println("\n\n");
084 }
085 catch(Exception e)
086 {
087 e.printStackTrace();
088 }
089 }
090
091 });
092
093 con.setExceptionListener(new ExceptionListener()
094 {
095 public void onException(JMSException e)
096 {
097 e.printStackTrace();
098 }
099 });
100
101 System.out.println("Waiting");
102 while (m == null)
103 {
104
105 }
106
107 System.out.println("Exiting");
108
109 /*javax.jms.TextMessage msg = ssn.createTextMessage();
110 msg.setText("This is a test message");
111 msg.setBooleanProperty("targetMessage", false);
112 prod.send(msg);
113
114 msg.setBooleanProperty("targetMessage", true);
115 prod.send(msg);
116
117 javax.jms.TextMessage m = (javax.jms.TextMessage)cons.receiveNoWait();
118
119 if (m == null)
120 {
121 System.out.println("message is null");
122 }
123 else
124 {
125 System.out.println("message is not null" + m);
126 }*/
127
128 }
129 catch(Exception e)
130 {
131 e.printStackTrace();
132 }
133 }
134
135 }
|