use of org.springframework.messaging.MessageChannel in project camel by apache.
the class SpringIntegrationConsumer method handleMessage.
public void handleMessage(org.springframework.messaging.Message<?> siInMessage) {
// we received a message from spring integration
// wrap that in a Camel Exchange and process it
Exchange exchange = getEndpoint().createExchange(getEndpoint().isInOut() ? ExchangePattern.InOut : ExchangePattern.InOnly);
exchange.setIn(new SpringIntegrationMessage(siInMessage));
// process the exchange
try {
getProcessor().process(exchange);
} catch (Exception e) {
getExceptionHandler().handleException("Error processing exchange", exchange, e);
return;
}
// reply logic
if (getEndpoint().isInOut()) {
MessageChannel reply = null;
// get the output channel from message header
Object returnAddress = siInMessage.getHeaders().getReplyChannel();
if (returnAddress != null) {
if (returnAddress instanceof String) {
reply = context.getApplicationContext().getBean((String) returnAddress, MessageChannel.class);
} else if (returnAddress instanceof MessageChannel) {
reply = (MessageChannel) returnAddress;
}
} else {
reply = outputChannel;
// we want to do in-out so the inputChannel is mandatory (used to receive reply from spring integration)
if (reply == null) {
throw new IllegalArgumentException("OutputChannel has not been configured on " + getEndpoint());
}
}
if (reply == null) {
throw new IllegalArgumentException("Cannot resolve ReplyChannel from message: " + siInMessage);
}
// put the message back the outputChannel if we need
org.springframework.messaging.Message<?> siOutMessage = SpringIntegrationBinding.storeToSpringIntegrationMessage(exchange.getOut());
// send the message to spring integration
log.debug("Sending {} to ReplyChannel: {}", siOutMessage, reply);
reply.send(siOutMessage);
}
}
use of org.springframework.messaging.MessageChannel in project camel by apache.
the class CamelTargetAdapter method send.
public boolean send(Message<?> message) throws Exception {
boolean result = false;
ExchangePattern pattern;
if (isExpectReply()) {
pattern = ExchangePattern.InOut;
} else {
pattern = ExchangePattern.InOnly;
}
Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() : outExchange.getIn();
if (camelMsg.isFault()) {
result = true;
}
Message<?> response;
if (isExpectReply()) {
//Check the message header for the return address
response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
if (replyChannel == null) {
MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
if (messageReplyChannel != null) {
result = messageReplyChannel.send(response);
} else {
throw new MessageDeliveryException(response, "Cannot resolve ReplyChannel from message: " + message);
}
} else {
result = replyChannel.send(response);
}
}
return result;
}
use of org.springframework.messaging.MessageChannel in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method csrfProtectionForConnect.
@Test
public void csrfProtectionForConnect() throws InterruptedException {
loadConfig(SockJsSecurityConfig.class);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
Message<?> message = message(headers, "/authentication");
MessageChannel messageChannel = clientInboundChannel();
try {
messageChannel.send(message);
fail("Expected Exception");
} catch (MessageDeliveryException success) {
assertThat(success.getCause()).isInstanceOf(MissingCsrfTokenException.class);
}
}
use of org.springframework.messaging.MessageChannel in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method addsAuthenticationPrincipalResolverWhenNoAuthorization.
@Test
public void addsAuthenticationPrincipalResolverWhenNoAuthorization() throws InterruptedException {
loadConfig(NoInboundSecurityConfig.class);
MessageChannel messageChannel = clientInboundChannel();
Message<String> message = message("/permitAll/authentication");
messageChannel.send(message);
assertThat(context.getBean(MyController.class).authenticationPrincipal).isEqualTo((String) messageUser.getPrincipal());
}
use of org.springframework.messaging.MessageChannel in project camel by apache.
the class SpringIntegrationOneWayConsumerTest method testSendingOneWayMessage.
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "outputChannel");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
Aggregations