||
Skip to end of metadata
Go to start of metadata

The ServerInitializer interface is an extension point that can be used within your components to perform specific tasks before the server is fully initialized, i.e even before the transport listeners are initialized. If defined and registered correctly, the new initializers that you implement using this interface will be called by the Carbon core component during server startup.


Implementing the ServerInitializer interface

A component developer who wants to use this extension should first implement the ServerInitializer interface. An example is given below.

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.wso2.carbon.core.ServerInitializer;
import org.wso2.carbon.utils.ServerException;

/**
* An example implementation of ServerInitializer. This should be registered via carbon.xml.
*
*/
public class ExampleInitializer implements ServerInitializer {
   @Override
   public void init(ConfigurationContext configurationContext) throws AxisFault, ServerException {
       // initialization tasks that should be performed should go here
   }
}

To implement the above interface, following Maven dependencies should be used :

 

<dependency>
   <groupId>org.apache.axis2.wso2</groupId>
   <artifactId>axis2</artifactId>
   <version>1.6.1.wso2v12</version>
</dependency>
<dependency>
   <groupId>org.wso2.carbon</groupId>
   <artifactId>org.wso2.carbon.utils</artifactId>
   <version>4.4.2</version>
</dependency>
<dependency>
   <groupId>org.wso2.carbon</groupId>
   <artifactId>org.wso2.carbon.logging</artifactId>
   <version>4.4.2</version>
</dependency>
<dependency>
   <groupId>org.wso2.carbon</groupId>
   <artifactId>org.wso2.carbon.core</artifactId>
   <version>4.4.2</version>
</dependency>

Registering your ServerInitilizer

After implementing your own ServerInitilizer, you have to use the <PRODUCT_HOME>/repository/conf/carbon.xml file to register your initilizer. You have to use the fully qualified class name to register the initilizer under the “ServerInitializers” element, using a new “Initializer” tag in the carbon.xml configuration file. An example is given below.
<ServerInitializers>
        <Initializer>org.wso2.carbon.example.ExampleInitializer</Initializer>
</ServerInitializers>
  • No labels