Merge branch 'master' of git.springsource.org:spring-integration/spring-integration
This commit is contained in:
@@ -191,21 +191,13 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
&& (this.destination != null || this.destinationName != null),
|
||||
"Either a 'jmsTemplate' or *both* 'connectionFactory' and"
|
||||
+ " 'destination' (or 'destination-name') are required.");
|
||||
this.jmsTemplate = this.createDefaultJmsTemplate();
|
||||
this.jmsTemplate = this.createJmsTemplate();
|
||||
}
|
||||
this.jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled);
|
||||
this.jmsTemplate.setTimeToLive(this.timeToLive);
|
||||
this.jmsTemplate.setPriority(this.priority);
|
||||
this.jmsTemplate.setDeliveryMode(this.deliveryMode);
|
||||
if (this.messageConverter != null) {
|
||||
this.jmsTemplate.setMessageConverter(this.messageConverter);
|
||||
}
|
||||
//this.configureMessageConverter(this.jmsTemplate);
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private JmsTemplate createDefaultJmsTemplate() {
|
||||
private JmsTemplate createJmsTemplate() {
|
||||
JmsTemplate jmsTemplate = new JmsTemplate();
|
||||
jmsTemplate.setConnectionFactory(this.connectionFactory);
|
||||
if (this.destination != null) {
|
||||
@@ -218,16 +210,18 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
if (this.destinationResolver != null) {
|
||||
jmsTemplate.setDestinationResolver(this.destinationResolver);
|
||||
}
|
||||
jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled);
|
||||
jmsTemplate.setTimeToLive(this.timeToLive);
|
||||
jmsTemplate.setPriority(this.priority);
|
||||
jmsTemplate.setDeliveryMode(this.deliveryMode);
|
||||
if (this.messageConverter != null) {
|
||||
jmsTemplate.setMessageConverter(this.messageConverter);
|
||||
}
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
// protected void configureMessageConverter(JmsTemplate jmsTemplate) {
|
||||
// MessageConverter converter = jmsTemplate.getMessageConverter();
|
||||
// if (converter == null) {
|
||||
// jmsTemplate.setMessageConverter(new SimpleMessageConverter());
|
||||
// }
|
||||
// }
|
||||
protected boolean shouldExtractPayload() {
|
||||
return extractPayload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
@@ -22,9 +26,8 @@ import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
@@ -55,10 +58,10 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
System.out.println(message);
|
||||
Assert.assertNotNull(message);
|
||||
assertNotNull(message);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception {
|
||||
ActiveMqTestUtils.prepare();
|
||||
@@ -76,7 +79,8 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
Assert.assertNotNull(message);
|
||||
assertNotNull(message);
|
||||
assertEquals("echoWithException", ((TextMessage) message).getText());
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@@ -86,35 +90,40 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class);
|
||||
String reply = gateway.echo("echoWithExceptionChannel");
|
||||
System.out.println("Reply: " + reply);
|
||||
assertEquals("echoWithException", reply);
|
||||
applicationContext.close();
|
||||
}
|
||||
//
|
||||
public static class SampleService{
|
||||
public String echoWithException(String value){
|
||||
|
||||
|
||||
public static class SampleService {
|
||||
|
||||
public String echoWithException(String value) {
|
||||
throw new SampleException("echoWithException");
|
||||
}
|
||||
|
||||
public String echo(String value){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class SampleException extends RuntimeException{
|
||||
public static class SampleException extends RuntimeException {
|
||||
public SampleException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
|
||||
|
||||
public static interface SampleGateway {
|
||||
public String echo(String value);
|
||||
}
|
||||
|
||||
public static class SampleErrorMessageMapper implements InboundMessageMapper<Throwable>{
|
||||
public org.springframework.integration.Message<?> toMessage(
|
||||
Throwable t) throws Exception {
|
||||
|
||||
|
||||
public static class SampleErrorMessageMapper implements InboundMessageMapper<Throwable> {
|
||||
public org.springframework.integration.Message<?> toMessage(Throwable t) throws Exception {
|
||||
return MessageBuilder.withPayload(t.getCause().getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ public class JmsMessageHistoryTests {
|
||||
assertEquals("jms:inbound-channel-adapter", event1.getProperty(MessageHistory.TYPE_PROPERTY));
|
||||
assertEquals("sampleJmsInboundAdapter", event1.getProperty(MessageHistory.NAME_PROPERTY));
|
||||
Properties event2 = historyIterator.next();
|
||||
System.out.println(event2);
|
||||
assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY));
|
||||
assertEquals("jmsInputChannel", event2.getProperty(MessageHistory.NAME_PROPERTY));
|
||||
}
|
||||
|
||||
@@ -101,6 +101,20 @@ public class JmsOutboundChannelAdapterParserTests {
|
||||
assertEquals(context.getBean("template"), jmsTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterWithJmsTemplateQos() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsOutboundWithJmsTemplateQos.xml", this.getClass());
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
|
||||
JmsTemplate jmsTemplate = (JmsTemplate) handlerAccessor.getPropertyValue("jmsTemplate");
|
||||
assertNotNull(jmsTemplate);
|
||||
assertEquals(context.getBean("template"), jmsTemplate);
|
||||
assertTrue(jmsTemplate.isExplicitQosEnabled());
|
||||
assertEquals(7, jmsTemplate.getPriority());
|
||||
assertEquals(12345, jmsTemplate.getTimeToLive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterWithMessageConverter() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:jms="http://www.springframework.org/schema/integration/jms"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jms
|
||||
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
|
||||
|
||||
<integration:channel id="input"/>
|
||||
|
||||
<jms:outbound-channel-adapter id="adapter" channel="input" jms-template="template"/>
|
||||
|
||||
<bean id="template" class="org.springframework.jms.core.JmsTemplate" >
|
||||
<property name="connectionFactory">
|
||||
<bean class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.jms.StubConnection">
|
||||
<constructor-arg value="target-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="explicitQosEnabled" value="true"/>
|
||||
<property name="priority" value="7"/>
|
||||
<property name="timeToLive" value="12345"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user