use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class UnicastingDispatcherTests method withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel.
@SuppressWarnings("unchecked")
@Test
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
MessageHandler errorHandler = message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
assertTrue(message.getPayload() instanceof MessageDeliveryException);
replyChannel.send(new GenericMessage<String>("reply"));
};
errorChannel.subscribe(errorHandler);
RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
assertEquals("reply", reply.getPayload());
context.close();
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithGenericMessageMethod.
@Test
public /*
* No handler fallback methods; don't force RRE
*/
void testRequestReplyExchangerWithGenericMessageMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(Message<String> request) {
return request.getPayload().toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertEquals("FOO", outputChannel.receive(10).getPayload());
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousGenericMessageMethod.
@Test
public /*
* No handler fallback methods; ambiguous message handler fallbacks; force RRE
*/
void testRequestReplyExchangerWithAmbiguousGenericMessageMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(Message<String> request) {
return request.getPayload().toUpperCase();
}
@SuppressWarnings("unused")
public String bar(Message<String> request) {
return request.getPayload().toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertNotEquals("FOO", outputChannel.receive(10).getPayload());
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousMethod.
@Test
public /*
* One message handler fallback method (RRE); ambiguous handler fallbacks; force RRE
*/
void testRequestReplyExchangerWithAmbiguousMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(String request) {
return request.toUpperCase();
}
@SuppressWarnings("unused")
public String bar(String request) {
return request.toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertNotEquals("FOO", outputChannel.receive(10).getPayload());
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchanger.
@Test
public void testRequestReplyExchanger() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
};
final Message<?> test = new GenericMessage<Object>("foo");
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean) {
@Override
protected Object handleRequestMessage(Message<?> message) {
Object o = super.handleRequestMessage(message);
assertSame(test, o);
return null;
}
};
serviceActivator.handleMessage(test);
}
Aggregations