1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.jencks;
19
20 import org.springframework.context.ConfigurableApplicationContext;
21 import org.springframework.context.support.ClassPathXmlApplicationContext;
22
23 import javax.jms.*;
24 import java.util.Date;
25
26 /***
27 * @version $Revision: 1.1.1.1 $
28 */
29 public class JCAContainerRequestReplyTest extends JCAContainerTestSupport implements MessageListener {
30
31 protected Session serverSession;
32 protected MessageProducer serverProducer;
33 protected MessageConsumer serverConsumer;
34 protected Queue queue;
35
36 protected void setUp() throws Exception {
37 super.setUp();
38 queue = session.createQueue(getClass().getName());
39
40 serverSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
41 serverProducer = serverSession.createProducer(null);
42 serverConsumer = serverSession.createConsumer(queue);
43 serverConsumer.setMessageListener(this);
44
45 }
46
47 public void onMessage(Message msg) {
48 try {
49 Destination dest = msg.getJMSReplyTo();
50 serverProducer.send(dest, msg);
51 }
52 catch (JMSException jmsEx) {
53 jmsEx.printStackTrace();
54 }
55 }
56
57 public void testRequestReply() throws Exception {
58
59
60 Requestor requestor = new Requestor((QueueSession) session, queue);
61
62 TextMessage message = session.createTextMessage("Hello! " + new Date());
63
64 System.out.println("About to send: " + message);
65
66
67 Message answer = requestor.request(message);
68
69 assertTrue("Should have received an answer", answer != null);
70
71 System.out.println("Received: " + answer);
72 }
73
74
75 protected ConfigurableApplicationContext createApplicationContext() {
76 return new ClassPathXmlApplicationContext("org/jencks/spring-request-reply.xml");
77 }
78 }