1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.jms;
18
19 import javax.jms.BytesMessage;
20 import javax.jms.JMSException;
21 import javax.jms.Message;
22 import javax.jms.Queue;
23 import javax.jms.Session;
24 import javax.jms.TextMessage;
25 import javax.jms.Topic;
26
27 import org.springframework.jms.core.JmsTemplate;
28 import org.springframework.jms.core.MessageCreator;
29 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
30
31 public class WebServiceMessageListenerIntegrationTest extends AbstractDependencyInjectionSpringContextTests {
32
33 private static final String CONTENT =
34 "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>" + "<SOAP-ENV:Body>\n" +
35 "<m:GetLastTradePrice xmlns:m='http://www.springframework.org/spring-ws'>\n" +
36 "<symbol>DIS</symbol>\n" + "</m:GetLastTradePrice>\n" + "</SOAP-ENV:Body></SOAP-ENV:Envelope>";
37
38 private JmsTemplate jmsTemplate;
39
40 private Queue responseQueue;
41
42 private Queue requestQueue;
43
44 private Topic requestTopic;
45
46 public WebServiceMessageListenerIntegrationTest() {
47 setAutowireMode(AUTOWIRE_BY_NAME);
48 }
49
50 public void setJmsTemplate(JmsTemplate jmsTemplate) {
51 this.jmsTemplate = jmsTemplate;
52 }
53
54 public void setRequestQueue(Queue requestQueue) {
55 this.requestQueue = requestQueue;
56 }
57
58 public void setRequestTopic(Topic requestTopic) {
59 this.requestTopic = requestTopic;
60 }
61
62 public void setResponseQueue(Queue responseQueue) {
63 this.responseQueue = responseQueue;
64 }
65
66 protected String[] getConfigLocations() {
67 return new String[]{"classpath:org/springframework/ws/transport/jms/jms-receiver-applicationContext.xml"};
68 }
69
70 public void testReceiveQueueBytesMessage() throws Exception {
71 final byte[] b = CONTENT.getBytes("UTF-8");
72 jmsTemplate.send(requestQueue, new MessageCreator() {
73 public Message createMessage(Session session) throws JMSException {
74 BytesMessage request = session.createBytesMessage();
75 request.setJMSReplyTo(responseQueue);
76 request.writeBytes(b);
77 return request;
78 }
79 });
80 BytesMessage response = (BytesMessage) jmsTemplate.receive(responseQueue);
81 assertNotNull("No response received", response);
82 }
83
84 public void testReceiveQueueTextMessage() throws Exception {
85 jmsTemplate.send(requestQueue, new MessageCreator() {
86 public Message createMessage(Session session) throws JMSException {
87 TextMessage request = session.createTextMessage(CONTENT);
88 request.setJMSReplyTo(responseQueue);
89 return request;
90 }
91 });
92 TextMessage response = (TextMessage) jmsTemplate.receive(responseQueue);
93 assertNotNull("No response received", response);
94 }
95
96 public void testReceiveTopic() throws Exception {
97 final byte[] b = CONTENT.getBytes("UTF-8");
98 jmsTemplate.send(requestTopic, new MessageCreator() {
99 public Message createMessage(Session session) throws JMSException {
100 BytesMessage request = session.createBytesMessage();
101 request.writeBytes(b);
102 return request;
103 }
104 });
105 Thread.sleep(100);
106 }
107
108 }