5 Replies Latest reply on Aug 19, 2011 10:04 AM by Edward Isakov

    Using MailEndpoint bean in Java DSL to receive mail

    Edward Isakov Newbie

      I need to create MailEndpoint using configuration files from esb/etc folder (to set uri) to receive e-mail. This can be done by creating MailEndpoint as bean described in spring. But you can not use bean as the input to the route.

      If MailEndpoint uses like .to("smtp://..."), it send mail.

      Can I use MailEndpoint bean in Java DSL to receive mail?

        • 1. Re: Using MailEndpoint bean in Java DSL to receive mail
          Claus Ibsen Master

          Yeah there is method in the Java DSL to send to an endpoint by an instance:

           .to(Endpoint endpoint)
          

           

          As well as the receive

           

           from(Endpoint endpoint)
             ...
          

           

          • 2. Re: Using MailEndpoint bean in Java DSL to receive mail
            Edward Isakov Newbie

            It works good:

            spring.xml :

             

                   

                  

            In Java DSL

             

                from("direct:start")

                 .to("log:sap-maillog?level=WARN&showAll=true&multiline=true")

                 .process(new Processor() {

             

                      @Override

                      public void process(Exchange exchange) throws Exception {                              

                       

                      .......

                 })

             

            It does not work

             

             

                 from("bean:myMailEndpointIn")

                     .to("log:sap-maillog?level=WARN&showAll=true&multiline=true")

                     .process(new Processor() {

             

                                     @Override

                                     public void process(Exchange exchange) throws Exception {

             

            ....

             

            });                              

             

             

             

             

            17:46:28,603 | ERROR | myMailEndpointIn | DefaultErrorHandler              | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-15 | Failed delivery for exchangeId: ID-1-1814-4008-1313674407560-4-5172. Exhausted after delivery attempt: 1 caught: org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous method invocations possible: . Exchange[Message: ]

            org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous method invocations possible: . Exchange[Message: ]

                 at org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java:423)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:177)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:150)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:74)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.impl.ProcessorPollingConsumer.receive(ProcessorPollingConsumer.java:51)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.impl.ProcessorPollingConsumer.receiveNoWait(ProcessorPollingConsumer.java:59)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.impl.DefaultScheduledPollConsumer.poll(DefaultScheduledPollConsumer.java:48)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:97)[68:org.apache.camel.camel-core:2.6.0.fuse-01-15]

                 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_26]

                 at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_26]

                 at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_26]

                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_26]

                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_26]

                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_26]

                 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26]

                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26]

                 at java.lang.Thread.run(Thread.java:662)[:1.6.0_26]

            • 3. Re: Using MailEndpoint bean in Java DSL to receive mail
              Claus Ibsen Master

              You should not use the bean component, eg this code is wrong

              from("bean:myMailEndpointIn")
              

               

              Instead you can use the ref component to refer to the endpoint

              http://camel.apache.org/ref

               

              It should be

              from("ref:myMailEndpointIn")
              

               

              Or if you have the object instance already in java code

               

              from(myMailEndpointIn)
              

               

              Where myMailEndpointIn is an Endpoint instance.

              • 5. Re: Using MailEndpoint bean in Java DSL to receive mail
                Edward Isakov Newbie

                If I do so:

                from("myMailEndpointIn")...

                , it also works.

                 

                Edited by: isakoves on Aug 19, 2011 2:03 PM