Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-4517

got cast exception when using endChoice() in Java DSL

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 2.8.1
    • 2.9.0
    • camel-core
    • None
    • Windows XP, JDK 1.6, Eclipse IDE

    • Unknown

    Description

      I am trying CBR pattern and using 'choice', 'when', 'to' and 'endChoice()'.
      I can actually have the code compile, but always got cast exception when running it.

      this really confused me, because I checked every steps and can't find any problems.
      does anyone have similar situation?

      here is my Camel route in JDSL:
      =========================================================================
      18 CamelContext context = new DefaultCamelContext();
      19 ConnectionFactory connectionFacotyr = new ActiveMQConnectionFactory("tcp://P10118178-T400:61616");
      20 context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFacotyr));
      21
      22 context.addRoutes(new RouteBuilder() {
      23 public void configure() throws Exception

      { 24 from("jms:incomingOrders") 25 .choice() 26 .when(header("CamelFileName").endsWith(".crt")) 27 .to("jms:crtQueue").endChoice() 28 .when(header("CamelFileName").endsWith(".zpx")) 29 .to("jms:zpxQueue"); 30 }

      31 });
      =========================================================================

      pretty simple route. but always got an 'java.lang.ClassCastException' when I start the Camel route.
      the exception message as below: (the exception occurred at line 27)
      =========================================================================
      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:1203)
      at SimpleTest$1.configure(SimpleTest.java:27)
      at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
      at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:277)
      at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:263)
      at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:603)
      at SimpleTest.main(SimpleTest.java:22)
      =========================================================================

      Maven pom.xml:
      =========================================================================
      <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>
      <groupId>com.pic.newigx.sample</groupId>
      <artifactId>rider.auto.parts.sample1.eip.filter1</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
      <plugins>
      <plugin>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-maven-plugin</artifactId>
      <version>2.8.0</version>
      </plugin>
      </plugins>
      </build>
      <dependencies>
      <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jms</artifactId>
      <version>2.8.1</version>
      </dependency>
      <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring</artifactId>
      <version>2.8.1</version>
      </dependency>
      <dependency>
      <groupId>org.apache.activemq</groupId>
      <artifactId>activemq-core</artifactId>
      <version>5.3.1</version>
      </dependency>
      </dependencies>
      </project>
      =========================================================================

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            choufeng.tw Timothy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: