Skip to content

Commit e36a840

Browse files
committed
SWS-311
1 parent baa1dc0 commit e36a840

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ public WebServiceConnection createConnection(URI uri) throws IOException {
128128
jmsConnection = createConnection();
129129
jmsSession = createSession(jmsConnection);
130130
Destination requestDestination = resolveRequestDestination(jmsSession, uri);
131-
JmsSenderConnection wsConnection =
132-
new JmsSenderConnection(getConnectionFactory(), jmsConnection, jmsSession, requestDestination);
131+
Message requestMessage = createRequestMessage(jmsSession, uri);
132+
JmsSenderConnection wsConnection = new JmsSenderConnection(getConnectionFactory(), jmsConnection,
133+
jmsSession, requestDestination, requestMessage);
133134
wsConnection.setDeliveryMode(JmsTransportUtils.getDeliveryMode(uri));
134135
wsConnection.setPriority(JmsTransportUtils.getPriority(uri));
135136
wsConnection.setReceiveTimeout(receiveTimeout);
136137
wsConnection.setResponseDestination(resolveResponseDestination(jmsSession, uri));
137138
wsConnection.setTimeToLive(JmsTransportUtils.getTimeToLive(uri));
138-
wsConnection.setMessageType(JmsTransportUtils.getMessageType(uri));
139139
wsConnection.setTextMessageEncoding(textMessageEncoding);
140140
return wsConnection;
141141
}
@@ -159,5 +159,19 @@ private Destination resolveResponseDestination(Session session, URI uri) throws
159159
return StringUtils.hasLength(destinationName) ? resolveDestinationName(session, destinationName) : null;
160160
}
161161

162+
private Message createRequestMessage(Session session, URI uri) throws JMSException {
163+
int messageType = JmsTransportUtils.getMessageType(uri);
164+
if (messageType == JmsTransportConstants.BYTES_MESSAGE_TYPE) {
165+
return session.createBytesMessage();
166+
}
167+
else if (messageType == JmsTransportConstants.TEXT_MESSAGE_TYPE) {
168+
return session.createTextMessage();
169+
}
170+
else {
171+
throw new IllegalArgumentException("Invalid message type [" + messageType + "].");
172+
}
173+
174+
}
175+
162176

163177
}

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @author Arjen Poutsma
5252
* @since 1.5.0
5353
*/
54-
public class JmsSenderConnection extends AbstractSenderConnection implements WebServiceConnection {
54+
public class JmsSenderConnection extends AbstractSenderConnection {
5555

5656
private final ConnectionFactory connectionFactory;
5757

@@ -61,9 +61,9 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
6161

6262
private final Destination requestDestination;
6363

64-
private Destination responseDestination;
64+
private final Message requestMessage;
6565

66-
private Message requestMessage;
66+
private Destination responseDestination;
6767

6868
private Message responseMessage;
6969

@@ -77,20 +77,22 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
7777

7878
private String textMessageEncoding;
7979

80-
private int messageType;
81-
8280
/** Constructs a new JMS connection with the given parameters. */
8381
protected JmsSenderConnection(ConnectionFactory connectionFactory,
8482
Connection connection,
8583
Session session,
86-
Destination requestDestination) throws JMSException {
84+
Destination requestDestination,
85+
Message requestMessage) throws JMSException {
8786
Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
8887
Assert.notNull(connection, "'connection' must not be null");
8988
Assert.notNull(session, "'session' must not be null");
89+
Assert.notNull(requestDestination, "'requestDestination' must not be null");
90+
Assert.notNull(requestMessage, "'requestMessage' must not be null");
9091
this.connectionFactory = connectionFactory;
9192
this.connection = connection;
9293
this.session = session;
9394
this.requestDestination = requestDestination;
95+
this.requestMessage = requestMessage;
9496
}
9597

9698
/** Returns the request message for this connection. Returns either a {@link BytesMessage} or a {@link TextMessage}. */
@@ -134,10 +136,6 @@ void setTextMessageEncoding(String textMessageEncoding) {
134136
this.textMessageEncoding = textMessageEncoding;
135137
}
136138

137-
void setMessageType(int messageType) {
138-
this.messageType = messageType;
139-
}
140-
141139
/*
142140
* URI
143141
*/
@@ -167,20 +165,6 @@ public String getErrorMessage() throws IOException {
167165
* Sending
168166
*/
169167

170-
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
171-
try {
172-
if (messageType == JmsTransportConstants.BYTES_MESSAGE_TYPE) {
173-
requestMessage = session.createBytesMessage();
174-
}
175-
else {
176-
requestMessage = session.createTextMessage();
177-
}
178-
}
179-
catch (JMSException ex) {
180-
throw new JmsTransportException(ex);
181-
}
182-
}
183-
184168
protected void addRequestHeader(String name, String value) throws IOException {
185169
try {
186170
JmsTransportUtils.addHeader(requestMessage, name, value);

0 commit comments

Comments
 (0)