Skip to content

Commit 09bcd7f

Browse files
committed
SWS-742 - JMSCorrelationID together with Oracle AQ
1 parent 341ba1c commit 09bcd7f

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

support/src/main/java/org/springframework/ws/transport/jms/JmsSenderConnection.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -32,7 +32,6 @@
3232
import javax.jms.MessageProducer;
3333
import javax.jms.Session;
3434
import javax.jms.TemporaryQueue;
35-
import javax.jms.TemporaryTopic;
3635
import javax.jms.TextMessage;
3736

3837
import org.springframework.jms.connection.ConnectionFactoryUtils;
@@ -81,6 +80,8 @@ public class JmsSenderConnection extends AbstractSenderConnection {
8180

8281
private boolean sessionTransacted = false;
8382

83+
private boolean temporaryResponseQueueCreated = false;
84+
8485
/** Constructs a new JMS connection with the given parameters. */
8586
protected JmsSenderConnection(ConnectionFactory connectionFactory,
8687
Connection connection,
@@ -211,6 +212,7 @@ protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
211212
messageProducer.setPriority(priority);
212213
if (responseDestination == null) {
213214
responseDestination = session.createTemporaryQueue();
215+
temporaryResponseQueueCreated = true;
214216
}
215217
requestMessage.setJMSReplyTo(responseDestination);
216218
if (postProcessor != null) {
@@ -243,7 +245,7 @@ private boolean isSessionLocallyTransacted(Session session) {
243245
protected void onReceiveBeforeRead() throws IOException {
244246
MessageConsumer messageConsumer = null;
245247
try {
246-
if (responseDestination instanceof TemporaryQueue || responseDestination instanceof TemporaryTopic) {
248+
if (temporaryResponseQueueCreated) {
247249
messageConsumer = session.createConsumer(responseDestination);
248250
}
249251
else {
@@ -266,19 +268,11 @@ else if (message != null) {
266268
}
267269
finally {
268270
JmsUtils.closeMessageConsumer(messageConsumer);
269-
if (responseDestination instanceof TemporaryQueue) {
271+
if (temporaryResponseQueueCreated) {
270272
try {
271273
((TemporaryQueue) responseDestination).delete();
272274
}
273-
catch (JMSException e) {
274-
// ignore
275-
}
276-
}
277-
else if (responseDestination instanceof TemporaryTopic) {
278-
try {
279-
((TemporaryTopic) responseDestination).delete();
280-
}
281-
catch (JMSException e) {
275+
catch (JMSException ex) {
282276
// ignore
283277
}
284278
}

support/src/test/java/org/springframework/ws/transport/jms/JmsMessageSenderIntegrationTest.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -64,7 +64,7 @@ public void createMessageFactory() throws Exception {
6464
}
6565

6666
@Test
67-
public void testSendAndReceiveQueueBytesMessage() throws Exception {
67+
public void testSendAndReceiveQueueBytesMessageTemporaryQueue() throws Exception {
6868
WebServiceConnection connection = null;
6969
try {
7070
URI uri = new URI("jms:SenderRequestQueue?deliveryMode=NON_PERSISTENT");
@@ -102,6 +102,48 @@ public Message createMessage(Session session) throws JMSException {
102102
}
103103
}
104104

105+
@Test
106+
public void testSendAndReceiveQueueBytesMessagePermanentQueue() throws Exception {
107+
WebServiceConnection connection = null;
108+
try {
109+
String responseQueueName = "SenderResponseQueue";
110+
URI uri = new URI(
111+
"jms:SenderRequestQueue?replyToName=" + responseQueueName + "&deliveryMode=NON_PERSISTENT");
112+
connection = messageSender.createConnection(uri);
113+
SoapMessage soapRequest = new SaajSoapMessage(messageFactory.createMessage());
114+
soapRequest.setSoapAction(SOAP_ACTION);
115+
connection.send(soapRequest);
116+
117+
final BytesMessage request = (BytesMessage) jmsTemplate.receive();
118+
assertNotNull("No message received", request);
119+
assertTrue("No message content received", request.readByte() != -1);
120+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
121+
messageFactory.createMessage().writeTo(bos);
122+
final byte[] buf = bos.toByteArray();
123+
jmsTemplate.send(responseQueueName, new MessageCreator() {
124+
125+
public Message createMessage(Session session) throws JMSException {
126+
BytesMessage response = session.createBytesMessage();
127+
response.setJMSCorrelationID(request.getJMSMessageID());
128+
response.setStringProperty(JmsTransportConstants.PROPERTY_SOAP_ACTION, SOAP_ACTION);
129+
response.setStringProperty(JmsTransportConstants.PROPERTY_CONTENT_TYPE,
130+
SoapVersion.SOAP_11.getContentType());
131+
response.writeBytes(buf);
132+
return response;
133+
}
134+
});
135+
SoapMessage response = (SoapMessage) connection.receive(new SaajSoapMessageFactory(messageFactory));
136+
assertNotNull("No response received", response);
137+
assertEquals("Invalid SOAPAction", SOAP_ACTION, response.getSoapAction());
138+
assertFalse("Message is fault", response.hasFault());
139+
}
140+
finally {
141+
if (connection != null) {
142+
connection.close();
143+
}
144+
}
145+
}
146+
105147
@Test
106148
public void testSendAndReceiveQueueTextMessage() throws Exception {
107149
WebServiceConnection connection = null;

support/src/test/resources/org/springframework/ws/transport/jms/jms-sender-applicationContext.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<property name="physicalName" value="SenderRequestQueue"/>
1111
</bean>
1212

13+
<bean id="responseQueue" class="org.apache.activemq.command.ActiveMQQueue">
14+
<property name="physicalName" value="SenderResponseQueue"/>
15+
</bean>
16+
1317
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
1418
<property name="connectionFactory" ref="connectionFactory"/>
1519
<property name="defaultDestination" ref="requestQueue"/>

0 commit comments

Comments
 (0)