use of org.apache.camel.ExchangePattern in project camel by apache.
the class CamelOutputStream method commitOutputMessage.
private void commitOutputMessage() throws IOException {
ExchangePattern pattern;
if (isOneWay) {
pattern = ExchangePattern.InOnly;
} else {
pattern = ExchangePattern.InOut;
}
LOG.debug("send the message to endpoint {}", this.targetCamelEndpointUri);
final org.apache.camel.Exchange exchange = this.producer.createExchange(pattern);
exchange.setProperty(Exchange.TO_ENDPOINT, this.targetCamelEndpointUri);
CachedOutputStream outputStream = (CachedOutputStream) outMessage.getContent(OutputStream.class);
// Send out the request message here, copy the protocolHeader back
CxfHeaderHelper.propagateCxfToCamel(this.headerFilterStrategy, outMessage, exchange.getIn(), exchange);
// TODO support different encoding
exchange.getIn().setBody(outputStream.getInputStream());
LOG.debug("template sending request: ", exchange.getIn());
if (outMessage.getExchange().isSynchronous()) {
syncInvoke(exchange);
} else {
// submit the request to the work queue
asyncInvokeFromWorkQueue(exchange);
}
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class SetExchangePatternTest method assertMessageReceivedWithPattern.
protected void assertMessageReceivedWithPattern(String sendUri, ExchangePattern expectedPattern) throws InterruptedException {
ExchangePattern sendPattern;
switch(expectedPattern) {
case InOut:
sendPattern = ExchangePattern.InOnly;
break;
case InOnly:
case RobustInOnly:
sendPattern = ExchangePattern.InOut;
break;
default:
sendPattern = ExchangePattern.InOnly;
}
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
String expectedBody = "InOnlyMessage";
resultEndpoint.expectedBodiesReceived(expectedBody);
resultEndpoint.expectedHeaderReceived("foo", "bar");
template.sendBodyAndHeader(sendUri, sendPattern, expectedBody, "foo", "bar");
resultEndpoint.assertIsSatisfied();
ExchangePattern actualPattern = resultEndpoint.getExchanges().get(0).getPattern();
assertEquals("received exchange pattern", actualPattern, expectedPattern);
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class CamelInvocationHandler method doInvokeProxy.
@Override
public Object doInvokeProxy(Object proxy, Method method, Object[] args) throws Throwable {
MethodInfo methodInfo = methodInfoCache.getMethodInfo(method);
final ExchangePattern pattern = methodInfo != null ? methodInfo.getPattern() : ExchangePattern.InOut;
return invokeProxy(method, pattern, args, binding);
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class PojoMessageInvocationHandler method doInvokeProxy.
@Override
public Object doInvokeProxy(Object proxy, Method method, Object[] args) throws Throwable {
int argsLength = (args == null) ? 0 : args.length;
if (argsLength != 1) {
throw new RuntimeCamelException(String.format("Error creating proxy for %s.%s Number of arguments must be 1 but is %d", method.getDeclaringClass().getName(), method.getName(), argsLength));
}
final ExchangePattern pattern = method.getReturnType() != Void.TYPE ? ExchangePattern.InOut : ExchangePattern.InOnly;
return invokeWithBody(method, args[0], pattern);
}
use of org.apache.camel.ExchangePattern in project camel by apache.
the class SendDynamicProcessor method process.
public boolean process(Exchange exchange, final AsyncCallback callback) {
if (!isStarted()) {
exchange.setException(new IllegalStateException("SendProcessor has not been started: " + this));
callback.done(true);
return true;
}
// we should preserve existing MEP so remember old MEP
// if you want to permanently to change the MEP then use .setExchangePattern in the DSL
final ExchangePattern existingPattern = exchange.getPattern();
// which endpoint to send to
final Endpoint endpoint;
final ExchangePattern destinationExchangePattern;
// use dynamic endpoint so calculate the endpoint to use
Object recipient = null;
try {
recipient = expression.evaluate(exchange, Object.class);
endpoint = resolveEndpoint(exchange, recipient);
destinationExchangePattern = EndpointHelper.resolveExchangePatternFromUrl(endpoint.getEndpointUri());
} catch (Throwable e) {
if (isIgnoreInvalidEndpoint()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Endpoint uri is invalid: " + recipient + ". This exception will be ignored.", e);
}
} else {
exchange.setException(e);
}
callback.done(true);
return true;
}
// send the exchange to the destination using the producer cache
return producerCache.doInAsyncProducer(endpoint, exchange, pattern, callback, new AsyncProducerCallback() {
public boolean doInAsyncProducer(Producer producer, AsyncProcessor asyncProducer, final Exchange exchange, ExchangePattern pattern, final AsyncCallback callback) {
final Exchange target = configureExchange(exchange, pattern, destinationExchangePattern, endpoint);
LOG.debug(">>>> {} {}", endpoint, exchange);
return asyncProducer.process(target, new AsyncCallback() {
public void done(boolean doneSync) {
// restore previous MEP
target.setPattern(existingPattern);
// signal we are done
callback.done(doneSync);
}
});
}
});
}
Aggregations