I have an ejb-jar.xml that contains configuration information for one of my MDB. In there is a configuration of:
<activation-config-property>
<activation-config-property-name>addressList</activation-config-property-name>
<activation-config-property-value>mq://test.server.uk:7676</activation-config-property-value>
</activation-config-property>
As my project is built and packaged and then distributed off to users I need to be able to make sure this value can be modified as users have different server addresses.
Currently I have the option to set the address in a properties file. Is there anyway that I could modify this xml during deployment on glassfish 4.0 with the property value?
If not am I going to have to set the value every time someone wants the application and re-build it?
I am open to putting the configuration else where I just need to have it dynamic so that users can set the server addresses in a properties file.
One thing you can try is to use an @AroundConstruct
interceptor to set the value on the MDB at runtime. It's worthwhile to note that while it is possible to use placeholders in your ejb-jar.xml, it's primarily container-dependent, and the apparent lack of reading material on how it's done for Glassfish specifically should be a source of worry for you. Let's try this:
Define an interceptor on your MDB:
@MessageDriven
@Interceptors(AddressListInterceptor.class)
public class YourMDB
Define your interceptor
public class AddressListInterceptor {
@AroundConstruct
private void begin(InvocationContext iCtxt) {
/**load your property prior to this point */
ActivationConfigProperty addressList = new ActivationConfigProperty{
public String propertyName(){
return "addressList";
}
public String propertyValue(){
return theAddressList;
}
public Class<? extends Annotation> annotationType(){
return ActivationConfigProperty.class;
}
};
try {
/**get the annotations, with the intention of adding yours (addressList) to the array using the method demonstrated in
http://stackoverflow.com/a/14276270/1530938 */
Annotations[] annotations = iCtxt.getClass().getAnnotations();
iCtxt.proceed(); //this will allow processing to continue as normal
} catch (Exception ex) {
}
}
Apart from the unfortunate need to scan and modify the annotations yourself, what this approach buys you is that you're allowed to step into the lifecycle of the MDB and modify the value of the annotation, just before the bean is intantiated. By the time the bean is put into service, it'll take the value you've set and everything should be in order
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With