2

Within a route defined in camel context I would like to access a method of an abstract class that is contained in a 3rd party library I am using.

 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:osgi="http://www.springframework.org/schema/osgi"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> 


 <bean id="objectFactory" class="org.example.Factory" abstract="true"/>

 <camelContext xmlns="http://camel.apache.org/schema/spring">
     <route>
         ...
       <marshal>
          <rss/>
   </marshal>
   <marshal>
      <string/>
   </marshal>
       <to uri="jms:feeds"/>
       <to uri="file:/tmp/output"/>
       <!-- That is the point in the route where I would like to pass the URL of 
            the folder the files have been written to a static method of an abstract
            class in order to instantiate an object
       -->
     </route>
      ...

The above snippet shows the route definition in Spring DSL and the definition of the abstract bean. I have tried using the <bean> tag to achieve what I want, but this always ends with a org.springframework.beans.factory.BeanIsAbstractException. Is there no way to just simply access a static method of an abstract class within a camelcontext?

kapa
  • 77,694
  • 21
  • 158
  • 175

2 Answers2

1

If the method is a static method, you can possible refer to it in the Camel DSL directly

<bean type="org.example.Factory" method="myMethod"/>

Mind that this requires a fairly recent version of Camel where we added support for invoking static methods directly.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Thanks for the very quick answer. I tried that by using the Camel Spring-DM archetype: ` ` . This gives me a `org.xml.sax.SAXParseException`: `cvc-complex-type.3.2.2: Attribute 'type' is not allowed to appear in element 'bean'.` Did i misunderstand the way it is supposed to be used? – user1281204 Mar 20 '12 at 17:26
  • Yes inside you have the Camel namespace, and there is also a tag to call a bean, from a route. – Claus Ibsen Mar 21 '12 at 08:01
1

I think the easiest way to use an abstract class is to define your own class that extends the abstract class and then call this. You can then use the normal bean syntax like Claus mentioned. In this case non static methods will also work.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64