I'm trying to use this method for receiving mail in our EJB3 app. In short, that means creating an MDB with the following annotations:
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "mailServer", propertyValue = "imap.company.com"),
@ActivationConfigProperty(propertyName = "mailFolder", propertyValue = "INBOX"),
@ActivationConfigProperty(propertyName = "storeProtocol", propertyValue = "imap"),
@ActivationConfigProperty(propertyName = "debug", propertyValue = "false"),
@ActivationConfigProperty(propertyName = "userName", propertyValue = "username"),
@ActivationConfigProperty(propertyName = "password", propertyValue = "pass") })
@ResourceAdapter("mail-ra.rar")
@Name("mailMessageBean")
public class MailMessageBean implements MailListener {
public void onMessage(final Message msg) {
...snip...
}
}
I have this working, but the situation is less than ideal: The hostname, username and password are hardcoded. Short of using ant and build.properties to replace those values before compilation, I don't know how to externalize them.
It would be ideal to use an MBean, but I have no idea how to get the values from the MBean to the MDB configuration.
How should I do this?
You can externalise the annotations into the ejb-jar.xml that you deploy in the META-INF of your jar file as follows:
Then you can set the mdb.user.name value as a system property as part of the command line to your application server using -Dmdb.user.name=theUserName and it will magically get picked up by the mdb.
Hope that helps.
As of JBoss AS 5.1 at least, you can use AOP to configure the @ActivationConfigProperties. I discovered this by looking at the examples that jboss provides here. This is useful if you do not want your username and passwords available to the entire container in a systems property, or if you are like me and never, I repeat NEVER, want to deploy an artifact with a username/password in it. Any how, here is the jist...
Annotate the mdb like this...
Then add a ${whatever}-aop.xml to the deploy dir with internals like below. I left the original comments in there in case Jaikiran does make the changes mentioned...