Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Error Handling

  1. #11
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Okay, I finally had a chance to look at your example in more detail, and what is happening is the header values are not applied if you pass an actual MailMessage to the outbound adapter. In that case, it assumes you are in control (however, I can see how that could be viewed as a bug).

    I noticed that you are only setting the text on that MailMessage anyways. So, can you try to just returning a String from your 'transformError' method? It should then apply the headers when it creates a new MailMessage in the outbound adapter.

    By the way, I am not sure where your 'message' variable is actually defined (when you build the String), but it looks suspiciously like a thread-safety issue.

    -Mark

  2. #12
    Join Date
    Aug 2006
    Posts
    236

    Default

    Hi Mark

    thanks for response. I can change the transform error to a string. There is a string builder that is a local variable I may have commented it out in the post. The only other thing I guess is do I put the mail enricher def inside the chain config or should it be outside?

    Thanks

  3. #13
    Join Date
    Aug 2006
    Posts
    236

    Default

    Hi Mark

    I updated my code based on your recommendations and it works. I have added the enricher within the chain config:
    Code:
    <chain input-channel="errorChannel" output-channel="errorOutChannel">
    		<transformer ref="errorTransformer" method="transformError" />
            <mail:header-enricher from="${mailFrom}" to="${mailTo}" subject="${mail.subject}" overwrite="false"/>
         </chain>
    Is this ok?

    Cheers
    Amin

  4. #14
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Cool. I'm glad you were able to get that working, and it looks good to me.

    In fact, now that your transformer is returning a simple String, it should be easier for you to unit test that component.

    I am still interested in your opinion on the applicability of those headers to a preexisting MailMessage object though. As I mentioned, our rationale was that an explicitly constructed MailMessage should have been configured completely. The headers only make sense for the non-MailMessage payloads that are passed in to the outbound adapter. In hindsight, does that make sense?

    At the very least, I think we should clarify this in the JavaDoc as well as the reference manual. Could you please open a JIRA issue for that and link to this forum thread?

    Thanks,
    Mark

  5. #15
    Join Date
    Aug 2006
    Posts
    236

    Default

    Hi Mark

    I guess when I read the documentation I naturally thought if my transformer returned a MailMessage then the enricher would add the header to it. I would defintiely recommend adding something to the documentation (I could've missed it) or may be add a sample project to show it's use. From a user point of view I would like to have the mail header enricher be applied to the MailMessage as well as the string payload (maybe too much!). To me it made sense for it to be applied to the MailMessage to be honest.

    Unit testing the errortransformer was still very easy whether i returned a string or the MailMessage. I can raise a JIRA for the docs to be updated.

    Cheers
    Amin

  6. #16
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Thanks Amin.

    My only concern with adding headers even to a MailMessage payload would be the case where someone is sending to an outbound adapter from more than one source. One of the sources would be just simple Strings and the headers are needed, while the other source is fully configured MailMessages. In such a scenario, the header-enricher would be considered as "default" headers. However, I guess even in such a case, the flow should be configured in such a way that the header-enricher only applies to the non-MailMessage part of the chain if that is what's desired.

    Feel free to raise the issue for the headers being applied to any payload type. If nothing else, we can generate some debate that way. If necessary, we could consider adding a boolean for 'applyHeadersToMailMessagePayload', but that is probably overkill. If others agree that the approach you expected is most intuitive, then we can go with that for 2.0.

    Hopefully what you have now will be fine for your immediate needs?

    Regards,
    Mark

  7. #17
    Join Date
    Aug 2006
    Posts
    236

    Default

    Hi Mark

    I'll raise a JIRA for headers to be applied to MailMessage payload. The stuff I have now works well so no complaints from me. I am really enjoying SI, cool stuff and simple to use.

    Cheers
    Amin

  8. #18
    Join Date
    Aug 2006
    Posts
    236

    Default

    I've raised JIRA http://jira.springsource.org/browse/INT-760

    Cheers
    Amin

  9. #19
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Thanks again. I set its target to 2.0-M1.

    -Mark

  10. #20
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    I made this change on the trunk:
    https://fisheye.springsource.org/cha...ration?cs=2439

    If you get a chance to try out your code with the next nightly snapshot, it would be great to confirm that it is working for you as expected.

    Thanks,
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •