You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Florian B." <fl...@isar-software.com> on 2012/11/22 20:17:44 UTC

CastException error when using choice in a route

Hi I'm trying to setup some routes to handle an import from different csv
files to a database. First I defined a single route for each file but I
thought it should be easier and be more flexible when I try to split
everything up to have some routes which can be used for different files. 

Here are the routes I defined till now. That are not all routes. At the
moment I just setup up two routes to see how it works. 

CsvDataFormat csv = new CsvDataFormat();
csv.setDelimiter(";");
        
from("file://data?doneFileName=${file:name}.done").noAutoStartup()
    .choice()
       
.when(header("CamelFileNameOnly").isEqualTo("import_organization.csv")) 
            .to("direct:csv_organization_in")
        .when(header("CamelFileNameOnly").isEqualTo("import_user.csv")) 
            .to("direct:csv_user_in")
   .endChoice().setId("route_pickup_file");
        
from("direct:csv_organization_in").noAutoStartup().unmarshal(csv)
    .bean(msdOrganizationConverter, "convert")
.to(YsuraImportRouteBuilder.ENDPOINT_DIRECT_IMPORT_YSURA_OBJECTS_IN_DB).setId("route_import_organization");


When I start up the routes I got following exception:

java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
be cast to org.apache.camel.model.ChoiceDefinition
	at
org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1237)
~[camel-core-2.10.2.jar:2.10.2]
	at
com.isarsoftware.ysura.model.integration.msd.MsdImportRouteBuilder.configure(MsdImportRouteBuilder.java:50)
~[ysura-integration-0.0.1.jar:na]
....

I've also tried to append a .end() to each of the choices, but then I got an
error on the second when(): The method when(Predicate) is undefined for the
type ProcessorDefinition<capture#1-of ?
 >

Any ideas what I'm doing wrong? 

Best Regards,
Florian 



--
View this message in context: http://camel.465427.n5.nabble.com/CastException-error-when-using-choice-in-a-route-tp5723125.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CastException error when using choice in a route

Posted by "Florian B." <fl...@isar-software.com>.
Hi 

sorry for responding so late. I've added an route id to the route as you
mentioned in your last answer, but I'm still getting the ClassCastException. 

Any other ideas? 



--
View this message in context: http://camel.465427.n5.nabble.com/CastException-error-when-using-choice-in-a-route-tp5723125p5723609.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CastException error when using choice in a route

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Nov 22, 2012 at 8:17 PM, Florian B.
<fl...@isar-software.com> wrote:
> Hi I'm trying to setup some routes to handle an import from different csv
> files to a database. First I defined a single route for each file but I
> thought it should be easier and be more flexible when I try to split
> everything up to have some routes which can be used for different files.
>
> Here are the routes I defined till now. That are not all routes. At the
> moment I just setup up two routes to see how it works.
>
> CsvDataFormat csv = new CsvDataFormat();
> csv.setDelimiter(";");
>
> from("file://data?doneFileName=${file:name}.done").noAutoStartup()
>     .choice()
>
> .when(header("CamelFileNameOnly").isEqualTo("import_organization.csv"))
>             .to("direct:csv_organization_in")
>         .when(header("CamelFileNameOnly").isEqualTo("import_user.csv"))
>             .to("direct:csv_user_in")
>    .endChoice().setId("route_pickup_file");
>

Try with using .routeId to set id of the route.

 from("file://data?doneFileName=${file:name}.done").noAutoStartup().routeId("route_pickup_file")
     .choice()
 .when(header("CamelFileNameOnly").isEqualTo("import_organization.csv"))
             .to("direct:csv_organization_in")
         .when(header("CamelFileNameOnly").isEqualTo("import_user.csv"))
             .to("direct:csv_user_in");


