-
Email Whitelist Handling
hi all
i have to extend my spring integration configuration with a email whitelist handling. emails should only be sent to receipients defined in a file. what's the best way or spring integration component to do that? later i also have to implement the same for sms, faxes and so on.
regards
angela
-
You can use a custom filter...
Code:
public class MailFilter {
public boolean filter(@Header(MailHeaders.TO) String mailTo) {
return isInWhiteList(mailTo);
}
private boolean isInWhiteList(String mailTo) {
...
}
}
Code:
<int:filter input-channel="foo" output-channel="toMail">
<bean class="foo.MailFilter" />
</int:filter>
-
thanks for the answer!
i will try that...would it be also a good approach to implement one filter for all whitelist handling (email, fax, sms)? then reading the whitelists there and setting the new messageheaders?
something like that?
@
PHP Code:
Named("outgoingMessageFilter")
public class OutgoingMessageFilter implements MessageSelector {
/**
* Implement a whitelist handling for all outgoing messages!
*
* @see org.springframework.integration.core.MessageSelector#accept(org.springframework.integration.Message)
*/
@Override
public boolean accept(Message<?> message) {
MessageHeaders headers = message.getHeaders();
List<String> emailSubscribers = headers.get(CustomHeaders.EMAIL_SUBSCRIBERS, List.class);
//handle and set new emails subscribers
List<String> faxSubscribers = headers.get(CustomHeaders.FAX_SUBSCRIBERS, List.class);
//handle and set new fax subscribers
List<String> iphonePushSubscribers = headers.get(CustomHeaders.IPHONEPUSH_SUBSCRIBERS, List.class);
//handle and set new iphone push subscribers
return false;
}
}
regards
angela
-
That would work too, but you could avoid tying your code to the framework by using a POJO and a SpEL expression to pull the lists out of the headers; something like
Code:
<filter ... expression="@myPojoSelector.select(headers['mailSubs'], headers['faxSubs'], headers['iphonePushSubs'])" ... />