This section of Developer's Guide explains the steps that were performed to create the sample extension HelloWorld and application.
About the Example
Design the Extension
Complete the Extension
Build the Application
Test the Application
Open Netscape Extension Builder Designer.
Create an access module.
Create a service module.
Generate IDL files.
On Windows NT, double-click the Netscape Extension Builder icon or run the neb command. On Solaris, run the neb command. The neb command executable is in the bin directory of your Netscape Extension Builder installation directory.
The Netscape Extension Builder Designer start-up window appears.
Name the extension HelloWorld.
In the tree view, highlight the iSample access module.
Name the module ihello.
In the access module, define an interface named IHelloWorld.
In the interface, define a method named helloThere.
In the method, define a parameter named pHelloMessage. Define it as an Out parameter of type String.
In the tree view, highlight the service module.
Name the module chello. Leave the values for service module decorations as they are.
In the service module, define a coclass named CHelloWorld.
Change the value of the Manager Class decoration to Yes. This marks CHelloWorld as the manager class for the chello service.
Leave the other values for CHelloWorld decorations as they are.
In the CHelloWorld coclass, implement the IHelloWorld interface.
In the IHelloWorld interface, decorate the parameter of the helloThere method. Set the value of the pHelloMessage parameter to 256. This sets the maximum buffer size for the out string parameter.
Generate source code by running the gmake command from the top-level directory of the extension.
The gmake command places stub files in the cpp\gen.chello\ directory. The gmake command also copies stub files to the cpp\chello\ directory if it is empty.
Go to the cpp\chello\ directory and locate the stub file named CHelloWorld.cpp. This file corresponds to the class you created.
Edit CHelloWorld.cpp by completing the stub for the helloThere method.
Note: in the sample extension provided, the cpp\chello\CHelloWorld.cpp file already contains the completed stub. To view the stub file before it is completed, compare the sample code in cpp\gen.chello\CHelloWorld.cpp.
Rerun the gmake utility from the cpp\chello directory. In general, you only need to rerun gmake from directories in which you've edited files.
Register the extension: kreg < Hello.gxr
Registering an extension makes it available to C++ and Java applications.
Locate the callHello.java application in the sample\hello\servlet directory.
Edit the application to use the accessors for the extension. When you are done, the application should look like the following: package HelloTest; import java.lang.*; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import com.netscape.server.servlet.extension.*; import com.kivasoft.applogic.*; import helloExtension.*; // extension classes public class callHello extends HttpServlet { /** * Call the hello extension */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { // access servlet's underlying AppLogic instance HttpServletRequest2 req2; req2 = (HttpServletRequest2) req; // legal cast within NAS AppLogic al = req2.getAppLogic(); com.kivasoft.IContext alContext; alContext = al.context; // Attempt to get to the helloExtension through the accessor IHelloWorld hello=access_chello.getchello(alContext, null, al); // Let's build the result string String result; // Go to the extension to get the greeting if (hello != null) { result = hello.helloThere(); } else { result = "ERROR! Can't get access to the Hello extension."; } req.setAttribute("strHelloMsg", result); res.setContentType("text/html"); RequestDispatcher dispatcher; dispatcher = getServletContext().getRequestDispatcher("HelloTest/ hello.jsp"); dispatcher.include(req, res); return; } }
After you finish editing the application code, register the application: kreg < appinfo.gxr
Copy hello.jsp into the <NAS_ROOTDIR>\APPS\helloTest directory.
Copy appInfo.ntv and servInfo.ntv into the <NAS_ROOTDIR>\APPS\helloTest\ntv directory.
From your web browser, load a test page that uses the application. Point your browser to http://<my_host_name>/extensions, and select the Hello example.
Test the application from the web page.
You have completed all tasks for the code walkthrough.