Finished up JMS support.

This commit is contained in:
Arjen Poutsma
2006-11-18 01:18:58 +00:00
parent 93a7121475
commit 0a6e33c1ec
9 changed files with 402 additions and 226 deletions

View File

@@ -9,24 +9,6 @@
<artifactId>spring-ws-sandbox</artifactId>
<packaging>jar</packaging>
<name>Spring WS Sandbox</name>
<profiles>
<profile>
<id>spring-2.0</id>
<activation>
<property>
<name>spring.version</name>
<value>2.0</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<!-- Spring-WS dependencies -->
<dependency>
@@ -54,6 +36,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<!-- JEE dependencies -->
<dependency>
<groupId>javax.xml.soap</groupId>
@@ -79,6 +65,11 @@
<version>3.0.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>activemq</groupId>
<artifactId>activemq</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>

View File

@@ -0,0 +1,104 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.transport.jms;
import javax.jms.BytesMessage;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jms.support.JmsUtils;
import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.endpoint.MessageEndpoint;
import org.springframework.ws.transport.ReceiverObjectSupport;
import org.springframework.ws.transport.TransportInputStream;
import org.springframework.ws.transport.TransportOutputStream;
/**
* Convenience base class for JMS server-side transport objects. Contains a {@link MessageEndpoint}, and has methods for
* handling incoming JMS <code>Message</code> requests.
* <p/>
* This class can be used as a base for a EJB MessageDrivenBean, or using Spring-2.0's MessageDriven POJO's.
*
* @author Arjen Poutsma
* @see #handle(javax.jms.Message,javax.jms.Session)
*/
public abstract class JmsReceiverObjectSupport extends ReceiverObjectSupport implements InitializingBean {
private MessageEndpoint messageEndpoint;
/**
* Returns the <code>MessageEndpoint</code> used by this listener.
*/
public MessageEndpoint getMessageEndpoint() {
return messageEndpoint;
}
/**
* Sets the <code>MessageEndpoint</code> used by this listener.
*/
public void setMessageEndpoint(MessageEndpoint messageEndpoint) {
this.messageEndpoint = messageEndpoint;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(getMessageFactory(), "messageFactory is required");
Assert.notNull(getMessageEndpoint(), "messageEndpoint must not be null");
logger.info("Using message factory [" + getMessageFactory() + "]");
}
/**
* Handles an incoming <code>Message</code>s. Uses the given <code>Session</code> to create a response request.
*
* @param request the incoming message
* @param session the JMS session used to create a response
* @throws IllegalArgumentException when request is not a <code>BytesMessage</code>
*/
protected final void handle(Message request, Session session) throws Exception {
if (request instanceof BytesMessage) {
TransportInputStream tis = new JmsTransportInputStream((BytesMessage) request);
TransportOutputStream tos = new JmsTransportOutputStream(session, request.getJMSCorrelationID());
handle(tis, tos, getMessageEndpoint());
}
else {
throw new IllegalArgumentException(
"Wrong message type: [" + request.getClass() + "]. Only BytesMessages can be handled");
}
}
protected final void handleResponse(TransportInputStream tis, TransportOutputStream tos, WebServiceMessage response)
throws Exception {
Message requestMessage = ((JmsTransportInputStream) tis).getMessage();
if (requestMessage.getJMSReplyTo() == null) {
logger.warn("Incoming message has no ReplyTo set, not sending response");
return;
}
response.writeTo(tos);
Session session = ((JmsTransportOutputStream) tos).getSession();
MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
Message responseMessage = ((JmsTransportOutputStream) tos).getMessage();
try {
producer.send(responseMessage);
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
}

View File

@@ -16,13 +16,13 @@
package org.springframework.ws.transport.jms;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Iterator;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.TextMessage;
import javax.jms.MessageEOFException;
import org.springframework.util.Assert;
import org.springframework.ws.transport.TransportInputStream;
@@ -30,45 +30,40 @@ import org.springframework.ws.transport.support.EnumerationIterator;
/**
* JMS specific implementation of the <code>TransportInputStream</code> interface. Exposes a JMS
* <code>TextMessage</code>.
* <code>BytesMessage</code>.
*
* @author Arjen Poutsma
* @see #getTextMessage()
* @see #getMessage()
*/
public class JmsTransportInputStream extends TransportInputStream {
private final TextMessage textMessage;
private final BytesMessage message;
/**
* Constructs a new instance of the <code>JmsTransportInputStream</code> using the provided JMS
* <code>TextMessage</code>.
* <code>BytesMessage</code>.
*
* @param textMessage the JMS message
* @param message the JMS message
*/
public JmsTransportInputStream(TextMessage textMessage) {
Assert.notNull(textMessage, "textMessage must not be null");
this.textMessage = textMessage;
public JmsTransportInputStream(BytesMessage message) {
Assert.notNull(message, "message must not be null");
this.message = message;
}
/**
* Returns the wrapped JMS <code>TextMessage</code>.
* Returns the wrapped JMS message.
*/
public TextMessage getTextMessage() {
return textMessage;
public BytesMessage getMessage() {
return message;
}
protected InputStream createInputStream() throws IOException {
try {
return new ByteArrayInputStream(textMessage.getText().getBytes("UTF-8"));
}
catch (JMSException ex) {
throw new IOException("Could not get text of message: " + ex.getMessage());
}
return new BytesMessageInputStream();
}
public Iterator getHeaderNames() throws IOException {
try {
return new EnumerationIterator(textMessage.getPropertyNames());
return new EnumerationIterator(message.getPropertyNames());
}
catch (JMSException ex) {
throw new IOException("Could not get property names: " + ex.getMessage());
@@ -77,11 +72,52 @@ public class JmsTransportInputStream extends TransportInputStream {
public Iterator getHeaders(String name) throws IOException {
try {
String value = textMessage.getStringProperty(name);
String value = message.getStringProperty(name);
return Collections.singletonList(value).iterator();
}
catch (JMSException ex) {
throw new IOException("Could not get property value: " + ex.getMessage());
}
}
/**
* InputStream that wraps the JMS <code>BytesMessage</code>.
*/
private class BytesMessageInputStream extends InputStream {
public int read(byte b[]) throws IOException {
try {
return message.readBytes(b);
}
catch (JMSException ex) {
throw new IOException(ex.getMessage());
}
}
public int read(byte b[], int off, int len) throws IOException {
if (off == 0) {
try {
return message.readBytes(b, len);
}
catch (JMSException ex) {
throw new IOException(ex.getMessage());
}
}
else {
return super.read(b, off, len);
}
}
public int read() throws IOException {
try {
return message.readByte();
}
catch (MessageEOFException ex) {
return -1;
}
catch (JMSException ex) {
throw new IOException(ex.getMessage());
}
}
}
}

View File

@@ -1,135 +0,0 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.transport.jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jms.listener.SessionAwareMessageListener;
import org.springframework.jms.support.JmsUtils;
import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.endpoint.MessageEndpoint;
import org.springframework.ws.transport.ServerTransportObjectSupport;
import org.springframework.ws.transport.TransportInputStream;
import org.springframework.ws.transport.TransportOutputStream;
/**
* JMS <code>MessageListener</code> that can be used to handle incoming JMS messages. Requires a
* <code>WebServiceMessageFactory</code> which is used to convert the incoming JMS <code>TextMessage</code> into a
* <code>WebServiceMessage</code>, and passes that context to the required <code>MessageEndpoint</code>. If a response
* is created, it is sent using a response JMS message.
* <p/>
* This class implements both <code>MessageListener</code>, for
* <p/>
* Note that the <code>MessageDispatcher</code> implements the <code>MessageEndpoint</code> interface, enabling this
* adapter to function as a gateway to further message handling logic.
*
* @author Arjen Poutsma
* @see #setMessageFactory(org.springframework.ws.WebServiceMessageFactory)
* @see #setMessageEndpoint(org.springframework.ws.endpoint.MessageEndpoint)
*/
public class JmsTransportMessageListener extends ServerTransportObjectSupport
implements SessionAwareMessageListener, MessageListener, InitializingBean {
private static final Log logger = LogFactory.getLog(JmsTransportMessageListener.class);
private MessageEndpoint messageEndpoint;
/**
* Returns the <code>MessageEndpoint</code> used by this listener.
*/
public MessageEndpoint getMessageEndpoint() {
return messageEndpoint;
}
/**
* Sets the <code>MessageEndpoint</code> used by this listener.
*/
public void setMessageEndpoint(MessageEndpoint messageEndpoint) {
this.messageEndpoint = messageEndpoint;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(getMessageFactory(), "messageFactory is required");
Assert.notNull(getMessageEndpoint(), "messageEndpoint must not be null");
logger.info("Using message factory [" + getMessageFactory() + "]");
}
public void onMessage(Message message) {
try {
onMessage(message, null);
}
catch (JMSException ex) {
logger.error("Could not handle message: " + ex.getMessage(), ex);
}
}
public void onMessage(Message message, Session session) throws JMSException {
if (message instanceof TextMessage) {
logger.info("Received message [" + message.getJMSMessageID() + "]");
try {
TransportInputStream tis = new JmsTransportInputStream((TextMessage) message);
TransportOutputStream tos;
if (session == null) {
tos = null;
}
else {
tos = new JmsTransportOutputStream(session, ((TextMessage) message).getJMSCorrelationID());
}
handle(tis, tos, getMessageEndpoint());
}
catch (Exception ex) {
logger.error(ex, ex);
}
}
else {
throw new IllegalArgumentException("JmsTransportMessageListener can only handle TextMessages");
}
}
protected void handleResponse(TransportInputStream tis, TransportOutputStream tos, WebServiceMessage response)
throws Exception {
if (tos != null) {
Message requestMessage = ((JmsTransportInputStream) tis).getTextMessage();
if (requestMessage.getJMSReplyTo() == null) {
logger.warn("Incoming message has no ReplyTo set, not sending response");
return;
}
response.writeTo(tos);
Message responseMessage = ((JmsTransportOutputStream) tos).getTextMessage();
Session session = ((JmsTransportOutputStream) tos).getSession();
MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
try {
producer.send(responseMessage);
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
else {
logger.warn("JMS Session is not available, sending of response is impossible");
}
}
}

View File

@@ -16,12 +16,11 @@
package org.springframework.ws.transport.jms;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -29,14 +28,14 @@ import org.springframework.ws.transport.TransportOutputStream;
/**
* JMS specific implementation of the <code>TransportOutputStream</code> interface. Exposes a JMS
* <code>TextMessage</code>, constructed lazily using a <code>Session</code>.
* <code>BytesMessage</code>, constructed lazily using a <code>Session</code>.
*
* @author Arjen Poutsma
* @see #getTextMessage()
* @see #getMessage()
*/
public class JmsTransportOutputStream extends TransportOutputStream {
private TextMessage textMessage;
private BytesMessage message;
private final Session session;
@@ -74,54 +73,67 @@ public class JmsTransportOutputStream extends TransportOutputStream {
}
/**
* Returns the wrapped JMS <code>TextMessage</code>. Created lazily.
* Returns the wrapped JMS <code>BytesMessage</code>. Created lazily.
*/
public TextMessage getTextMessage() throws IOException {
if (textMessage == null) {
public BytesMessage getMessage() throws IOException {
if (message == null) {
try {
textMessage = session.createTextMessage();
message = session.createBytesMessage();
if (StringUtils.hasLength(correlationId)) {
textMessage.setJMSCorrelationID(correlationId);
message.setJMSCorrelationID(correlationId);
}
}
catch (JMSException ex) {
throw new IOException("Could not create text message: " + ex.getMessage());
throw new IOException("Could not create message: " + ex.getMessage());
}
}
return textMessage;
return message;
}
protected OutputStream getOutputStream() throws IOException {
return new TextMessageOutputStream();
return new BytesMessageOutputStream();
}
public void addHeader(String name, String value) throws IOException {
try {
getTextMessage().setStringProperty(name, value);
getMessage().setStringProperty(name, value);
}
catch (JMSException ex) {
throw new IOException("Could not set property " + ex.getMessage());
}
}
private class TextMessageOutputStream extends ByteArrayOutputStream {
/**
* OutputStream that wraps the JMS <code>BytesMessage</code>.
*/
private class BytesMessageOutputStream extends OutputStream {
public void flush() throws IOException {
public void write(byte b[]) throws IOException {
try {
getTextMessage().setText(new String(toString("UTF-8")));
getMessage().writeBytes(b);
}
catch (JMSException ex) {
throw new IOException("Could not set message text: " + ex.getMessage());
throw new IOException(ex.getMessage());
}
}
public void close() throws IOException {
public void write(byte b[], int off, int len) throws IOException {
try {
getTextMessage().setText(new String(toString("UTF-8")));
getMessage().writeBytes(b, off, len);
}
catch (JMSException ex) {
throw new IOException("Could not set message text: " + ex.getMessage());
throw new IOException(ex.getMessage());
}
}
public void write(int b) throws IOException {
try {
getMessage().writeByte((byte) b);
}
catch (JMSException ex) {
throw new IOException(ex.getMessage());
}
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.transport.jms;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.listener.SessionAwareMessageListener;
/**
* Spring-2.0 <code>SessionAwareMessageListener</code> that can be used to handle incoming JMS messages. Requires a
* <code>WebServiceMessageFactory</code> which is used to convert the incoming JMS <code>TextMessage</code> into a
* <code>WebServiceMessage</code>, and passes that context to the required <code>MessageEndpoint</code>. If a response
* is created, it is sent using a response JMS message.
* <p/>
* Note that the <code>MessageDispatcher</code> implements the <code>MessageEndpoint</code> interface, enabling this
* adapter to function as a gateway to further message handling logic.
*
* @author Arjen Poutsma
* @see #setMessageFactory(org.springframework.ws.WebServiceMessageFactory)
* @see #setMessageEndpoint(org.springframework.ws.endpoint.MessageEndpoint)
*/
public class MessageEndpointMessageListener extends JmsReceiverObjectSupport implements SessionAwareMessageListener {
public void onMessage(Message message, Session session) throws JMSException {
logger.info("Received request [" + message.getJMSMessageID() + "]");
try {
handle((BytesMessage) message, session);
}
catch (Exception ex) {
JMSException jmsException = new JMSException(ex.getMessage());
jmsException.setLinkedException(ex);
throw jmsException;
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.transport.jms;
import java.util.Collections;
import java.util.Iterator;
import javax.jms.BytesMessage;
import junit.framework.TestCase;
import org.easymock.MockControl;
public class JmsTransportInputStreamTest extends TestCase {
private JmsTransportInputStream tis;
private MockControl messageControl;
private BytesMessage messageMock;
protected void setUp() throws Exception {
messageControl = MockControl.createControl(BytesMessage.class);
messageMock = (BytesMessage) messageControl.getMock();
tis = new JmsTransportInputStream(messageMock);
}
public void testHeaders() throws Exception {
String headerName = "Header";
messageControl.expectAndReturn(messageMock.getPropertyNames(),
Collections.enumeration(Collections.singleton(headerName)));
String headerValue = "Value";
messageControl.expectAndReturn(messageMock.getStringProperty(headerName), headerValue);
messageControl.replay();
Iterator iterator = tis.getHeaderNames();
assertTrue("No headers found", iterator.hasNext());
assertEquals("Invalid header", headerName, iterator.next());
iterator = tis.getHeaders(headerName);
assertTrue("No header values found", iterator.hasNext());
assertEquals("Invalid header value", headerValue, iterator.next());
messageControl.verify();
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.transport.jms;
import javax.jms.BytesMessage;
import javax.jms.Session;
import junit.framework.TestCase;
import org.easymock.MockControl;
public class JmsTransportOutputStreamTest extends TestCase {
private JmsTransportOutputStream tos;
private MockControl messageControl;
private BytesMessage messageMock;
private MockControl sessionControl;
private Session sessionMock;
protected void setUp() throws Exception {
messageControl = MockControl.createControl(BytesMessage.class);
messageMock = (BytesMessage) messageControl.getMock();
sessionControl = MockControl.createControl(Session.class);
sessionMock = (Session) sessionControl.getMock();
tos = new JmsTransportOutputStream(sessionMock);
}
public void testHeaders() throws Exception {
sessionControl.expectAndReturn(sessionMock.createBytesMessage(), messageMock);
String headerName = "Header";
String headerValue = "Value";
messageMock.setStringProperty(headerName, headerValue);
sessionControl.replay();
messageControl.replay();
tos.addHeader(headerName, headerValue);
sessionControl.verify();
messageControl.verify();
}
}

View File

@@ -1,3 +1,5 @@
/*
*/
/*
* Copyright 2006 the original author or authors.
*
@@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
package org.springframework.ws.transport.jms;
@@ -20,15 +23,17 @@ import javax.jms.BytesMessage;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.StreamMessage;
import junit.framework.TestCase;
import org.codehaus.activemq.message.ActiveMQBytesMessage;
import org.codehaus.activemq.message.ActiveMQTopic;
import org.easymock.MockControl;
import org.springframework.ws.MockWebServiceMessageFactory;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.endpoint.MessageEndpoint;
public class JmsTransportMessageListenerTest extends TestCase {
public class MessageEndpointMessageListenerTest extends TestCase {
private static final String REQUEST = " <SOAP-ENV:Envelope\n" +
" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
@@ -36,24 +41,28 @@ public class JmsTransportMessageListenerTest extends TestCase {
" <m:GetLastTradePrice xmlns:m=\"Some-URI\">\n" + " <symbol>DIS</symbol>\n" +
" </m:GetLastTradePrice>\n" + " </SOAP-ENV:Body>\n" + "</SOAP-ENV:Envelope>";
private JmsTransportMessageListener messageListener;
private MessageEndpointMessageListener messageListener;
private MockControl messageControl;
private BytesMessage request;
private TextMessage requestMock;
private MockControl sessionControl;
private Session sessionMock;
protected void setUp() throws Exception {
messageListener = new JmsTransportMessageListener();
messageControl = MockControl.createControl(TextMessage.class);
requestMock = (TextMessage) messageControl.getMock();
messageListener = new MessageEndpointMessageListener();
request = new ActiveMQBytesMessage();
request.writeBytes(REQUEST.getBytes("UTF-8"));
messageListener.setMessageFactory(new MockWebServiceMessageFactory());
sessionControl = MockControl.createControl(Session.class);
sessionMock = (Session) sessionControl.getMock();
}
public void testOnMessageInvalidMessage() throws Exception {
MockControl mockControl = MockControl.createControl(BytesMessage.class);
BytesMessage bytesMessage = (BytesMessage) mockControl.getMock();
MockControl mockControl = MockControl.createControl(StreamMessage.class);
StreamMessage message = (StreamMessage) mockControl.getMock();
try {
messageListener.onMessage(bytesMessage);
messageListener.onMessage(message, sessionMock);
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
@@ -62,8 +71,6 @@ public class JmsTransportMessageListenerTest extends TestCase {
}
public void testOnMessageNoResponse() throws Exception {
messageControl.expectAndReturn(requestMock.getText(), REQUEST);
messageControl.replay();
MessageEndpoint endpoint = new MessageEndpoint() {
@@ -72,28 +79,22 @@ public class JmsTransportMessageListenerTest extends TestCase {
};
messageListener.setMessageEndpoint(endpoint);
messageListener.onMessage(requestMock);
messageControl.verify();
request.reset();
messageListener.onMessage(request, sessionMock);
}
public void testOnMessageResponse() throws Exception {
MockControl sessionControl = MockControl.createControl(Session.class);
Session sessionMock = (Session) sessionControl.getMock();
MockControl producerControl = MockControl.createControl(MessageProducer.class);
MessageProducer producerMock = (MessageProducer) producerControl.getMock();
TextMessage responseMock = (TextMessage) messageControl.getMock();
messageControl.expectAndReturn(requestMock.getText(), REQUEST);
BytesMessage response = new ActiveMQBytesMessage();
String correlationId = "correlationId";
Destination replyTo = new Destination() {
};
messageControl.expectAndReturn(requestMock.getJMSCorrelationID(), correlationId);
sessionControl.expectAndReturn(sessionMock.createTextMessage(), responseMock);
responseMock.setJMSCorrelationID(correlationId);
messageControl.expectAndReturn(requestMock.getJMSReplyTo(), replyTo);
Destination replyTo = new ActiveMQTopic();
request.setJMSCorrelationID(correlationId);
request.setJMSReplyTo(replyTo);
request.reset();
sessionControl.expectAndReturn(sessionMock.createBytesMessage(), response);
sessionControl.expectAndReturn(sessionMock.createProducer(replyTo), producerMock);
producerMock.send(responseMock);
messageControl.replay();
producerMock.send(response);
sessionControl.replay();
producerControl.replay();
@@ -105,10 +106,11 @@ public class JmsTransportMessageListenerTest extends TestCase {
};
messageListener.setMessageEndpoint(endpoint);
messageListener.onMessage(requestMock, sessionMock);
messageListener.onMessage(request, sessionMock);
messageControl.verify();
sessionControl.verify();
producerControl.verify();
assertEquals("Invalid correlationId", correlationId, response.getJMSCorrelationID());
}
}
}*/