You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jing Yang <jy...@gojbm.com> on 2012/03/09 19:22:46 UTC

Composed Message Processor example (Spring XML) doesn't work

By following the Composed Message Processor example (see
http://camel.apache.org/composed-message-processor.html) , 
I created my route as below:
<route>
<from uri="direct:split2"/>

<bean ref="baselineMappingService" method="genreateOrderItems"/>
	<split>
	<simple>body</simple>
	<choice>
	<when>
		<method bean="orderItemHelper" method="isWidget"/>
		<log message="body isWidget " loggingLevel="INFO"/>
	</when>
	<otherwise>
		<bean ref="myTransform" method="transform"/>
	</otherwise>
	</choice>
	</split>
</route>

The beans are listed as following:

public class BaselineMappingService {
	public List<OrderItem> genreateIteratorOrderItems(@Body String body){
		List<OrderItem> list =	new ArrayList<OrderItem>();
		if(body.contains("A")){
			OrderItem item = new OrderItem();
			item.type="widget";
			list.add(item);
			
			OrderItem item2 = new OrderItem();
			item2.type="non-widget";
			list.add(item2);
		}
		return list;
	}

public class OrderItemHelper{
	private OrderItemHelper() { }
	public boolean isWidget(@Body OrderItem orderItem) {

	System.out.println("isWidget ?" + orderItem.type.equals("widget"));

	return orderItem.type.equals("widget");
	}
}

In runtime, the org.apache.camel.component.bean.MethodNotFoundException:
Method with name: isWidget not found on bean: demo.esb.OrderItem@437bedc6
was thrown.

Do I miss something ?

-Jing

--
View this message in context: http://camel.465427.n5.nabble.com/Composed-Message-Processor-example-Spring-XML-doesn-t-work-tp5551373p5551373.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Composed Message Processor example (Spring XML) doesn't work

Posted by Jing Yang <jy...@gojbm.com>.
I modified the codes(see below)  as your suggestion. It throws different
exception as "org.apache.camel.component.bean.MethodNotFoundException:
Method with name:  isWidget  not found on bean: widget".

I don't define any bean named "widget".  This example is run under osgi and
camel 2.6.0.

<route>
  		<from uri="direct:split2"/>
  	     <bean ref="baselineMappingService" method="genreateOrderItems"/>
  		<split>
   			 <simple>body</simple>
   			<choice>
     		 <when>
        		<method  ref="orderItemHelper" method="isWidget"/>
        		<log message="body isWidget " loggingLevel="INFO"/>
        	 </when>
        	 <otherwise>
        	 	<bean  ref="myTransform" method="transform"/>
        	 </otherwise>	
        	 </choice> 
  	  </split>
  	</route>

<bean id="orderItemHelper" class="demo.esb.OrderItemHelper"/>

public   class OrderItemHelper{
	public OrderItemHelper(){}
	
	public boolean isWidget(@Body OrderItem orderItem) {
    	System.out.println("isWidget ? " + orderItem.type.equals("widget"));
    	return orderItem.type.equals("widget");
    }
}



--
View this message in context: http://camel.465427.n5.nabble.com/Composed-Message-Processor-example-Spring-XML-doesn-t-work-tp5551373p5557927.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Composed Message Processor example (Spring XML) doesn't work

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

You should make the method a static method on your OrderItemHelper,
as the constructor is private, which means its not possible to create
a bean instance of it

If you have a static method you need to declare the FQN of the bean in
the <method> as
with the beanType attribute for the FQN

 <method beanType="com.foo.OrderItemHelper" method="isWidget"/>


Alternative is to have a public default ctr of the helper, and then
declare it as a regular <bean>

<bean id="orderItemHelper" class="com.foo.OrderItemHelper"/>

And then refer to it using the ref attribute to its id:
 <method ref="orderItemHelper" method="isWidget"/>



On Fri, Mar 9, 2012 at 7:22 PM, Jing Yang <jy...@gojbm.com> wrote:
> By following the Composed Message Processor example (see
> http://camel.apache.org/composed-message-processor.html) ,
> I created my route as below:
> <route>
> <from uri="direct:split2"/>
>
> <bean ref="baselineMappingService" method="genreateOrderItems"/>
>        <split>
>        <simple>body</simple>
>        <choice>
>        <when>
>                <method bean="orderItemHelper" method="isWidget"/>
>                <log message="body isWidget " loggingLevel="INFO"/>
>        </when>
>        <otherwise>
>                <bean ref="myTransform" method="transform"/>
>        </otherwise>
>        </choice>
>        </split>
> </route>
>
> The beans are listed as following:
>
> public class BaselineMappingService {
>        public List<OrderItem> genreateIteratorOrderItems(@Body String body){
>                List<OrderItem> list =  new ArrayList<OrderItem>();
>                if(body.contains("A")){
>                        OrderItem item = new OrderItem();
>                        item.type="widget";
>                        list.add(item);
>
>                        OrderItem item2 = new OrderItem();
>                        item2.type="non-widget";
>                        list.add(item2);
>                }
>                return list;
>        }
>
> public class OrderItemHelper{
>        private OrderItemHelper() { }
>        public boolean isWidget(@Body OrderItem orderItem) {
>
>        System.out.println("isWidget ?" + orderItem.type.equals("widget"));
>
>        return orderItem.type.equals("widget");
>        }
> }
>
> In runtime, the org.apache.camel.component.bean.MethodNotFoundException:
> Method with name: isWidget not found on bean: demo.esb.OrderItem@437bedc6
> was thrown.
>
> Do I miss something ?
>
> -Jing
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Composed-Message-Processor-example-Spring-XML-doesn-t-work-tp5551373p5551373.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, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/