Changing ejb-jar.xml configuration properties during deployment to GlassFish 4.0

I have ejb-jar.xml which contains configuration information for one of my MDB. It has a configuration:

<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 to users, I need to be able to make sure that this value can be changed, because users have different server addresses.

Currently, I have the ability to set the address in the properties file. Anyway, can I change this xml during deployment to glassfish 4.0 with a property value?

If I donโ€™t have to set a value every time someone wants an application and rebuild it?

I am open to hosting another configuration, where I just need to have it dynamic so that users can set server addresses in the properties file.

+6
source share
2 answers

I found an easy way to change the address list in glassfish 4.0. This solution allows you to use the rest of your @ActivationConfigProperty. For me, when a user uses a setup script to install, I can run the following commands:

 asadmin server.jms-service.type = REMOTE asadmin set configs.config.server-config.jms-service.jms-host.default_JMS_host.host= "testserver.test.te.uk" asadmin restart-domain 

You set the default REMOTE type to the JMS host, and then suggest that the broker use the address defined on the default JMS host.

Then you set the host address with the asadmin set command.

Once this is done, you need to restart your old fish.

This is obviously a glass fish container, but thatโ€™s all I need.

0
source

One thing you can try is to use the @AroundConstruct interceptor to set the value in MDB at runtime. It is worth noting that although you can use placeholders in your ejb-jar.xml, this is primarily dependent on the container, and the apparent lack of reading about how this is done for Glassfish should be a source of concern for you. Let's try this:

  • Define an interceptor on your MDB:

     @MessageDriven @Interceptors(AddressListInterceptor.class) public class YourMDB 
  • Identify 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) { } } 

Besides the unfortunate need to scan and modify annotations yourself, the fact that this approach buys you is that you are allowed to enter the MDB life cycle and change the value of the annotation just before you are intaniated. By the time the bean is entered, it will take the value you set, and everything should be fine

+3
source

All Articles