INT-1224 - added test-case sample for MarshallingMessageConverter
This commit is contained in:
@@ -15,8 +15,14 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
</dependency>
|
||||
<!-- test-scoped dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-oxm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -66,6 +66,7 @@ public class JmsOutboundGatewayParserTests {
|
||||
assertEquals("HELLO", result);
|
||||
}
|
||||
|
||||
|
||||
public static interface SampleGateway{
|
||||
public String echo(String value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd">
|
||||
|
||||
|
||||
<int:channel id="outbound-gateway-channel"/>
|
||||
|
||||
<int:channel id="output">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-jms:outbound-gateway request-channel="outbound-gateway-channel"
|
||||
reply-destination="replyQueue"
|
||||
reply-channel="output"
|
||||
request-destination="requestQueue"
|
||||
message-converter="marshallingMessageConverter"/>
|
||||
|
||||
<int-jms:inbound-gateway request-destination="requestQueue"
|
||||
request-channel="inbound-gateway-channel"
|
||||
message-converter="marshallingMessageConverter"/>
|
||||
|
||||
<int:channel id="inbound-gateway-channel"/>
|
||||
|
||||
<int:service-activator input-channel="inbound-gateway-channel" method="echo">
|
||||
<bean class="org.springframework.integration.jms.config.JmsWithMarshallingMessageConverterTests$SampleService"/>
|
||||
</int:service-activator>
|
||||
|
||||
<bean id="marshallingMessageConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.jms.config.JmsWithMarshallingMessageConverterTests$SampleMarshaller"/>
|
||||
</constructor-arg>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.jms.config.JmsWithMarshallingMessageConverterTests$SampleUnmarshaller"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
|
||||
<constructor-arg value="request.queue"/>
|
||||
</bean>
|
||||
|
||||
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
|
||||
<constructor-arg value="reply.queue"/>
|
||||
</bean>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="sessionCacheSize" value="10"/>
|
||||
<property name="cacheProducers" value="false"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.integration.jms.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class JmsWithMarshallingMessageConverterTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void demoWithMarshallingConverter(){
|
||||
ActiveMqTestUtils.prepare();
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JmsWithMarshallingMessageConverterTests-context.xml", JmsWithMarshallingMessageConverterTests.class);
|
||||
MessageChannel input = ac.getBean("outbound-gateway-channel", MessageChannel.class);
|
||||
PollableChannel output = ac.getBean("output", PollableChannel.class);
|
||||
|
||||
input.send(new StringMessage("hello"));
|
||||
Message<String> replyMessage = (Message<String>) output.receive();
|
||||
System.out.println("Message: " + replyMessage);
|
||||
}
|
||||
|
||||
public static class SampleService{
|
||||
public String echo(String value){
|
||||
return value.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleMarshaller implements Marshaller{
|
||||
public void marshal(Object graph, Result result) throws IOException,
|
||||
XmlMappingException {
|
||||
String payload = null;
|
||||
if (graph instanceof Message<?>){
|
||||
payload = (String) ((Message<?>)graph).getPayload();
|
||||
} else {
|
||||
payload = (String) graph;
|
||||
}
|
||||
((StreamResult)result).getOutputStream().write(payload.getBytes());
|
||||
|
||||
}
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleUnmarshaller implements Unmarshaller{
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
public Object unmarshal(Source source) throws IOException,
|
||||
XmlMappingException {
|
||||
|
||||
InputStream io = ((StreamSource)source).getInputStream();
|
||||
byte[] bytes = new byte[io.available()];
|
||||
io.read(bytes);
|
||||
return new StringMessage(new String(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user