3
votes

I am trying to create component which move files from one location to another location using Camel Spring.

Its working fine for FTP, but it given error when trying with SFTP.

Error is (SFTP URI : sftp://IP Address:Port/CamelTesting?username=testftp&password=testftp): Loading XML bean definitions from class path resource [testApplicationContext.xml] Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 25 in XML document from class path resource [processorApplicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 25; columnNumber: 76; The reference to entity "password" must end with the ';' delimiter.

Error is (SFTP URI (&amp): sftp://IP Address:Port/CamelTesting?username=testftp&password=testftp): Exception in thread "main" org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[sftp://IP Address:Port/CamelTesting?username=testftp&password=testftp] <<< in route: Route(route1)[[From[file:D:/Test/in]] -> [To[sftp:/IP Address:Port... because of Failed to resolve endpoint: sftp://IP Address:Port/CamelTesting?password=testftp&username=testftp due to: No component found with scheme: sftp

Dependencies are :

<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.15.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>2.15.1</version>
    </dependency>
</dependencies>

testApplicationContext.xml :

<?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">
    <!--FTP Working fine--> 
    <!--route>
        <from uri="file:D:/Test/in" />                          
        <to uri="file:D:/Test/out" />
    </route-->

     <!--SFTP--> 
     <route>
        <from uri="file:D:/Test/in" />          
        <to uri="sftp://<IP Address:Port>/CamelTesting?username=testftp&password=testftp"/>
    </route> 
</camelContext>

Test Class :

import org.apache.camel.CamelContext;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class testSFTP {
public static final void main(String[] args) throws Exception {
    ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext("testApplicationContext.xml");
    CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);
    try {
        camelContext.start();
        Thread.sleep(3000);
    }catch(Exception e){
        e.printStackTrace();
    }
    finally {
        camelContext.stop();
        appContext.close();
    }
    }
}

can someone help me for resolve the issue.

1

1 Answers

7
votes

in xml use &amp; as &

<route>
    <from uri="file:D:/Test/in" />          
    <to uri="sftp://<IP Address:Port>/CamelTesting?username=testftp&amp;password=testftp"/>
</route> 

for secord Error:

You need to add camel-ftp to your classpath. just add it as dependency to the pom.xml.

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-ftp</artifactId>
        <version>2.15.1</version>
    </dependency>

hope this helps.