use of org.apache.camel.ExchangePattern 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.apache.camel.ExchangePattern in project camel by apache.
the class SjmsComponent method validateMepAndReplyTo.
/**
* Helper method used to verify that when there is a namedReplyTo value we
* are using the InOut MEP. If namedReplyTo is defined and the MEP is InOnly
* the endpoint won't be expecting a reply so throw an error to alert the
* user.
*
* @param parameters {@link Endpoint} parameters
* @throws Exception throws a {@link CamelException} when MEP equals InOnly
* and namedReplyTo is defined.
*/
private static void validateMepAndReplyTo(Map<String, Object> parameters) throws Exception {
boolean namedReplyToSet = parameters.containsKey("namedReplyTo");
boolean mepSet = parameters.containsKey("exchangePattern");
if (namedReplyToSet && mepSet) {
if (!parameters.get("exchangePattern").equals(ExchangePattern.InOut.toString())) {
String namedReplyTo = (String) parameters.get("namedReplyTo");
ExchangePattern mep = ExchangePattern.valueOf((String) parameters.get("exchangePattern"));
throw new CamelException("Setting parameter namedReplyTo=" + namedReplyTo + " requires a MEP of type InOut. Parameter exchangePattern is set to " + mep);
}
}
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class SpringRemotingWithOneWayTest method testAsyncInvocation.
@Test
public void testAsyncInvocation() throws Exception {
endpoint.expectedMessageCount(1);
// we should not block even though there is no consumer on the endpoint!
myService.doSomethingAsync("Hello");
endpoint.assertIsSatisfied();
List<Exchange> list = endpoint.getReceivedExchanges();
for (Exchange exchange : list) {
log.info("Received: " + exchange.getIn().getBody());
ExchangePattern pattern = exchange.getPattern();
assertEquals("Expected pattern on exchange: " + exchange, ExchangePattern.InOnly, pattern);
}
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class CxfRsInvoker method prepareExchange.
private org.apache.camel.Exchange prepareExchange(Exchange cxfExchange, Method method, Object[] paramArray, Object response) {
ExchangePattern ep = ExchangePattern.InOut;
if (method.getReturnType() == Void.class) {
ep = ExchangePattern.InOnly;
}
final org.apache.camel.Exchange camelExchange = endpoint.createExchange(ep);
if (response != null) {
camelExchange.getOut().setBody(response);
}
CxfRsBinding binding = endpoint.getBinding();
binding.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
// the CXF in message property. Question: where should this property name be set up ?
if (endpoint.isPropagateContexts()) {
camelExchange.setProperty(UriInfo.class.getName(), new UriInfoImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(Request.class.getName(), new RequestImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(HttpHeaders.class.getName(), new HttpHeadersImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(SecurityContext.class.getName(), new SecurityContextImpl(cxfExchange.getInMessage()));
}
return camelExchange;
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class BeanInfoTest method assertMethodPattern.
protected void assertMethodPattern(BeanInfo info, String methodName, ExchangePattern expectedPattern) throws NoSuchMethodException {
Class<?> type = info.getType();
Method method = type.getMethod(methodName);
assertNotNull("Could not find method: " + methodName, method);
MethodInfo methodInfo = info.getMethodInfo(method);
assertNotNull("Could not find methodInfo for: " + method, methodInfo);
ExchangePattern actualPattern = methodInfo.getPattern();
assertEquals("Pattern for: " + method, expectedPattern, actualPattern);
LOG.info("Method: " + method + " has pattern: " + actualPattern);
}
Aggregations