Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The following steps show the actions that need to be performed to deploy a custom module for a given Web service:

There is an example of a simple logging module below. This module contains one handler that just logs the message that is passed through it. Axis2 uses MAR (Module Archive) to deploy modules in Axis2.

Create the Module Implementation

Anchor
Create the Module Implementation
Create the Module Implementation

...

For a simple logging service (as in the example), it is possible to keep these methods blank in the implementation class.

Create the Handlers

Anchor
Create the Handlers
Create the Handlers

...

Code Block
Java
Java
public class LogHandler extends AbstractHandler implements Handler {
    private static final Log log = LogFactory.getLog(LogHandler.class);
    private String name;

    public String getName() {
        return name;
    }

    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
        log.info(msgContext.getEnvelope().toString());
        return InvocationResponse.CONTINUE;
    }

    public void revoke(MessageContext msgContext) {
        log.info(msgContext.getEnvelope().toString());
    }

    public void setName(String name) {
        this.name = name;
    }
}

Create the module.xml
Anchor
Create the module.xml
Create the module.xml

module.xml contains the deployment configurations for a particular module. It contains details such as the implementation class of the module (in this example it is the LoggingModule class and various handlers that will run in different phases). The module.xml for the logging module will be as follows:

...

To learn more about Phase rules, refer to the article Axis2 Execution Framework: http://www.developer.com/java/web/article.php/3529321

Modify the axis2.xml
Anchor
Modify the "axis2.xml"
Modify the "axis2.xml"

In this handler the loggingPhase is defined by the module writer. It is not a predefined handler phase, hence the module writer should introduce it to the axis2.xml (not the services.xml) so that the Axis2 engine knows where to place the handler in different flows (inFlow, outFlow, etc.).

...

The custom phase loggingPhase is placed in all the flows, hence that phase will be called in all the message flows in the engine. Since the module is associated with this phase, the LogHandler inside the module will now be executed in this phase.

Modify the services.xml
Anchor
Modify the "services.xml"
Modify the "services.xml"

Up to this point, it was created the required classes and configuration descriptions for the logging module and the required phases.

...

In this example, the service name was changed. In addition the line <module ref="logging"/> was added to services.xml. This informs the "Axis2" engine that the module logging should be engaged for this service. The handler inside the module will be executed in their respective phases as described by the module.xml.

Package in a MAR (Module Archive)
Anchor
Package in a ".mar" (Module Archive)
Package in a ".mar" (Module Archive)

Before deploying the module, it is necessary to create the MAR file for this module. This can be done using the JAR command and then renaming the created JAR file. Else you can find the logging.mar that has already been created in the Axis2_HOME/samples/userguide directory.

Deploy the module in Axis2
Anchor
Deploy the module in Axis2
Deploy the module in Axis2

Deploying a module in Axis2 requires the user to create a directory with the name "modules" in the webapps/axis2/WEB-INF directory of their servlet container, and then copying the MAR file to that directory.

...