Home | | Sitemap ||Page number :10

4.3.1 Server extension sample

The following sample illustrates how integration with existing billing information system can be implemented. The sample code shows how to create a server extension that implements the AccessLogWriter interface and maintains a persistent connection to a billing system. As discussed later [see 5.1], a servlet can initialise persistent connections during the initialisation of the servlet.

import javax.servlet.*; import com.nokia.wap.server.*; import com.bcomp.billing.*;

public class WapService extends GenericServlet, implements com.nokia.wap.server.extension.AccessLogWriter {

// My connection to on-line billing system BillingOnLine billSystem;

public void init(ServletConfig config) throws ServletException

{// create and open connection to actual system billSystem = new

BillingOnLine(config.getInitParameter("SysName"));

billSystem.loginAsRecordCreator(config.getInitParameter("BFo rmat"));

// Get WAPServer interface

ServletContext myCntx = config.getServletContext(); WapServer iServ=(WapServer)myCntx.getAttribute ("com.nokia.wap.server.WapServer");

// Register myself as AccessLogWriter iServ.registerExtensionService( "com.nokia.wap.server.extension.AccessLogWriter", this);

}

// AccessLogWriter methods

public void LogAccess(AccessLogEntry entry)

{if (entry.getWspStatusCode() == 0x20) {

Brecord br=billSystem.createRecord(entry.getUserid());

br.setSelector(GetServiceName(entry.getRequestedUrl())); billSystem.commit(br); } }

String GetServiceName(URL url) { return …; } }