Manual Module CreationManual Module Creation
Home > Books > Tutorials and Training Guides > Fundamentals Practicalites > Manual Module Creation

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:


Manual Module Creation Tutorial

This tutorial describes how to create a new NetKernel module using six steps. These can be completed with any text editor. After you read this tutorial you may wish to use the New Module Wizard instead of creating your module manually.

The goal of this tutorial is to describe how to create a working application module, register it with NetKernel and access its services from a browser.

Step 1

Create a new physical directory for the module.

Locate the [install] directory - this is the directory into which your installation of NetKernel was placed. Underneath the [install] directory locate the modules directory. In the modules directory create a new directory named HelloWorld (capitalization is significant).

Step 2

Create the module definition file module.xml.

As described in the Logical Module description, a module is fully described by its module definition file. In the directory [install]/modules/HelloWorld/ create a file named module.xml. Copy the following and paste it into that file:

<module>
  <identity>
    <uri>urn:com:mycompany:mymodules:hello-world</uri>
    <version>0.1.0</version>
  </identity>
  <info>
    <name>Hello World</name>
    <description>My first module</description>
    <type>application</type>
    <dynamic />
  </info>
  <export>
    <uri>
      <match>ffcpl:/hello/world.*</match>
    </uri>
  </export>
  <rewrite>
    <rule>
      <match>ffcpl:/hello/world(.*)</match>
      <to>active:dpml+operand@ffcpl:/world.idoc$1</to>
    </rule>
  </rewrite>
  <mapping>
    <this>
      <match>ffcpl:/resources/.*</match>
    </this>
    <import>
      <uri>urn:org:ten60:netkernel:ext:dpml</uri>
    </import>
  </mapping>
</module>

This defines a module with a limited exported addres space and the entries required to run a DPML program.

Step 3

Create a DPML program to return the "hello world" resource representation.

In the previous section we declared a rewrite rule in the module definition file which will execute a DPML script ffcpl:/world.idoc.

<rewrite>
  <rule>
    <match>ffcpl:/hello/world(.*)</match>
    <to>active:dpml+operand@ffcpl:/world.idoc$1</to>
  </rule>
</rewrite>

This matching rule captures any parameters at the end of the URI and adds them back to the target URI. (Any parameters are ignored by the DPML program.)

We also mapped all local resources starting with ffcpl:/ into the inner private address space

<mapping>
  <this>
    <match>ffcpl:/.*</match>
  </this> ...
</mapping>

which makes the program ffcpl:/world.idoc available for use. Create the file world.idoc in the module directory and copy the following program into it:

<idoc>
  <instr>
    <type>copy</type>
    <operand>
      <hello>world</hello>
    </operand>
    <target>this:response</target>
  </instr>
</idoc>

Step 4

Register the module with NetKernel.

NetKernel uses the file [install]/etc/deployedModules.xml to physically locate all installed modules. To register our new module add the following line to this file:

<module>modules/HelloWorld/</module>

Step 5

Associate the module with the HTTP transport.

In order to connect our new module to the outside world we need to register it with a transport. We are going to use the Frontend Fulcrum, a web server listening on port 8080. We do this by adding an import statement to the fulcrum which is located in the directory [install]/modules/mod-fulcrum-frontend/. Edit the module.xml file of this module to import our new module by adding this:

<import>
  <uri>urn:hello-world</uri>
</import>

Step 6

Run the service.

Now that we everything coded and configured we need to restart NetKernel so that it will re-read the deployedModules.xml file and discover our new module. Go to the Cold Restart tool and restart NetKernel. Wait a few seconds. Then enter http://localhost:8080/hello/world into your browser and you should see the message:

<hello>world</hello>

Summary

That is all you need to do to create a new module in NetKernel.

© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.