Javadoc
This commit is contained in:
@@ -18,9 +18,12 @@ package org.springframework.ws.transport.jms;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.jms.support.destination.DynamicDestinationResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
@@ -44,6 +47,8 @@ public class JmsMessageSender implements WebServiceMessageSender, JmsTransportCo
|
||||
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
private DestinationResolver destinationResolver = new DynamicDestinationResolver();
|
||||
|
||||
private long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT;
|
||||
|
||||
public JmsMessageSender() {
|
||||
@@ -54,12 +59,16 @@ public class JmsMessageSender implements WebServiceMessageSender, JmsTransportCo
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default ConnectionFactory to use for obtaining JMS Connections.
|
||||
* Set the ConnectionFactory to use for obtaining JMS {@link Connection}s.
|
||||
*/
|
||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public void setDestinationResolver(DestinationResolver destinationResolver) {
|
||||
this.destinationResolver = destinationResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timeout to use for receive calls. The default is 0, which means no timeout.
|
||||
*/
|
||||
@@ -72,7 +81,7 @@ public class JmsMessageSender implements WebServiceMessageSender, JmsTransportCo
|
||||
JmsSenderConnection connection = null;
|
||||
try {
|
||||
JmsUri uri = new JmsUri(uriString);
|
||||
connection = new JmsSenderConnection(uri, connectionFactory, receiveTimeout);
|
||||
connection = new JmsSenderConnection(uri, connectionFactory, destinationResolver, receiveTimeout);
|
||||
return connection;
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import javax.jms.TemporaryQueue;
|
||||
|
||||
import org.springframework.jms.connection.ConnectionFactoryUtils;
|
||||
import org.springframework.jms.support.JmsUtils;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.FaultAwareWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
@@ -55,38 +56,40 @@ public class JmsSenderConnection extends AbstractSenderConnection
|
||||
|
||||
private final ConnectionFactory connectionFactory;
|
||||
|
||||
private final DestinationResolver destinationResolver;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
private final Session session;
|
||||
|
||||
private final Destination requestDestination;
|
||||
|
||||
private Destination responseDestination;
|
||||
|
||||
private final JmsUri uri;
|
||||
|
||||
private final long receiveTimeout;
|
||||
|
||||
private Destination responseDestination;
|
||||
|
||||
private BytesMessage requestMessage;
|
||||
|
||||
private BytesMessage responseMessage;
|
||||
|
||||
private long receiveTimeout;
|
||||
|
||||
/**
|
||||
* Constructs a new JMS connection with the given parameters.
|
||||
*/
|
||||
protected JmsSenderConnection(JmsUri uri, ConnectionFactory connectionFactory, long receiveTimeout)
|
||||
throws JMSException {
|
||||
protected JmsSenderConnection(JmsUri uri,
|
||||
ConnectionFactory connectionFactory,
|
||||
DestinationResolver destinationResolver,
|
||||
long receiveTimeout) throws JMSException {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
|
||||
Assert.notNull(destinationResolver, "destinationResolver must not be null");
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.destinationResolver = destinationResolver;
|
||||
connection = connectionFactory.createConnection();
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
if (uri.isPubSubDomain()) {
|
||||
requestDestination = session.createTopic(uri.getDestination());
|
||||
}
|
||||
else {
|
||||
requestDestination = session.createQueue(uri.getDestination());
|
||||
}
|
||||
requestDestination =
|
||||
destinationResolver.resolveDestinationName(session, uri.getDestination(), uri.isPubSubDomain());
|
||||
this.uri = uri;
|
||||
this.receiveTimeout = receiveTimeout;
|
||||
}
|
||||
@@ -154,13 +157,8 @@ public class JmsSenderConnection extends AbstractSenderConnection
|
||||
messageProducer.setTimeToLive(uri.getTimeToLive());
|
||||
messageProducer.setPriority(uri.getPriority());
|
||||
if (uri.hasReplyTo()) {
|
||||
if (uri.isPubSubDomain()) {
|
||||
responseDestination = session.createTopic(uri.getReplyTo());
|
||||
}
|
||||
else {
|
||||
responseDestination = session.createQueue(uri.getReplyTo());
|
||||
}
|
||||
|
||||
responseDestination =
|
||||
destinationResolver.resolveDestinationName(session, uri.getReplyTo(), uri.isPubSubDomain());
|
||||
}
|
||||
else {
|
||||
responseDestination = session.createTemporaryQueue();
|
||||
|
||||
@@ -73,8 +73,8 @@ public class DefaultMonitoringStrategy extends AbstractPollingMonitoringStrategy
|
||||
|
||||
/**
|
||||
* Creates the search term that defines the messages to look for. Default implementation returns a term that
|
||||
* searches for all messages in the folder that are {@link Flags.Flag#RECENT RECENT}, and not {@link
|
||||
* Flags.Flag#ANSWERED ANSWERED}, and not {@link Flags.Flag#DELETED DELETED}.
|
||||
* searches for all messages in the folder that are {@link Flags.Flag#RECENT RECENT}, not {@link Flags.Flag#ANSWERED
|
||||
* ANSWERED}, and not {@link Flags.Flag#DELETED DELETED}.
|
||||
* <p/>
|
||||
* Return <code>null</code> if all messages should be returned from {@link #pollForNewMessages(Folder)}.
|
||||
*/
|
||||
|
||||
@@ -20,16 +20,18 @@ import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.URLName;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.ws.transport.WebServiceMessageSender;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MailMessageSender implements WebServiceMessageSender, InitializingBean {
|
||||
|
||||
private Session session = Session.getInstance(new Properties(), null);
|
||||
@@ -97,6 +99,6 @@ public class MailMessageSender implements WebServiceMessageSender, InitializingB
|
||||
}
|
||||
|
||||
public boolean supports(String uri) {
|
||||
return StringUtils.hasLength(uri) && uri.startsWith(MailtoUri.MAILTO_SCHEME);
|
||||
return StringUtils.hasLength(uri) && uri.startsWith(MailTransportConstants.URI_SCHEME + ":");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,10 +165,7 @@ public class MailSenderConnection extends AbstractSenderConnection {
|
||||
Store store = null;
|
||||
Folder folder = null;
|
||||
try {
|
||||
String requestMessageId = null;
|
||||
if (requestMessage instanceof MimeMessage) {
|
||||
requestMessageId = ((MimeMessage) requestMessage).getMessageID();
|
||||
}
|
||||
String requestMessageId = requestMessage.getMessageID();
|
||||
if (StringUtils.hasLength(requestMessageId)) {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
@@ -194,7 +191,7 @@ public class MailSenderConnection extends AbstractSenderConnection {
|
||||
if (responses.length > 1) {
|
||||
logger.warn("Received more than one response for request with ID [" + requestMessageId + "]");
|
||||
}
|
||||
responseMessage = (MimeMessage) responses[0];
|
||||
responseMessage = responses[0];
|
||||
}
|
||||
if (deleteAfterReceive) {
|
||||
responseMessage.setFlag(Flags.Flag.DELETED, true);
|
||||
|
||||
@@ -18,11 +18,15 @@ package org.springframework.ws.transport.mail;
|
||||
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface MailTransportConstants extends TransportConstants {
|
||||
|
||||
/** The "In-Reply-To" header. */
|
||||
/**
|
||||
* The "In-Reply-To" header.
|
||||
*/
|
||||
String HEADER_IN_REPLY_TO = "In-Reply-To";
|
||||
|
||||
|
||||
String URI_SCHEME = "mailto";
|
||||
}
|
||||
|
||||
@@ -18,19 +18,18 @@ package org.springframework.ws.transport.mail;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.Address;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.support.ParameterizedUri;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MailtoUri extends ParameterizedUri {
|
||||
|
||||
static final String MAILTO_SCHEME = "mailto:";
|
||||
|
||||
public MailtoUri(String uri) {
|
||||
super(uri);
|
||||
Assert.isTrue(uri.startsWith(MAILTO_SCHEME), "Invalid uri: " + uri);
|
||||
Assert.isTrue(uri.startsWith(MailTransportConstants.URI_SCHEME), "Invalid uri: " + uri);
|
||||
try {
|
||||
InternetAddress.parse(getDestination(), false);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JmsMessageSenderIntegrationTest extends AbstractDependencyInjection
|
||||
this.messageSender = messageSender;
|
||||
}
|
||||
|
||||
public void testSendAndReceiveResponse() throws Exception {
|
||||
public void testSendAndReceiveQueue() throws Exception {
|
||||
WebServiceConnection connection = null;
|
||||
try {
|
||||
connection = messageSender.createConnection(REQUEST_QUEUE_URI);
|
||||
|
||||
@@ -55,15 +55,15 @@ public class TcpMessageReceiverIntegrationTest extends AbstractDependencyInjecti
|
||||
|
||||
public void testServer() throws IOException, InterruptedException {
|
||||
Socket socket = new Socket("localhost", TcpMessageReceiver.DEFAULT_PORT);
|
||||
Writer writer = null;
|
||||
BufferedReader reader = null;
|
||||
Writer writer;
|
||||
BufferedReader reader;
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
|
||||
writer.write(REQUEST);
|
||||
writer.flush();
|
||||
socket.shutdownOutput();
|
||||
reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
|
||||
String line = null;
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user