SWS-311
This commit is contained in:
@@ -128,14 +128,14 @@ public class JmsMessageSender extends JmsDestinationAccessor implements WebServi
|
||||
jmsConnection = createConnection();
|
||||
jmsSession = createSession(jmsConnection);
|
||||
Destination requestDestination = resolveRequestDestination(jmsSession, uri);
|
||||
JmsSenderConnection wsConnection =
|
||||
new JmsSenderConnection(getConnectionFactory(), jmsConnection, jmsSession, requestDestination);
|
||||
Message requestMessage = createRequestMessage(jmsSession, uri);
|
||||
JmsSenderConnection wsConnection = new JmsSenderConnection(getConnectionFactory(), jmsConnection,
|
||||
jmsSession, requestDestination, requestMessage);
|
||||
wsConnection.setDeliveryMode(JmsTransportUtils.getDeliveryMode(uri));
|
||||
wsConnection.setPriority(JmsTransportUtils.getPriority(uri));
|
||||
wsConnection.setReceiveTimeout(receiveTimeout);
|
||||
wsConnection.setResponseDestination(resolveResponseDestination(jmsSession, uri));
|
||||
wsConnection.setTimeToLive(JmsTransportUtils.getTimeToLive(uri));
|
||||
wsConnection.setMessageType(JmsTransportUtils.getMessageType(uri));
|
||||
wsConnection.setTextMessageEncoding(textMessageEncoding);
|
||||
return wsConnection;
|
||||
}
|
||||
@@ -159,5 +159,19 @@ public class JmsMessageSender extends JmsDestinationAccessor implements WebServi
|
||||
return StringUtils.hasLength(destinationName) ? resolveDestinationName(session, destinationName) : null;
|
||||
}
|
||||
|
||||
private Message createRequestMessage(Session session, URI uri) throws JMSException {
|
||||
int messageType = JmsTransportUtils.getMessageType(uri);
|
||||
if (messageType == JmsTransportConstants.BYTES_MESSAGE_TYPE) {
|
||||
return session.createBytesMessage();
|
||||
}
|
||||
else if (messageType == JmsTransportConstants.TEXT_MESSAGE_TYPE) {
|
||||
return session.createTextMessage();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid message type [" + messageType + "].");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.springframework.ws.transport.jms.support.JmsTransportUtils;
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class JmsSenderConnection extends AbstractSenderConnection implements WebServiceConnection {
|
||||
public class JmsSenderConnection extends AbstractSenderConnection {
|
||||
|
||||
private final ConnectionFactory connectionFactory;
|
||||
|
||||
@@ -61,9 +61,9 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
|
||||
|
||||
private final Destination requestDestination;
|
||||
|
||||
private Destination responseDestination;
|
||||
private final Message requestMessage;
|
||||
|
||||
private Message requestMessage;
|
||||
private Destination responseDestination;
|
||||
|
||||
private Message responseMessage;
|
||||
|
||||
@@ -77,20 +77,22 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
|
||||
|
||||
private String textMessageEncoding;
|
||||
|
||||
private int messageType;
|
||||
|
||||
/** Constructs a new JMS connection with the given parameters. */
|
||||
protected JmsSenderConnection(ConnectionFactory connectionFactory,
|
||||
Connection connection,
|
||||
Session session,
|
||||
Destination requestDestination) throws JMSException {
|
||||
Destination requestDestination,
|
||||
Message requestMessage) throws JMSException {
|
||||
Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
|
||||
Assert.notNull(connection, "'connection' must not be null");
|
||||
Assert.notNull(session, "'session' must not be null");
|
||||
Assert.notNull(requestDestination, "'requestDestination' must not be null");
|
||||
Assert.notNull(requestMessage, "'requestMessage' must not be null");
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.connection = connection;
|
||||
this.session = session;
|
||||
this.requestDestination = requestDestination;
|
||||
this.requestMessage = requestMessage;
|
||||
}
|
||||
|
||||
/** Returns the request message for this connection. Returns either a {@link BytesMessage} or a {@link TextMessage}. */
|
||||
@@ -134,10 +136,6 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
|
||||
this.textMessageEncoding = textMessageEncoding;
|
||||
}
|
||||
|
||||
void setMessageType(int messageType) {
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
/*
|
||||
* URI
|
||||
*/
|
||||
@@ -167,20 +165,6 @@ public class JmsSenderConnection extends AbstractSenderConnection implements Web
|
||||
* Sending
|
||||
*/
|
||||
|
||||
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
|
||||
try {
|
||||
if (messageType == JmsTransportConstants.BYTES_MESSAGE_TYPE) {
|
||||
requestMessage = session.createBytesMessage();
|
||||
}
|
||||
else {
|
||||
requestMessage = session.createTextMessage();
|
||||
}
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
throw new JmsTransportException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addRequestHeader(String name, String value) throws IOException {
|
||||
try {
|
||||
JmsTransportUtils.addHeader(requestMessage, name, value);
|
||||
|
||||
Reference in New Issue
Block a user