Apache Camel failed to create endpoint

10,168

You need to add camel-ftp to your classpath. If you use Maven then its easy as just add it as dependency to the pom.xml

Share:
10,168
Luca89
Author by

Luca89

Updated on June 04, 2022

Comments

  • Luca89
    Luca89 almost 2 years

    I'm new on Apache Camel and I need to integrate it with Apache ActiveMQ.

    I tried a basic example, I installed on my computer FileZilla Server and ActiveMQ (works both) and I want to copy a file from the local server to the JMS queue that I created in Active MQ; the problem is that the method start() of CamelContext throws org.apache.camel.FailedToCreateRouteException

    Here is my code (the address in ftpLocation is the static address of my computer):

    import javax.jms.ConnectionFactory;
    
    import org.apache.activemq.ActiveMQConnection;
    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.apache.camel.CamelContext;
    import org.apache.camel.Exchange;
    import org.apache.camel.Processor;
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.component.jms.JmsComponent;
    import org.apache.camel.impl.DefaultCamelContext;
    
    public class FtpToJmsExample
    {
    
        private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
        private static String ftpLocation = "ftp://192.168.1.10/incoming?username=Luca&password=Luca";
    
        public void start() throws Exception
        {
            CamelContext context = new DefaultCamelContext();
            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
            context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
    
            context.addRoutes( 
                    new RouteBuilder() {
                        public void configure() 
                        {
                            from(ftpLocation).
                            process(executeFirstProcessor()).
                            to("jms:TESTQUEUE");             
                        }
                    });
    
            System.out.println("START");
            context.start();
    
            System.out.println("wait");
            System.out.println(loaded);
    
            Thread.sleep(3000);
    
            while (loaded == false) 
            { 
                System.out.println("in attesa\n");
            }
    
            context.stop();
    
            System.out.println("stop context!");
            System.out.println(loaded);
        }
    
        public static void main(String args[]) throws Exception
        {
            FtpToJmsExample example = new FtpToJmsExample();
            example.start();
        }
    
        private Processor executeFirstProcessor() 
        {
            return new Processor() {
                @Override
                public void process(Exchange exchange) 
                {
                    System.out.println("We just downloaded : "+ 
                            exchange.getIn().getHeader("CamelFileName"));
                    loaded = true;
                }
            };
        }
    }
    

    This is the POM.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.apache.camel</groupId>
            <artifactId>examples</artifactId>
            <version>2.11.0</version>
        </parent>
        <artifactId>camel-example-jms-file</artifactId>
        <name>Camel :: Example :: JMS-File</name>
        <description>An example that persists messages from FTP site to JMS</description>
    
        <dependencies>
    
            <!-- Camel dependencies -->
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-jms</artifactId>
            </dependency>
    
            <!-- ActiveMQ dependencies -->
            <dependency>
                <groupId>org.apache.activemq</groupId>
                <artifactId>activemq-broker</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.activemq</groupId>
                <artifactId>activemq-client</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.activemq</groupId>
                <artifactId>activemq-camel</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.xbean</groupId>
                <artifactId>xbean-spring</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <profiles>
            <profile>
                <id>Example</id>
                <properties>
                    <target.main.class>com.ftpToJms.FtpToJMSExample</target.main.class>
                </properties>
            </profile>
        </profiles>
    </project>
    

    And this is the report of the error

    Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[ftp://192.168.1.10/incoming?username=Luc... because of Failed to resolve endpoint: ftp://192.168.1.10/incoming?password=Luca&username=Luca due to: No component found with scheme: ftp
        at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:181)
        at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:750)
        at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1829)
        at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1609)
        at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1478)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1446)
        at ftptojms.FtpToJmsExample.start(FtpToJmsExample.java:51)
        at ftptojms.FtpToJmsExample.main(FtpToJmsExample.java:73)
    Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: ftp://192.168.1.10/incoming?password=Luca&username=Luca due to: No component found with scheme: ftp
        at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:514)
        at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:62)
        at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:191)
        at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)
        at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)
        at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72)
        at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:90)
        at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:861)
        at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176)
        ... 8 more
    

    Someone can help me?

    Sorry for the long post and the not-perfect english.

  • Luca89
    Luca89 over 9 years
    Thank you, i added the dependency of camel-ftp, now the error is changed: java.lang.NoSuchMethodError: org.apache.camel.component.file.remote.FtpComponent.setEndpo‌​intClass(Ljava/lang/‌​Class;). I will try to resolve this new error before of ask a new question Thank you very much
  • Claus Ibsen
    Claus Ibsen over 9 years
    Make sure you use the same version of Camel
  • Luca89
    Luca89 over 9 years
    It works! I forgot the Maven Update Thank you very much for the help