apacheosgiapache-camelspring-dm

camel bean method parameter conversion


I am creating a camel route, the first steps are ok but i have trouble calling the method of another osgi bundle i made. My service expect a Long value in parameter and my pojo had only this id.

My Service :

public interface FooService {
    void bar(Long id);
}

My route :

<route>
    <from uri="direct:anEntry"/>
    <bean ref="myBean" method="bar"/>
</route>

And my data format for the route :

public class MyDto implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long myId;

    public Long getMyId() {
        return myId;
    }

    public void setMyId(Long myId) {
        this.myId= myId;
    }

    @Override
    public String toString() {
        return "MyDto [myId=" + myId+ "]";
    }

}

With this code y got a NoTypeConversionAvailableException

No type converter available to convert from type: my.company.MyDto to the required type: java.lang.Long with value MyDto [myId=141564]

I can't fin the place to convert the Dto.

I tried to make my Service expect a dto with the same structure that the one of the route but I have the same mistake.

Any Idea?


Solution

  • As Christian says, or call the getMyId method on the body

    <bean ref="myBean" method="bar(${body.myId})"/>
    

    See more details at