Let's start with engaging modules with axis2.xml.
With this, we have asked Axis2 to load the module rampart.
<axisconfig name="AxisJava2.0">
<!-- engaging rampart module -->
< module ref="rampart" />
</axisconfig>
But, how come axis2 knows - from where to locate the above 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.
ConfigurationContext configContext = null;
configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo","path_to_axis2_xml");
Following is another way - how you can tell Axis2 to load your axis2.xml.
Here we pass null for path_to_axis2_xml.
ConfigurationContext configContext = null;
configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo",null);
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.
All set and we are done with the first option.
SimpleServiceStub service = null;
service = new SimpleServiceStub(configContext, SERVICE_EPR);
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.
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.
import org.apache.axis2.Constants;
System.setProperty(Constants.AXIS2_CONF, "path_to_axis2_xml");
System.setProperty(Constants.AXIS2_REPO, "path_to_repo");
With this option you need not to create and load the ConfigurationContext in to the service Stub.
Let's move to the next option - that is engaging modules programmatically.
SimpleServiceStub service = null;
//service = new SimpleServiceStub(configContext, SERVICE_EPR);
service = new SimpleServiceStub(SERVICE_EPR);
Following shows how to do that.
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.
SimpleServiceStub service = null;
service = new SimpleServiceStub(SERVICE_EPR);
service._getServiceClient().engageModule("rampart");
We can do it by just setting the Constants.AXIS2_REPO system property as below.
OR we can create a ConfigurationContext with path_to_repo and pass it to the service stub.
System.setProperty(Constants.AXIS2_REPO, "path_to_repo");
That's it - and we are done with the second option as well.
SimpleServiceStub service = null;
ConfigurationContext configContext = null;
configContext= ConfigurationContextFactory.createConfigurationContextFromFileSystem("path_to_repo",null);
//service = new SimpleServiceStub(SERVICE_EPR);
service = new SimpleServiceStub(configContext, SERVICE_EPR);