camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hadrian Zbarcea <hzbar...@gmail.com>
Subject Re: camel-jsch in sink mode for one time copy from a remote host using SCP
Date Wed, 02 May 2012 15:54:35 GMT
The main issue is that with scp you cannot list the content of a remote 
file system. It is possible to implement a consumer that can be used in 
conjunction with a ConsumerTemplate. The protocol is a bit tricky to 
implement, but too hard. Give me one day to put some code together.

Hadrian


On 05/02/2012 11:43 AM, mohammadwrk wrote:
> Hi,
>
> According to  http://camel.apache.org/jsch.html camel-jsch : Currently
> camel-jsch only supports a Producer (i.e. copy files to another host)... It
> is possible however to use camel-jsch in sink mode for one time copy from a
> remote host using a ConsumerTemplate.
>
> Here is the code I'm using to test this functionality:
>
> camelContext = new DefaultCamelContext();
> msgConsumer = camelContext.createConsumerTemplate();
> camelContext.addRoutes(new RouteBuilder() {
> 	@Override
> 	public void configure() throws Exception {
> 		ScpConsumer scpConsumer = new ScpConsumer(msgConsumer,
> 		
> "scp://remotehost/test_scp/test.txt?username=myuser&password=mypassword&knownHostsFile=/myhome/.ssh/known_hosts");
> 		from("timer://foo?period=5000").bean(scpConsumer, "receive");
> 		
> 	}
> });
> camelContext.start();
>
>
>
> public static class ScpConsumer {
> 	
> 	private final ConsumerTemplate consumer;
> 	private final String uri;
> 	
> 	public ScpConsumer(ConsumerTemplate consumer, String uri) {
> 		this.consumer = consumer;
> 		this.uri = uri;
> 	}
>
> 	public void receive() {
> 		Object body = consumer.receiveBodyNoWait(uri);
> 		System.out.println(body);
> 	}
> }
>
> This code results in NPE (see below for stack trace). Here is the source
> code for  org.apache.camel.component.jsch.ScpEndpoint.buildConsumer
>
>      @Override
>      protected RemoteFileConsumer<ScpFile>  buildConsumer(Processor processor)
> {
>          return null; // new ScpConsumer(this, processor,
> createRemoteFileOperations());
>      }
>
> Which explains the NPE! Wondering if anybody knows how I can fix this issue?
>
> 08:14:01,664 ERROR DefaultErrorHandler:161 - Failed delivery for (MessageId:
> ID-msg-35692-1335971640877-0-1 on ExchangeId:
> ID-msg-35692-1335971640877-0-2). Exhausted after delivery attempt: 1 caught:
> org.apache.camel.FailedToCreateConsumerException: Failed to create Consumer
> for endpoint:
> Endpoint[scp://remotehost/test_scp/test.txt?knownHostsFile=/myhome/.ssh/known_hosts&password=******&username=myuser].
> Reason: java.lang.NullPointerException
> org.apache.camel.FailedToCreateConsumerException: Failed to create Consumer
> for endpoint:
> Endpoint[scp://remotehost/test_scp/test.txt?knownHostsFile=/myhome/.ssh/known_hosts&password=******&username=myuser].
> Reason: java.lang.NullPointerException
> 	at org.apache.camel.impl.ConsumerCache.getConsumer(ConsumerCache.java:81)
> 	at
> org.apache.camel.impl.ConsumerCache.receiveNoWait(ConsumerCache.java:116)
> 	at
> org.apache.camel.impl.DefaultConsumerTemplate.receiveNoWait(DefaultConsumerTemplate.java:92)
> 	at
> org.apache.camel.impl.DefaultConsumerTemplate.receiveBodyNoWait(DefaultConsumerTemplate.java:131)
> 	at
> ca.sk.gov.cjimspoc.service.camel.CamelService$ScpConsumer.receive(CamelService.java:81)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:340)
> 	at
> org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:237)
> 	at
> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:166)
> 	at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
> 	at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
> 	at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> 	at
> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:333)
> 	at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:223)
> 	at
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:304)
> 	at
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
> 	at
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
> 	at
> org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:50)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> 	at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
> 	at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
> 	at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
> 	at
> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:134)
> 	at
> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:63)
> 	at java.util.TimerThread.mainLoop(Timer.java:512)
> 	at java.util.TimerThread.run(Timer.java:462)
> Caused by: java.lang.NullPointerException
> 	at
> org.apache.camel.component.file.remote.RemoteFileEndpoint.createConsumer(RemoteFileEndpoint.java:94)
> 	at
> org.apache.camel.component.file.remote.RemoteFileEndpoint.createConsumer(RemoteFileEndpoint.java:31)
> 	at
> org.apache.camel.impl.EventDrivenPollingConsumer.doStart(EventDrivenPollingConsumer.java:140)
> 	at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
> 	at org.apache.camel.impl.ConsumerCache.getConsumer(ConsumerCache.java:79)
> 	... 41 more
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-jsch-in-sink-mode-for-one-time-copy-from-a-remote-host-using-SCP-tp5680887.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

-- 
Hadrian Zbarcea
Principal Software Architect
Talend, Inc
http://coders.talend.com/
http://camelbot.blogspot.com/

Mime
View raw message