Friday, October 15, 2010

Engaging modules in AXIS2 on client side

Engaging modules at client side gets quite frustrating when you have written stand alone client on eclipse. There are no. of ways you can do that. The easiest one is to change module extensions form .mar to .jar so that you can add them to eclipse class path. You don't have to make any other changes and you can engage module at client side programatically.

suppose you want to engage addressing module, then following code will be sufficient provided you have addressing.jar file in your class path.

ServiceClient sc = new ServiceClient();

Now lets remove addressing jar from class path and try running the same code. You will get infamous "Unable to engage module : addressing"!

So what if I don't want to change the extension of modules. We need to pass location of module file while creating configuration context as follows.

ConfigurationContext configContext =
ServiceClient sc = new ServiceClient(configContext,null);

Engaging modules can be set globally when you pass axis2.xml while creating configuartion context. You need to uncomment <module ref="addressing"/> in axis2.xml. Now sc.engageModule("addressing"); is not needed to engage addressing module. Moreover if you don't want addressing feature for every client request comment <module ref="addressing"/> in axis2.xml and engage module by calling ServiceClient#engageModule when needed.

There is another way to provide modules information at runtime by setting :Constants.AXIS2_REPO and Constants.AXIS2_CONF config properties.

System.setProperty(Constants.AXIS2_REPO, "C:/MyFolder/MySoftwareLab/tools/axis2-1.5.1-bin/axis2-1.5.1/repository");
System.setProperty(Constants.AXIS2_CONF, "your local axis2 path");

Above works because of following code of AXIS2 engine.

if (repoLocation == null) {
//checking wether user has set the system property
repoLocation = System.getProperty(Constants.AXIS2_REPO);

if (axis2xml == null) {
// If not, check for a system property setting
axis2xml = System.getProperty(Constants.AXIS2_CONF);

1 comment:

  1. This post helped me to create and add client modules from a standalone client. Thank you