Saturday, November 15, 2008

Axis2 client side module engagement

This post explains the different options available for engaging modules at the Axis2 client side.

Let's start with engaging modules with axis2.xml.

<axisconfig name="AxisJava2.0">
<!-- engaging rampart module -->
< module ref="rampart" />
With this, we have asked Axis2 to load the module rampart.

But, how come axis2 knows - from where to locate the above axis2.xml.

ConfigurationContext configContext = null;
configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo","path_to_axis2_xml");
In this case axis2.xml will be loaded from path_to_axis2_xml and the corresponding modules will be loaded from path_to_repo/modules directory. So in our case you need to have the rampart module inside path_to_repo/modules directory.

Following is another way - how you can tell Axis2 to load your axis2.xml.

ConfigurationContext configContext = null;
configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo",null);
Here we pass null for path_to_axis2_xml.

In this case Axis2 will try to find out axis2.xml from directly under path_to_repo location.

Notice here that the name of the configuration file must be axis2.xml.

Doing all these above is still not enough - we need to load ConfigurationContext we created into the service Stub.

SimpleServiceStub service = null;
service = new SimpleServiceStub(configContext, SERVICE_EPR);
All set and we are done with the first option.

BTW, there is another way you can ask Axis2 to load your axis2.xml without creating a ConfigurationContext and passing it to the service Stub. In this case you need to set following system properties.

import org.apache.axis2.Constants;

System.setProperty(Constants.AXIS2_CONF, "path_to_axis2_xml");
System.setProperty(Constants.AXIS2_REPO, "path_to_repo");
Even in this case, if you only set the AXIS2_REPO property then the axis2.xml will be read from directly under path_to_repo location.

With this option you need not to create and load the ConfigurationContext in to the service Stub.

SimpleServiceStub service = null;
//service = new SimpleServiceStub(configContext, SERVICE_EPR);
service = new SimpleServiceStub(SERVICE_EPR);
Let's move to the next option - that is engaging modules programmatically.

Following shows how to do that.

SimpleServiceStub service = null;
service = new SimpleServiceStub(SERVICE_EPR);
Here we do not need to tell Axis2, where to find the axis2.xml - but still we need to tell where to locate the module - that is the path_to_repo.

We can do it by just setting the Constants.AXIS2_REPO system property as below.

System.setProperty(Constants.AXIS2_REPO, "path_to_repo");
OR we can create a ConfigurationContext with path_to_repo and pass it to the service stub.

SimpleServiceStub service = null;
ConfigurationContext configContext = null;

configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo",null);

//service = new SimpleServiceStub(SERVICE_EPR);
service = new SimpleServiceStub(configContext, SERVICE_EPR);
That's it - and we are done with the second option as well.


Pedro said...

Thanks for this very clearly written post. I just came accross the problem you address and, with your help, I solved it in no time.

Andrey said...

Yes, it is really useful information.
Could you please advise how to configure jms transport programatically? I need my axis client to be configured by application options which could be changed in runtime.

Thanx in advance.

sriraj said...

this really helped me. Thank you

Ryan H. said...

This article saved my life...THANK YOU!

Ryan H. said...

Some extra information to note, which may be useful to others, taken from Axis2 documentation:

Axis2 configuration is based on a repository and standard archive format. A repository is a directory in the file system, and it should have the following:

axis2.xml, the Axis2 global deployment descriptor in conf/axis2.xml file
services directory, which will have the service archives
modules directory (optional), which will have the module archives
Both services and modules will be identified and deployed once their archives are copied to the corresponding directories. At the server side, users should specify the repository folder at the time of starting the Axis2 Server (e.g. HTTP or TCP). In Tomcat, webapps/axis2/WEB-INF folder acts as the repository. At the client side, binary distribution can itself be a repository. You can copy the conf directory which includes the axis2.xml file from the exploded axis2.war and edit it to change the global configurations repository.

Jorge Infante Osorio said...

What if I call a web service A using some client classes and this classes are inside another webservice B.
How i can call the repo to engage rampart inside a web service??

raybanoutlet001 said...

louboutin shoes
nike huarache
yeezy shoes
mont blanc outlet
ed hardy uk
michael kors handbags
ugg boots
oakley sunglasses
ugg boots
coach outlet online