> from("direct:csv_organization_in").noAutoStartup().unmarshal(csv)
>     .bean(msdOrganizationConverter, "convert")
> .to(YsuraImportRouteBuilder.ENDPOINT_DIRECT_IMPORT_YSURA_OBJECTS_IN_DB).setId("route_import_organization");
>
>
> When I start up the routes I got following exception:
>
> java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
> be cast to org.apache.camel.model.ChoiceDefinition
>         at
> org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1237)
> ~[camel-core-2.10.2.jar:2.10.2]
>         at
> com.isarsoftware.ysura.model.integration.msd.MsdImportRouteBuilder.configure(MsdImportRouteBuilder.java:50)
> ~[ysura-integration-0.0.1.jar:na]
> ....
>
> I've also tried to append a .end() to each of the choices, but then I got an
> error on the second when(): The method when(Predicate) is undefined for the
> type ProcessorDefinition<capture#1-of ?
>  >
>
> Any ideas what I'm doing wrong?
>
> Best Regards,
> Florian
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CastException-error-when-using-choice-in-a-route-tp5723125.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: CastException error when using choice in a route

Posted by "Florian B." <fl...@isar-software.com>.
Hi 

I've read the FAQ page you mentioned and changed my route configuration
accordantly to the following.

from("file://data?doneFileName=${file:name}.done").noAutoStartup()
        .choice()
         
.when(header("CamelFileNameOnly").isEqualTo("import_organization.csv")) 
              .to("direct:csv_organization_in").endChoice()
          .when(header("CamelFileNameOnly").isEqualTo("import_user.csv")) 
                   .to("direct:csv_user_in").endChoice()
          .otherwise().to("direct:dump");


But I still get the same ClassCastException:
java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
be cast to org.apache.camel.model.ChoiceDefinition
	at
org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1237)
~[camel-core-2.10.2.jar:2.10.2]
	at
com.isarsoftware.ysura.model.integration.msd.MsdImportRouteBuilder.configure(MsdImportRouteBuilder.java:50)
~[ysura-integration-0.0.1.jar:na]
	at
com.isarsoftware.ysura.integration.route.YsuraRouteBuilder.configure(YsuraRouteBuilder.java:22)
~[ysura-integration-0.0.1.jar:na]

Do you have any other ideas what might the problem here. 



--
View this message in context: http://camel.465427.n5.nabble.com/CastException-error-when-using-choice-in-a-route-tp5723125p5723150.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CastException error when using choice in a route

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See this FAQ
http://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html

On Thu, Nov 22, 2012 at 8:17 PM, Florian B.
<fl...@isar-software.com> wrote:
> Hi I'm trying to setup some routes to handle an import from different csv
> files to a database. First I defined a single route for each file but I
> thought it should be easier and be more flexible when I try to split
> everything up to have some routes which can be used for different files.
>
> Here are the routes I defined till now. That are not all routes. At the
> moment I just setup up two routes to see how it works.
>
> CsvDataFormat csv = new CsvDataFormat();
> csv.setDelimiter(";");
>
> from("file://data?doneFileName=${file:name}.done").noAutoStartup()
>     .choice()
>
> .when(header("CamelFileNameOnly").isEqualTo("import_organization.csv"))
>             .to("direct:csv_organization_in")
>         .when(header("CamelFileNameOnly").isEqualTo("import_user.csv"))
>             .to("direct:csv_user_in")
>    .endChoice().setId("route_pickup_file");
>
> from("direct:csv_organization_in").noAutoStartup().unmarshal(csv)
>     .bean(msdOrganizationConverter, "convert")
> .to(YsuraImportRouteBuilder.ENDPOINT_DIRECT_IMPORT_YSURA_OBJECTS_IN_DB).setId("route_import_organization");
>
>
> When I start up the routes I got following exception:
>
> java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot
> be cast to org.apache.camel.model.ChoiceDefinition
>         at
> org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1237)
> ~[camel-core-2.10.2.jar:2.10.2]
>         at
> com.isarsoftware.ysura.model.integration.msd.MsdImportRouteBuilder.configure(MsdImportRouteBuilder.java:50)
> ~[ysura-integration-0.0.1.jar:na]
> ....
>
> I've also tried to append a .end() to each of the choices, but then I got an
> error on the second when(): The method when(Predicate) is undefined for the
> type ProcessorDefinition<capture#1-of ?
>  >
>
> Any ideas what I'm doing wrong?
>
> Best Regards,
> Florian
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CastException-error-when-using-choice-in-a-route-tp5723125.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen