11 Replies Latest reply on Mar 6, 2014 1:21 PM by Rob Cernich

    How to invoke a Camel Component from a Bean Component

    Jorge Morales Master

      Hi,

      I'm trying to invoke a Camel component to do some routing logic with a message that has been processed by a Bean.

      I have declared the Camel Component (extending an interface) and injected that interface into the Bean. Right now, I have one problem: The Camel Component has not been injected.

       

      @Service(VideoDownloader.class)
      public class VideoDownloaderBean implements VideoDownloader {
      
      
        @Reference("LoggingRoute") @Inject
        protected LoggingRoute route;
      
        @Override
        public DownloadDetails download(VideoDetails details)
        throws VideoDownloaderException {
        System.out.println("--------  EXECUTING SERVICE");
        System.out.println("----- PARAMS: " + details);
        DownloadDetails download = new DownloadDetails();
        if (route!=null){
           route.process(download);
        }else{
           System.out.println("------------ ROUTE IS NULL. IT HAS NOT BEEN INJECTED");
        }
      
        return download;
        }
      
      }
      

       

      After I solve this problem, and IF this problem can be solved, I have the question on "How to invoke the Camel Component?".

       

      The interface for the Camel Component is this:

      public interface LoggingRoute {
        public void process(DownloadDetails download);
      }
      

       

      And My Camel Route Builder is:

      public class LoggingRouteContextBuilder extends RouteBuilder {
      
        public void configure() {
        from("switchyard://LoggingRoute").log(
        "Received message for 'LoggingRoute' : ${body}");
        }
      
      }
      

       

      Will be ${body} the passed instance of "DownloadDetails"?

      Is there a requirement or document that defines how to invoke Camel Components, and what will be the body, the exchange, etc...?

      Should I use the Context (if yes, how)?

       

      PS: I know I can invoke the bean inside the Camel Component, and avoid all of this, but the key is learning the possibilities, not learning just one, but any.