8 Replies Latest reply on Oct 15, 2013 9:11 AM by Ruan van Biljon

    Switchyard - Configure for multiple E-Mail boxes

    Ruan van Biljon Newbie

      Hi

       

      In short:

      I have a DB table that carries a list of mailboxes (with username/passwords). I am trying to configure switchyard to pull emails dynamically from exchange based on data in this table.

      My plan is to "parameterise" the mailbox/username/password and then change properties as required. I am still stuck at parameterising the details in the switchyard.xml file.

       

      This is what I currently have:

      <sca:service name="PrintService" promote="PrintServiceBean/PrintService">

            <sca:interface.java interface="org.switchyard.quickstarts.camel.mail.binding.PrintService"/>

            <mail:binding.mail>

              <mail:contextMapper/>

              <mail:messageComposer class="org.switchyard.quickstarts.camel.mail.binding.MyComposer"/>

              <mail:host>localhost</mail:host>

              <mail:port>110</mail:port>

              <mail:username>{{USER}}</mail:username>

              <mail:password>{{PASS}}</mail:password>

              <mail:consume accountType="pop3">

                <mail:delay>10000</mail:delay>

                <mail:delete>true</mail:delete>

              </mail:consume>

            </mail:binding.mail>

          </sca:service>

       

      and then later on in the file I have

          <sca:property value="testuser" name="USER"/>

          <sca:property value="testpassword" name="PASS"/>

       

      When I run this I get the following error:

      Consumer Consumer[pop3://localhost:110?delay=10000&delete=true&password=******&username=%7B%7BUSER%7D%7D] could not poll endpoint: Endpoint[pop3://localhost:110?delay=10000&delete=true&password=******&username=%7B%7BUSER%7D%7D] caused by: Authentication failed.: javax.mail.AuthenticationFailedException: Authentication failed.

      at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208) [mail-1.4.5-redhat-1.jar:1.4.5-redhat-1]

        at javax.mail.Service.connect(Service.java:317) [mail-1.4.5-redhat-1.jar:1.4.5-redhat-1]

        at org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:376) [camel-mail-2.10.0.jar:2.10.0]

        at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:82) [camel-mail-2.10.0.jar:2.10.0]

        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139) [camel-core-2.10.0.jar:2.10.0]

       

      I have tried a couple of other property-escaping methods described in the documentation, but the only one that works is the ${USER}, but that substitutes the property when loading so changing the property value afterwards, wouldn't work since the URI was passed to Camel-Mail as : pop3://localhost:110?delay=10000&delete=true&password=******&username=testuser

       

      Now:

      -Is this the suggested method, or do you have a better solution?

      -What am I missing with regards to the properties that was explained above?

       

      Thanks in advance

       

      Ruan

        • 1. Re: Switchyard - Configure for multiple E-Mail boxes
          David Ward Master

          ${USER} will use switchyard/jboss property replacement, looking for the value of the USER property.  If you want switchyard/jboss to stay out of it, and leave the property alone, use a double-dollar value: $${USER}

          • 2. Re: Switchyard - Configure for multiple E-Mail boxes
            Ruan van Biljon Newbie

            Hi David

             

            Yes, that is how I understood it, and your answer is consistent with the documentation, but I am still struggling.

             

            When I use the double-dollar value like this:

            <mail:username>$${USER}</mail:username>

             

            The problem that I receive:

            21:59:26,325 DEBUG [org.apache.camel.component.mail.MailConsumer] (Camel (camel-2) thread #2 - pop3://localhost:110) Connecting to MailStore: pop3://localhost:110, folder=INBOX

            21:59:26,336 WARN  [org.apache.camel.impl.DefaultPollingConsumerPollStrategy] (Camel (camel-2) thread #2 - pop3://localhost:110) Consumer Consumer[pop3://localhost:110?delay=10000&delete=true&password=******&username=%24%7BUSER%7D] could not poll endpoint: Endpoint[pop3://localhost:110?delay=10000&delete=true&password=******&username=%24%7BUSER%7D] caused by: Authentication failed.: javax.mail.AuthenticationFailedException: Authentication failed.

              at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208) [mail-1.4.5-redhat-1.jar:1.4.5-redhat-1]

              at javax.mail.Service.connect(Service.java:317) [mail-1.4.5-redhat-1.jar:1.4.5-redhat-1]

              at org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:376) [camel-mail-2.10.0.jar:2.10.0]

              at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:82) [camel-mail-2.10.0.jar:2.10.0]

              at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139) [camel-core-2.10.0.jar:2.10.0]

              at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:91) [camel-core-2.10.0.jar:2.10.0]

              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_21]

              at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) [rt.jar:1.7.0_21]

              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) [rt.jar:1.7.0_21]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [rt.jar:1.7.0_21]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [rt.jar:1.7.0_21]

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_21]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]

              at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]

             

            Sorry if this is a noob question...

            • 3. Re: Switchyard - Configure for multiple E-Mail boxes
              David Ward Master

              Hmmm... Well at this point I'm wondering what version of SwitchYard runtime you're using.  When you startup the server, it should say something like:

               

              16:15:17,768 INFO  [org.switchyard] (ServerService Thread Pool -- 16) SwitchYard version 1.1.0-SNAPSHOT

               

              (or whatever version you actually have).  It looks like the work for SWITCHYARD-1409 was actually done in SWITCHYARD-1486 (by me), in time for 1.0.0.Final...

              • 4. Re: Switchyard - Configure for multiple E-Mail boxes
                Ruan van Biljon Newbie

                Hi David

                 

                My Version of switchyard:

                21:46:04,704 INFO  [org.switchyard] (ServerService Thread Pool -- 23) SwitchYard version 1.0.0.Final

                 

                with Jboss:

                07:17:31,823 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015899: JBoss EAP 6.1.0.GA (AS 7.2.0.Final-redhat-8) starting

                • 5. Re: Re: Switchyard - Configure for multiple E-Mail boxes
                  Keith Babo Master

                  Let's return back to your original requirement/question for a sec.  Your config shows a service binding, so you are polling a mailbox via POP3.  You want to change the user/pass used to login via properties.  The value of these properties will change between deployments of the application and you want to update them without having to change switchyard.xml and repackage the application.

                   

                  To accomplish the above, you will want to use the native property support in SwitchYard which is ${PropName}.  The values of these properties can be specified statically (as you've discovered) via sca:property definitions within the app.  Another way to configure the property value is through system properties (java -D or configuration in standalone.xml).  That would allow you to change the value for the login on a per instance basis by changing the value of the system property used.  Keep in mind that these properties are effectively resolved at deployment time, which is when the component will pull the configuration in switchyard.xml and all property tokens are resolved.  This means that if you change the value of a property at runtime, this change will not be picked up by the component unless you restart (stop/start) the binding for the service.

                   

                  hth,

                  keith

                  • 6. Re: Switchyard - Configure for multiple E-Mail boxes
                    Ruan van Biljon Newbie

                    Hi Keith

                     

                    I might have not explained it clearly enough.

                     

                    My original "requirement".

                     

                    I need to be able to poll from a dynamically configured list of mailboxes.

                    Assume list is

                    support@company.com

                    info@company.com

                     

                    Switchyard polls the mailboxes, one after the other.

                     

                    While this is running, the user adds a new email address

                     

                    customercare@company.com

                     

                    the next iteration on the poller, the 3rd mailbox is polled as well.

                     

                    I thought using properties and setting them to different values will work, but I must admit, this doesn't seem very eligant, so any feedback would be much appreciated.

                     

                    nojlib

                    • 7. Re: Switchyard - Configure for multiple E-Mail boxes
                      Keith Babo Master

                      I don't believe that Camel supports polling multiple accounts from a single consumer entry, so you're not going to get this functionality out of the box.  You can poll multiple accounts by adding additional bindings to the service, but the requirement for a user to be able to come in at runtime and add an additional account is not supported. 

                       

                      One option which is a bit low-level would be to have a quartz binding which triggered a CDI Bean service.  The bean service could perform a lookup of accounts to poll in a file or db (via JPA), then loop through them using JavaMail APIs to grab messages.  The bean service would then invoke the target service using an @Reference.  In this scenario, you are essentially implementing a custom binding using a CDI bean.

                       

                      Speaking of custom code, you could always extend the Camel mail component to support this directly and then integrate that with SwitchYard as a Camel extension components.  A bit more advanced, but that would allow you to reuse all the plumbing already present in the Camel component.  The bit you would add would be the lookup of the account details from an external source and then iterating over each one.

                      1 of 1 people found this helpful