3 Replies Latest reply on Aug 6, 2010 9:54 AM by mwohlf

    How to handle SMTP failures in a mail activity

    jeffgreg

      Hi,

         I'm integrating jBPM 4.4 into an existing Spring application (2.5.6) and believe I have everything running (transactions, persistence, jobexecutor, etc) without any obvious failures.  I'm slowly building a process that is supposed to send out an email, wait for user responses, etc.  This means using the built-in mail activity to send out the email.  Since the code starting the process isn't mean't to perform the entire process the mail activity is setup continue='async' (hopefully) allowing the jobexecutor to handle the actual sending of the email.

       

         Unfortunately I can't figure out how to handle smtp errors using the build-in activity.  For instance, the smtp server is down, the supplied email address is invalid (not a bounce), etc.  Experimenting shows that the mail activity fails (errors in the error log) and the process stays in the mail activity.  Once this occurs the jobexecutor never restarts the activity.  I've seen multiple references to exception handling (including section 9.6 of the developers guide) but no real examples of how to handle this type of case.

       

         So I figured I would ask what the best practices are for handling this.  It seems like my options are:

       

      1. Figure out how to have an exception cause a transition to some node that I can put logic in to figure out how to handle it and proceed accordingly.  For transient errors I would imagine some sort of timer/retry would be appropriate.
      2. Extend the mail activity implementation and add the logic there.  The only issue I'm not sure about is how to "find" the transition names I want to transition to without hard-coding them into the java code (i.e., how to define them in the mail activity jpdl to be retrieved and used in the java code).  Also it seems like others would have this problem so I feel like I'm reinventing the wheel a bit here.
      3. ??? - some way that I haven't thought of?

       

      I'm the first to admit I'm a newbie to jBPM.  This is my first real process that isn't an example/poc.  Any suggestions, pointers, etc would be highly valued.

       

      Thanks,

      - Jeff

        • 1. Re: How to handle SMTP failures in a mail activity
          rebody

          Hi Jeffrey,

           

          If there were some exception during jobExecutor executed jobs.  It will store the related exception information into database.  We could get these error information by querying JBPM4_JOB tables.

           

          Then if you want to execute some jobs by hand,  you could use management.executeJob(jobId);

           

          At last,  I think the best way to handle the error in process is using exception-handler,  which is not implemented yet,  Did you have any advices on it?  If you have any advices please tell us,  Thank you very much.

          1 of 1 people found this helpful
          • 2. Re: How to handle SMTP failures in a mail activity
            jeffgreg

            Hi HuiSheng,

                First thanks a ton for replying - so far you are the only person to do so.  Your posting is most definitely helpful.

             

                As for my problem, yes the job is most definitely failing.  The error in the JBPM4_JOB table is the full java stack trace effectively saying:

             

            javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 2525;

             

            The fact that ExceptionHandling is not yet implemented wasn't obvious in any of the docs, wiki postings, etc (although I was guessing it :-)

             

            So if I understand you correctly I need to build a mechanism to check the job table looking for state = error and figure out how to handle it.  If I decide to try it again I can manually fire it off using the management.executeJob(jobId).  I'll have to look into the api's to see if my failure code can manually cause the Process/Job to transition to a different activity - sort of roll my own exception handling.  That would be preferable to hard coding this type of logic in the job error handler.

             

            Is there any expected version in which ExceptionHandling will be added to the system?

             

            Thanks,

            - Jeff

            • 3. Re: How to handle SMTP failures in a mail activity
              mwohlf

              Maybe you can just set RETRIES_ to > 0  in the JBPM4_JOB table, the JobExecutor should pick them up and execute on its next run, or maybe set STATE_ to 'waiting' too :-/.