Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Writing Axis2 Custom Deployers - hot deployment - WSO2 Carbon Products

DZone's Guide to

Writing Axis2 Custom Deployers - hot deployment - WSO2 Carbon Products

Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

Custom deployers is a concept introduced to Axis2 to increase it's flexibility and enhance the dynamic nature.  With this article on Axis2 Custom Deployers, it's originator himself explains it's background and procedure in details. With this post, I'll just share the steps I followed in using this feature.
  • Following is the basic structure of a custom deployer. There needs to be a class that has implemented 'org.apache.axis2.deployment.Deployer' interface and a component.xml file that carries some required properties for the deployer.
  • Following is the basic structure of a CustomDeployer class.
public class CustomDeployer extends AbstractDeployer {

    private static Log log = LogFactory.getLog(CustomDeployer.class);
    private File userMgtConfigFile;
    private RealmConfigXMLProcessor realmConfigXMLProcessor = new RealmConfigXMLProcessor();

    public void init(ConfigurationContext configurationContext) {
        // Here goes all the initialization code.
    }

    public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
        File file = deploymentFileData.getFile();
        // Here goes the processing code need to process the file
    }

    public void setDirectory(String s) {
        // if we need to know the subdirectory that the deployer has registered
    }

    public void setExtension(String s) {
        //extension of the file that the deployer has registered
    }
}
When there is a file addition in the subdirectory that we are interested in (file extension that the deployer has registered with) 'deploy' method is called. When a file is deleted 'undeploy' method is called. When a modification is done both the methods will be called accordingly. Directory and extension of the files to be deployed can be set by the relevant methods.
  • Following is a sample component.xml file written for a WSO2 Carbon product.
<component xmlns="http://products.wso2.org/carbon">
    <deployers>
        <deployer>
            <directory>userstore</directory>
            <extension>xml</extension>
            <class>org.wso2.carbon.identity.user.store.configuration.deployer.UserStoreConfigurationDeployer</class>
        </deployer>
    </deployers>
</component>
  • Finally in the pom.xml(of Maven module) we should define the deployer as follows,
<Axis2Deployer>CustomDeployer</Axis2Deployer> 

We are done now. Finally one more thing worth to note is, we can enable hot update by setting 'true' for the parameter 'hotupdate' in axis2.xml. With this if we add a file of the given extension in the directory, the file will be get deployed at the moment itself.












Download A Buyer's Guide to Application and Data Integration, your one-stop-shop for research, checklists, and explanations for an application and data integration solution.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}