When using ssh component to launch a remote scp command I must set the body. The ssh component is using the body as the command to be executed remotely.
What I want to achieve is this:
Monitor folder for files. The "from" is using delete=true as I don't want to keep files once route is completed.
Copy the file on the DMZ server using sftp.
Launch a scp on the DMZ server using ssh.
In case of failure, scp does return code greater than 0, rename the file with ".failed".
Unfortunately using ssh require that I overwrite the body and I'm loosing the content of my file. I tried to use inOnly, sending to another route, but it does not make a copy of the file but probably a copy of the file pointer. I can't use wireTap because by the time it complete the remote execution, the route is completed and the file removed. I cannot use (I think) a temporary variable because the file can be up to gigabyte in size.
I'm using Camel version 2.12.1 running under Karaf 2.3.2. I'm trying to use blueprint XML only to avoid java coding as much as possible. Below a sample. The result, in case of non-zero exit code from ssh component, is the file contain my remote command.
<route id="RemoteTest1">
<!-- 1. Monitor for incoming files -->
<from uri="file:///data/karaf/tmp/RemoteTest1/?delete=true"/>
<!-- 2. Copy file on DMZ server -->
<to uri="sftp:username#myDmz.com//home/RemoteTest1/?privateKeyFile=myPrivateKey.pk"/>
<!-- 3. Execute scp remotely -->
<setHeader headerName="remoteCommand">
<simple>scp /home/RemoteTest1/${file:name} someuser#acme.com:${file:name}</simple>
</setHeader>
<doTry>
<inOnly uri="direct-vm:remoteExec"/>
<log message="Success"/>
<doCatch>
<exception>java.lang.Exception</exception>
<!-- 4. In case of failure rename the file by adding .failed -->
<to uri="file:?fileName=${file:absolute.path}.failed"/>
<log message="Failed"/>
</doCatch>
</doTry>
</route>
<route id="remoteExec">
<from uri="direct-vm:remoteExec"/>
<setBody>
<simple>${header.remoteCommand}</simple>
</setBody>
<to uri="ssh://username#myDmz.com?certResource=file:resources/keys/myPrivateKey.pk"/>
<!-- Throw exception on remote error -->
<choice>
<when>
<simple>${header.CamelSshExitValue} != '0'</simple>
<throwException ref="remoteExecException"/>
</when>
<otherwise>
<log message="scp completed normally"/>
</otherwise>
</choice>
</route>
<bean id="remoteExecException" class="java.lang.Exception">
<argument value="Failed remote execution" />
</bean>
Is there a solution? Any help or tip would be appreciated.
Thanks
Related
I create a route on apache servicemix and put it in deploy. When the server started and I check the bundle:list it says that my route is in Grace Period and it's not working.
Currently I'm routing ftp to file server and do this format.
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="FTP:username#//hostname /DB?password=password"/>
<to uri="file:\\storage\folder\anotherFolder\anotherFolder\anotherFolder\"/>
</route>
</camelContext>
I did not input the exact credentials I use but that is the format that I used.
Is there any problem with my code or it's on my apache service mix? Please help I doing this for a week.
P.S. It works when its file to file server
You can install ftp using feature:install camel-ftp .
I have a mock endpoint at 8001 that will echo anything provided to it.
I have an http endpoint that will submit the end of the URL to the mock endpoint, and provide a response from the endpoint's response.
That works fine.
The challenge is, I want the http route to use only 1 tcp connection to the 8001 endpoint.
I created a worker group as explained elsewhere, and set the worker count to 1. Looking through the source code, I'm thinking this approach should work.
However, when I do this bash command:
for a in {1..5}; do curl "http://localhost:8080/upstream/REQUESTNUM$a" > $a.txt & done;
I see multiple connections to 8001. I would have expected the http endpoint requests would have to share a single pool worker, but that doesn't seem to be the case.
Perhaps I am missing something, or perhaps there is another way to accomplish my goal of using only 1 back-end tcp connection for all the http requests.
How do I accomplish it?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext
xmlns="http://camel.apache.org/schema/spring">
<route id="mockUpstream">
<from
uri="netty4:tcp://localhost:8001?sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<log message="Incoming to upstream: ${body}" />
<transform>
<simple>${body}</simple>
</transform>
</route>
<route id="httpServer">
<from
uri="netty4-http:http://0.0.0.0:8080/upstream?matchOnUriPrefix=true" />
<!-- optional just use CamelHttpQuery from header, for full query -->
<log
message="Incoming http command: ${in.headers[CamelHttpPath]}" />
<transform>
<simple>${in.headers[CamelHttpPath]}</simple>
</transform>
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<transform>
<simple>${body}</simple>
</transform>
</route>
</camelContext>
<bean id="poolBuilder"
class="org.apache.camel.component.netty4.NettyWorkerPoolBuilder">
<property name="workerCount" value="1" />
</bean>
<bean id="sharedPool" class="io.netty.channel.EventLoopGroup"
factory-bean="poolBuilder" factory-method="build"
destroy-method="shutdown">
</bean>
</beans>
Looking at the logs, with TRACE level logging, I saw the NettyProducer's pool was indeed set to use 1 max active connection, but the NettyProducer was allowed 100 idle connections. I changed the following line and it is now behaving as expected:
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true&producerPoolMaxActive=1&producerPoolMaxIdle=1" />
I assumed the "producer" settings were only good for the producer side (netty in mock host route) of the connection, but it looks like they can be used by the consumer end (netty in http route), too.
edit: I confused the terms producer and consumer and got that backwards above. Seeing that the "to" element is producing a request for something to consume, the producer* parameters make sense for (netty in http route). The (netty in mock host route) is the consumer of requests.
I am new to apache camel.
I want to create a service bus (middle ware) using apache camel by making a jetty Post request and then get the response from the server.
Here is what I've done
<route streamCache="true">
<from uri="jetty:{{wrapperEntry.protocol}}://{{wrapperEntry.host}}:{{wrapperEntry.port}}/rsb/SubmitNewCaseForAndroid?continuationTimeout=0" />
<convertBodyTo type="java.lang.String" />
<to uri="direct:helloworld"/>
</route>
<route streamCache="true">
<from uri="direct:helloworld"/>
<transform>
<simple>
Hello World
</simple>
</transform>
<convertBodyTo type="java.lang.String" />
</route>
the request goes successfully to the server and submit my case, other wise I cannot get the response back from the server.
Note: the response comes from the is the server is string it comes like this
'code':0,
'description':'operation completed succrssfully',
'complaintId':'45285'
Thank in Advacnce
I need to save file to network drive using system service for Apache tomcat and get all the time error:
Exception: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: u:\xxx.txt
My route sample:
<route id="myRoute">
<from uri="quartz:myQuartz?cron=0+0+*+?+*+MON-FRI"/>
<camel:doTry>
<bean method="getData" ref="myService"/>
<marshal ref="bindyFixedDataformat"/>
<to uri="file:u:?fileName=xxx.txt&autoCreate=false&fileExist=Append"/>
<to uri="file://c:/XXX/files?fileName=xxx-${date:now:yyyyMMdd}.txt"/>
<camel:bean method="setProcessed" ref="myService"/>
<camel:doCatch>
<exception>java.io.IOException</exception>
<camel:log message="Network drive (U:) is not available, please renew connection!" loggingLevel="ERROR"/>
<camel:bean method="setFailed" ref="myService"/>
</camel:doCatch>
<camel:doCatch>
<exception>java.lang.Exception</exception>
<camel:log message="Unexpected error has occured!" loggingLevel="ERROR" />
<camel:bean method="setFailed" ref="myService"/>
</camel:doCatch>
</camel:doTry>
</route>
'U' disk is the mapped network disk. But the same route with my second partition disk 'D' file creates successfully.
I'm generating WAR file and run it with Local System Service by Apache Tomcat.
Interesting, that before service, when I run the same project with eclipse by maven - copying to U disk was happening successfully.
The local system service user probably can't see your mapped drive 'U'. Solution: use UNC paths.
Note that the user running Tomcat will need permission to access the network path - often a local system service user won't have. In that case you can run Tomcat as a user who does have permission, i.e. by changing the user in the 'Log on' tab of the service.
i want to build simple copy from folder to folder application using camel:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true"/>
<to uri="file:src/data/new"/>
</route>
</camelContext>
I wanted to add quartz to copy file every 5 seconds.
I found something like this:
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
<property name="startDelayedSeconds" value="5"/>
</bean>
but i don't know how to use it to in my example.
Please help
You do not need to use quartz. Just change your from:
file:src/data?noop=true&consumer.delay=5000