You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by rxm0203 <ra...@yahoo.com> on 2010/11/09 00:50:47 UTC

Custom Predicates definition in Spring XML

I am using following XML snippet to declare custom predicate on my route.
However, Camel 2.4 is throwing exception. It looks like Camel is not able to
find Bean from exception message. Is it a correct syntax for custom
predicate declaration?

<bean id="filterPredicate" class="test.MockPredicate"/> <camelContext
id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from
uri="activemq:queueA"/> <filter> <method ref="filterPredicate"/> <to
uri="activemq:queueB"/> <filter> </route> </camelContext>

If it is incorrect, what is correct syntax?

Can I make route transactional with following syntax?

<bean id="filterPredicate" class="test.MockPredicate"/> <camelContext
id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from
uri="activemq:queueA"/> <transacted/><filter> <method
ref="filterPredicate"/> <to uri="activemq:queueB"/> <filter> </route>
</camelContext>

Thanks,

Ray

-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-Predicates-definition-in-Spring-XML-tp3256012p3256012.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Predicates definition in Spring XML

Posted by rxm0203 <ra...@yahoo.com>.
Hi Christian,

Thank you very much for your response. I don't see any difference in your
setup against mine except that you are using direct: component. I will try
to test my configuration again. I will get back to you early next week.

Thanks,

Ray
-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-Predicates-definition-in-Spring-XML-tp3256012p3263845.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Predicates definition in Spring XML

Posted by Christian Müller <ch...@gmail.com>.
Hello Ray!

I build a small example and it works. If you like, I can send you my example
Eclipse project.

{code:title=MyPredicate.java}
public class MyPredicate implements Predicate {

    public boolean matches(Exchange exchange) {
        return true;
    }
}
{code}

{code:title=MyBean}
public class MyBean {

    public void process(Exchange exchange) throws Exception {
        System.out.println("received exchange: " + exchange);
    }
}
{code}

{code:title=FilterSpringIntegrationTest}
public class FilterSpringIntegrationTest extends CamelSpringTestSupport {

    @EndpointInject(uri = "direct:start")
    private ProducerTemplate template;

    @Test
    public void testFilterPredicate() {
        Object response = template.requestBody("Hello Camel");
        System.out.println("received response: " + response);
    }

    @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new
ClassPathXmlApplicationContext("META-INF/spring/bundle-context.xml");
    }
}
{code}

{code:title=bundle-context.xml}
<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"
    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">

    <camel:camelContext trace="true">
        <camel:route>
            <camel:from uri="direct:start" />
            <camel:filter>
                <camel:method ref="myPredicate" />
                <camel:bean ref="myBean" method="process" />
            </camel:filter>
        </camel:route>
    </camel:camelContext>

    <bean id="myPredicate" class="org.apache.camel.cmueller.MyPredicate"/>

    <bean id="myBean" class="org.apache.camel.cmueller.MyBean"/>
</beans>
{code}

{code:title=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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.apache.camel.cmueller</groupId>
  <artifactId>filter-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
      <dependency>
          <groupId>org.apache.camel</groupId>
          <artifactId>camel-core</artifactId>
          <version>2.4.0</version>
      </dependency>
      <dependency>
          <groupId>org.apache.camel</groupId>
          <artifactId>camel-test</artifactId>
          <version>2.4.0</version>
          <scope>test</scope>
      </dependency>
  </dependencies>
</project>
{code}

Cheers,
Christian

Re: Custom Predicates definition in Spring XML

Posted by rxm0203 <ra...@yahoo.com>.
Here is my actual route definition from camel-context.xml

<bean id="filterPredicate" class="test.MockPredicate"/>
<bean id="MessageProcessor" class="com.service.MessageProcessor" />
<camelContext trace="true" xmlns="http://camel.apache.org/schema/spring">
	<route> 
		<from uri="activemq:queueA"/> 
		<filter> 
			<method ref="filterPredicate"/> 
			<bean ref="messageProcessor" method="process" />
		<filter> 
	</route> 
</camelContext> 

I am getting org.apache.camel.language.bean.RuntimeBeanExpressionException.
Here is first few lines of stack trace.

15:50:08,940 | INFO  | tenerContainer-1 | Tracer                           |
rg.apache.camel.processor.Logger   88 |
ID:BLVBLVESB-53426-1288965646629-3:83:-1:1:1 >>> (route23) transacted -->
filter[if: BeanExpression[bean: method: null]] <<< Pattern:InOnly,
Headers:{JMSReplyTo=null, JMSCorrelationID=null, JMSTimestamp=1289227372154, 
NMSXDeliveryMode=true, JMSPriority=5,  transformation=jms-byte,
JMSRedelivered=true, JMSExpiration=0, JMSType=TestLoad,
JMSDestination=queue://queueA, JMSDeliveryMode=2,
JMSMessageID=ID:BLVBLVESB-53426-1288965646629-3:83:-1:1:1,
JMSXGroupID=null}, BodyType:byte[], Body:
3
80732882éê" * 2 :T017B1753-01-01T00:00:00H5
80732882ENM141211.0000" * 21753-01-01T00:00:00
15:50:08,940 | ERROR | tenerContainer-1 | DefaultErrorHandler              |
rg.apache.camel.processor.Logger  248 | Failed delivery for exchangeId:
ID:BLVBLVESB-53426-1288965646629-3:83:-1:1:1. Exhausted after delivery
attempt: 1 caught:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
invoke method: null on  due to: org.apache.camel.NoSuchBeanException: No
bean could be found in the registry for: 
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
invoke method: null on  due to: org.apache.camel.NoSuchBeanException: No
bean could be found in the registry for: 
	at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:77)
	at
org.apache.camel.language.bean.BeanExpression.matches(BeanExpression.java:87)
	at
org.apache.camel.processor.FilterProcessor.process(FilterProcessor.java:42)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)
	at
org.apache.camel.processor.DelegateProcessor.processNext(DelegateProcessor.java:53)
	at
org.apache.camel.processor.DelegateProcessor.proceed(DelegateProcessor.java:82)

Thanks,

Ray
-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-Predicates-definition-in-Spring-XML-tp3256012p3257904.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom Predicates definition in Spring XML

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 9, 2010 at 12:50 AM, rxm0203 <ra...@yahoo.com> wrote:
>
> I am using following XML snippet to declare custom predicate on my route.
> However, Camel 2.4 is throwing exception. It looks like Camel is not able to
> find Bean from exception message. Is it a correct syntax for custom
> predicate declaration?
>
> <bean id="filterPredicate" class="test.MockPredicate"/> <camelContext
> id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from
> uri="activemq:queueA"/> <filter> <method ref="filterPredicate"/> <to
> uri="activemq:queueB"/> <filter> </route> </camelContext>
>
> If it is incorrect, what is correct syntax?
>

Looks like it yeah. What exception do you get?


> Can I make route transactional with following syntax?
>
> <bean id="filterPredicate" class="test.MockPredicate"/> <camelContext
> id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from
> uri="activemq:queueA"/> <transacted/><filter> <method
> ref="filterPredicate"/> <to uri="activemq:queueB"/> <filter> </route>
> </camelContext>
>

Yes just add <transacted/> to the route. And also since you use
JMS/ActiveMQ you need to enable transacted=true on the JMS connection
factory.

There is a free excerpt of the Camel book chapter 9 here, which covers
transactions with Camel
http://fusesource.com/fuse/apache-books/


> Thanks,
>
> Ray
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Custom-Predicates-definition-in-Spring-XML-tp3256012p3256012.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/