use of org.apache.camel.Producer in project camel by apache.
the class ToFtpTempFileTargetFileExistTest method prepareFtpServer.
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(Exchange.FILE_NAME, "foo/bar/message.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
// assert file is created
File file = new File(FTP_ROOT_DIR + "/tempfile/foo/bar/message.txt");
assertTrue("The file should exists", file.exists());
}
use of org.apache.camel.Producer in project camel by apache.
the class PojoProxyHelper method createProxy.
@SuppressWarnings("unchecked")
public static <T> T createProxy(Endpoint endpoint, Class<?>... interfaceClasses) throws Exception {
Producer producer = endpoint.createProducer();
// ensure the producer is started
ServiceHelper.startService(producer);
return (T) Proxy.newProxyInstance(ProxyHelper.getClassLoader(interfaceClasses), interfaceClasses.clone(), new PojoMessageInvocationHandler(endpoint, producer));
}
use of org.apache.camel.Producer in project camel by apache.
the class AsyncProducerTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
context.addComponent("async", new MyAsyncComponent());
Producer myAsyncProducer = context.getEndpoint("async:bye:camel").createProducer();
from("direct:start").to("mock:before").process(new Processor() {
public void process(Exchange exchange) throws Exception {
beforeThreadName = Thread.currentThread().getName();
}
}).process(myAsyncProducer).process(new Processor() {
public void process(Exchange exchange) throws Exception {
afterThreadName = Thread.currentThread().getName();
}
}).to("mock:after").to("mock:result");
}
};
}
use of org.apache.camel.Producer in project camel by apache.
the class FtpThrowExceptionOnConnectionFailedTest method uploadFile.
private void uploadFile(String username, String password) throws Exception {
Endpoint endpoint = context.getEndpoint("ftp://" + username + "@localhost:" + getPort() + "/login?password=" + password + "&maximumReconnectAttempts=0&throwExceptionOnConnectFailed=true");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World from FTPServer");
exchange.getIn().setHeader(Exchange.FILE_NAME, "report.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
use of org.apache.camel.Producer 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