Programmers Guide
Programmers Guide
Programmers Guide
http://www.nokia.com
Material code: WSRN10060WW0028
VERSION 1.0 November 18, 1999
Copyright © Nokia Corporation 1999. All Rights Reserved.
Please send your comments and suggestions to:
Nokia Group Finland
P.O. Box 207,
FIN-00045 NOKIA GROUP, FINLAND
Tel. 00800 6654 2927 (00800 nokiawap), +358 9 692 7156
Fax. 00800 6054 2927, +358 9 692 6894
Internet mail address:
[email protected]
http://www.nokia.com
This document is provided "as is" without warranty of any kind, either express or implied,
including, but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. Nokia will not, in any event, be responsible for
possible errors in this document or for any damages, incidental or consequential
(including, but not limited to monetary losses), that might arise from the use of or
inability to use the document or the information in it, even if Nokia has been advised of
the possibility of such damages.
The document could include technical inaccuracies or typographical errors. Nokia
welcomes customer comments as part of the process of continuous development of the
document. Any such comments shall become the property of Nokia without any duty of
compensation or obligation to use.
Changes are periodically added to the information herein; these changes will be
incorporated in the new editions of the document. Nokia may at any time make
improvements and/or changes in the product(s) and/or the program(s) described in the
document.
This document is part of the Nokia WAP Server. Reproduction, distribution or transmission
of part or all of this documentation in any form without the prior written permission of
Nokia is prohibited.
Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. Java,
Sun and Sun Microsystems are trademarks of Sun Microsystems, Inc. Windows NT is a
trademark of Microsoft Corporation. Other product and company names mentioned herein
may be trademarks or trade names of their respective owners, and are mentioned for
identification purposes only.
1 Introduction ............................................................................ 1
1.1 Overview of the WAP architecture...................................................... 1
1.2 Nokia WAP Server..................................................................................... 2
1.2.1 Purpose and scope.................................................................................... 2
1.3 Background ................................................................................................. 2
1.4 Terminology ................................................................................................ 3
1.5 References................................................................................................... 3
WAP services can be created in many ways. A simple approach is to place static WAP
(WML and WML Script) content on an existing web server or a Nokia WAP Server.
However, utilizing the Nokia WAP Server’s Application Programming Interfaces
provides remarkable benefits for advanced WAP development. This document is
directed at application developers interested in implementing versatile, dynamic
services by utilizing the open programming interfaces provided by the Nokia WAP
Server.
This document gives an overview and specification of the programming APIs for the
Nokia WAP Server. This chapter contains a short introduction to the WAP architecture
and Nokia WAP Server product. Chapters 2 and 3 give an overview of programming for
Nokia WAP Server and a sample program. Chapters 4 and 5 go into the details of the
Nokia WAP Server application development, and the last chapter discusses the
technical aspects related to WAP protocols that a programmer might find useful when
fine-tuning a WAP service.
The accompanying "Nokia WAP Server API reference" contains detailed interface, class
and method definitions for the API. The reference material is distributed as HTML files
with this document.
More information about WAP can be found at http://www.wapforum.org. More
information about the Nokia WAP Server can be found at
http://www.nokia.com/corporate/wap.
Datacom network
Application server
Telecom network
SMS, Company
CSD, Operator Intranet
WAP GPRS, network
SMS-C,
terminals IP
...
WAP
gateway
Web Server
For details of the WAP architecture, see the WAP Architecture Specification [2].
1.3 Background
Because Java Servlets have achieved a strong position in web application development,
the same concept was selected to make it easy for developers to start developing WAP
applications for the Nokia WAP Server.
The reader of this document is assumed to have a basic knowledge of Java Servlet
development. The Java Servlet API and other servlet developer information is available
at http://www.javasoft.com. The Java Servlet API 2.0 reference material is included in
the [installation directory]\docs directory.
1.4 Terminology
WAP gateway A general entity in the WAP architecture between a WAP
terminal in a telecom network and an origin server in a data
network. The WAP gateway makes a protocol transformation
from WAP to HTTP.
Nokia WAP Server A Nokia product that acts both as an origin server and a WAP
gateway.
Servlet Servlets are software modules that conform to the Nokia WAP
Server API. These modules can be plugged into the Nokia WAP
Server.
Bearer Adapter A piece of software that provides the Nokia WAP Server with
network connectivity.
1.5 References
[1] Java Servlet API, Javasoft, http://www.javasoft.com
[2] WAP Architecture Specification, WAP Forum, http://www.wapforum.org
[3] Wireless Session Protocol Specification, WAP Forum, 30-April-1998
[4] RFC 2068, "Hypertext Transfer Protocol - HTTP/1.1", Fielding, R., et.al.
Java Servlet
WAP Server
Authentication,
Protocol
interfaces
WAP Access control
Protocol
In addition to the Java Servlet interfaces, a WAP service can use other services
provided by the Nokia WAP Server. A WAP service can also use other servlets to
complete its tasks.
2.4 Why write servlets directly for the Nokia WAP Server
WAP services can be implemented in many ways. One way to develop WAP services is
to write the application for a web server. In this case, the Nokia WAP Server works as a
WAP gateway, using HTTP to connect to the application on the web server. This model
works without any additional software on the Nokia WAP Server, and the service is
located completely on the web server. However, this approach does not utilise all the
information and services that could be used in the development of advanced, secure
and user friendly WAP applications.
The Nokia WAP Server provides a platform that can be used to write applications
directly on top of the Nokia WAP Server. The major differences to web server
application authoring are:
■ WAP-specific user and protocol information is available to the servlet.
■ Powerful WAP- and Nokia WAP Server-specific functionality is available (bearers,
information push, response delivery confirmation).
■ Nokia WAP Server provides end-to-end security.
■ Web server is not required.
NOTE: The user interface screen shots in this chapter are subject to change.
Once a WAP service is created as a Java Servlet, it must be installed and configured for
the Nokia WAP Server. This includes several steps:
1 Install the servlet with the Nokia WAP Server Manager, which is the management
user interface of the Nokia WAP Server. Provide the initial configuration
information and the Java classes that implement the servlet.
2 Map a specific URL to the installed servlet and define the necessary access control
to possibly limit access to your servlet.
3 Configure the servlet. The Nokia WAP Server Manager provides a generic user
interface to modify the configurable properties of servlets.
4 The servlet is now available for WAP terminal users. The servlet can then be
accessed with a WAP terminal by selecting a URL that is mapped to the servlet.
For information on how to configure servlets with Java Archive (JAR) files, see the
Nokia WAP Server Administration Guide.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* HelloWorldServlet - a very simple servlet
*/
Note: The above sample is the same one that is pre-installed in the standard Nokia
WAP Server 1.0 package.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.xcomp.DoorService.*;
import com.nokia.wap.server.*;
import samples.WMLTool;
if (pin > 0)
{
response.append("Welcome, the current PIN to this
door is:");
response.append(pin);
}
else
{
response.append("Sorry, correct PIN can not be
provided now.");
}
deck.getCard(0).add(new WMLTool.Paragraph(response));
res.setContentType(WMLTool.WML_MIME_TYPE);
res.getWriter().print(deck);
res.getWriter().close();
}
}
The following chapter describes in more detail the interfaces used in the sample.
The Nokia WAP Server APIs have been designed to make service authoring easier and to
reduce the learning effort required of web service developers. Developers familiar with
Java Servlet programming for web servers can get into WAP development directly. The
Java Servlet concept is also open for additional functionality. When needs for more
advanced WAP services occur, an existing servlet can be extended to use the additional
services available in the WAP Service API, which has been desiged to provide
developers with an opportunity to use the full potential of WAP.
The following figure shows the logical groups of the interfaces that are available for
servlet authoring.
Servlets
WAP
interfaces
Servlet
Application
Java Servlet API. A set of standard interfaces defined by Sun that are implemented by
the Nokia WAP Server and used by the WAP services.
WAP Service API. A set of Nokia WAP Server-specific interfaces that provide access to
advanced information and functionality in the Nokia WAP Server. The interfaces are
implemented by the Nokia WAP Server and used by the WAP services.
Server Extension API. A set of interfaces defined by the Nokia WAP Server. A servlet
may provide an implementation of one of the defined interfaces and thus customize
the server operation to meet specific needs. These servlets are called Server extensions.
Servlet. A standard Java interface that must be implemented by all servlets. The
Interface is defined as part of the Java Servlet API.
AckListener may be implemented by a servlet in order to get detailed information
about the response status. This interface is defined as part of the WAP Service API.
Server Management API is a programming interface that provides e.g. servlet
installation and configuration services to allow e.g. installation program creation for
WAP services written as servlets. In practice, that can be implemented as a script that
utilises the commands available via the Nokia WAP Server Command Prompt [see
details of the use of the Command Prompt in the Nokia WAP Server Administration
Guide].The following sections present the interfaces, their purpose and the
functionality of each interface.
Interfaces and classes in the Java Servlet API 2.0 that can be used directly from the
javax.servlet.http package:
Class Cookie // Can be used as such from
javax.servlet.http
Class HttpUtils // Can be used as such from
New interfaces may be added in the future releases of the Nokia WAP Server. For a
detailed description of the above mentioned interfaces, see the enclosed Nokia WAP
Server API Reference.
3 When an event to be written to the access log occurs inside the Nokia WAP Server,
the logAccess() method of the registered interface is called and the server
extension has all the information there is in the access log entry.
4 The Nokia WAP Server never calls the service() method of the servlet if there
is no URL mapping defined for the servlet.
If a servlet wants to use a server extension, the
com.nokia.wap.server.WapServer interface provides methods for locating
an implementation.
For each interface, it is defined whether there can be several registered
implementations.
The following interfaces have been defined for the Nokia WAP Server 1.0 release:
Interface Purpose
AccessLogWriter Provides a customized log writer for access
information. Can be used to e.g. collect
billing information.
AlarmHandler Enables an extension to receive and handle
alarms generated in the Nokia WAP Server.
Using this interface, a WAP Server
extension can integrate to existing alarm
management software.
For a detailed description of the interfaces, see the enclosed Nokia WAP Server API
reference.
import javax.servlet.*;
import com.nokia.wap.server.*;
import com.bcomp.billing.*;
billSystem.loginAsRecordCreator(config.getInitParameter("BFo
rmat"));
// AccessLogWriter methods
br.setSelector(GetServiceName(entry.getRequestedUrl()));
billSystem.commit(br);
}
}
This chapter gives a more technical description of the dynamics of a servlet in the
Nokia WAP Server.
WAP Request :
method, URL,
headers, request data WAP Response :
status, response data,
response headers
Nokia WAP Server init()
service()
Servlet
destroy()
After the loading, the following three main methods are involved in the life cycle of the
servlet:
Servlets are activated by the Nokia WAP Server through an init() call. Servlets are
likely to provide their own implementation of this method to perform the possibly slow
and costly initialization of the servlet only once, rather than once per request. With the
init() call, the servlet receives the configuration information
(ServletConfig). The Nokia WAP Server provides a user interface for editing and
maintaining these configuration settings.
After the initialization, the servlets handle many requests. Each terminal request
generates one service() method call. These requests can be concurrent.
The request processing goes on until the Nokia WAP Server explicitly shuts down the
servlet by calling the destroy() method.
The Nokia WAP Server provides a "reload servlet" functionality for the administrator.
The servlets see this as a destroy() call for the current servlet instance, followed by
the creation of a new instance and an init() call for it. If the configuration of the
servlet is changed, the updated configuration is provided in the init() call for the
new instance.
5.2 Security
The Nokia WAP Server is responsible for an end-to-end security solution for the
servlets. The Nokia WAP Server takes care of all the security issues and a servlet does
not have to implement anything in order to be accessed securely. This chapter describes
how a servlet can know the level of security and the authentication method that the
Nokia WAP Server has used to identify the servlet user.
The Nokia WAP Server also has access control features that are not visible to the
servlets. These features contain URL based access control and terminal access control.
Terminal access control means that the Nokia WAP Server can be accessed only with
defined terminals. For a detailed description of the Nokia WAP Server security and
access control features, see the Nokia WAP Server product information.
When the WTLS protocol is used, HTTP proxy authentication is a very reliable way of
authenticating users.
If a servlet requires separate user authentication, it may use the HTTP authentication
for its own purposes. For details, see [4].
■ WAP Protocol error. Delivering the data fails due to networking problems,
terminal out of battery power, failed security, etc.
5.5 Performance
A Nokia WAP Server servlet is a fast way to provide a response to a request. This is
because servlets run in the same process context as the Nokia WAP Server. Activating a
servlet requires only a lightweight thread context switch for the Nokia WAP Server. On
the other hand, the WAP protocol processing, content encoding and other Nokia WAP
Server functionality require processor time. Thus, WAP services requiring a lot of
processing power should be placed on another machine if the number of requests is
great. For that kind of services, servlets are more like WAP connectors than standalone
WAP applications.
5.5.1 Threading
Servlets run in the same process as the Nokia WAP Server. When several clients try to
use the servlet simultaneously, the service() method is called by several threads
concurrently. The servlet should itself protect class specific data and other necessary
resources from concurrent access.
If the servlet is not prepared for concurrent use, it should implement the
SingleThreadModel interface. This ensures that the Nokia WAP Server will call
the service() method of the servlet only from one single thread.
■ Servlet chaining. The Nokia WAP Server supports servlet chaining, which is an
easy way to link several servlets to process a WAP terminal's request.
■ MIME type mapping. The Nokia WAP Server supports mapping of MIME types to
specific servlets to perform postprocessing of predefined content types returned by
e.g. another servlet or origin server.
■ Locating other servlets via ServletContext. Servlets can locate other servlets via
Java Servlet API's ServletContext to perform specific tasks.
■ Locating server extensions. Finally, servlets can utilise server extensions, which
are servlets implemented by the developer to enhance the Nokia WAP Server's
functionality to serve specific needs.
The following sections describe the techniques in further detail.
ServletRequest
Application server
Preprocessor
HTTP request
Connector
HTTP response
ServletResponse
Postprocessor
The Nokia WAP Server 1.0 does not provide an administration interface for configuring
servlet chains, but you can easily configure them by editing the configuration files
located in the [installation directory]\config directory.
NOTE: The Nokia WAP Server MUST NOT be running when editing the configuration
files. You must shut down the Nokia WAP Server before you edit the configuration
files and you must restart it after you have configured all the configuration files.
Syntax:
urlmap.total=[total number of the url mappings]
urlmap.[number].name=[servlet name]
urlmap.[number].url=[url mapping]
Example:
urlmap.total=4
urlmap.1.name=FileServlet
urlmap.1.url=http\://yourdomain/file/
urlmap.2.name=HelloWorld
urlmap.2.url=http\://yourdomain/helloworld/
urlmap.3.name=FilterSample,HeaderSample
urlmap.3.url=http\://yourdomain/myfirstchain/
urlmap.4.name=HTTPManager
urlmap.4.url=http\://
Syntax:
mimetypemap.total=[total number of the filter mappings]
mimetypemap.[number].filter=[filter name]
mimetypemap.[number].mimeType=[mime type]
Example:
mimetypemap.total=1
mimetypemap.1.filter=jsp
mimetypemap.1.mimeType=java-internal/java-html
NOTE: The Nokia WAP Server MUST NOT be running when you are editing the
configuration files. You must shut down the Nokia WAP Server before you edit
configuration files and restart it after all the configuration files are configured.
Locating servlets via ServletContext One way to locate other servlets is to use the
ServletContext services in the Java
Servlet API. Once you have the servlet interface
of another servlet, the service method of
the located servlet can be called.
Note that the above samples are provided for learning purposes only. Samples, such as
the WMLTool, can be further developed to meet specific needs, but no official support
or maintenance is provided for the samples.
Note that all WAP terminals may not support WMLScripts or bitmaps. In addition to
these, some more specialised content types can be accepted:
When a request comes to the Nokia WAP Server, it adds some accepted content types
to the request before forwarding it to the servlet. The following content types are
added:
In addition to these, the MIME types defined in the MIME type mapping (see 5.6.2) are
added to the request's accept header.
Terminals may accept multipart content types. If a servlet replies with a multipart
response containing e.g. textual wml and textual wmlscript, the Nokia WAP Server can
correctly encode the individual subparts with the appropriate encoder.
Note that the WAP protocols and the Nokia WAP Server can be used to deliver any
content type to the WAP terminal. So, the Nokia WAP Server's content delivering
ability is not limited to WAP content types.
The WAP/WSP protocol is essentially a binary form of HTTP/1.1. The Nokia WAP Server
provides a complete implementation of the Java Servlet API 2.0, and existing servlets
can be run directly on the Nokia WAP Server. There are some basic differences in the
underlying WAP protocols that may affect WAP service development when the Java
Servlet API is used.
This chapter describes the biggest differences at the WAP and HTTP concept level. The
enclosed Nokia WAP Server API Reference in the [installation
directory]\docs directory contains notes about the notable differences between
implementing servlets for WAP and for HTTP.
Terminal Server
Invoke
1
Result
2
Ack
3
This has some effects on the behaviour of the servlets using the Java Servlet API.
InputStream. When the input stream is being read, the actual data is already in the
Nokia WAP Server and thus reading from the stream is fast.
OutputStream. The servlet creates its output by writing to the ServletOutputStream
object. The output stream provided by the Nokia WAP Server is not a stream to the
terminal, instead it is a memory-based stream that is copied to a WSP protocol
message after the service() and sent to the terminal with the Response part of the WTP
protocol. Sending the response starts after the service() method has returned.
Calling os.close() or os.flush() in service() are ignored by the Nokia
WAP Server.
Response Headers. There is a fixed place in the WSP protocol for sending the HTTP
headers in encoded format and for the status code. Sending the HTTP headers starts
after the service() method has returned. The limitations defined in the Java
Servlet API for setting all the headers and status code before writing the response body
thus do not apply in the Nokia WAP Server, but it is recommended that you follow the
instructions.
API has no way of getting information about if the response was delivered or not. This
also applies to origin server-based architecture: the origin server has no means of
getting information about whether the response was delivered to the WAP terminal or
not. Often, however, this is an important requirement in order to ensure consistency of
a business process (e.g. to make sure that an assignment to a field worker was
delivered to the WAP terminal) or to establish accurate billing procedures (a customer
is charged only for successful service transactions).
The Nokia WAP Server defines an AckListener interface, which can be
implemented by a servlet that requires the response delivery status information.
Servlets willing to receive this information must provide their AckListener
interface to the Nokia WAP Server during the servlet.init() method through
the com.nokia.wap.server.WapServer interface that can be retrieved via
ServletContext.getAttribute(). The Nokia WAP Server will then during
the response delivery provide information to the servlet about the status of the delivery
with the following functions:
■ AckListener.ResponseError(reasonClass, reasonCode,
ServletRequest, ServletResponse) to inform that the response was
not delivered to terminal, because the transaction has been aborted by the
terminal or by the Nokia WAP Server. If the terminal is out of coverage, out of
battery power or inaccessible for some other reason, the response delivery is
aborted by the Nokia WAP Server due to timeout in the WTP protocol.
■ AckListener.ResponseConfirmed(String ackHeaders,
ServletRequest, ServletResponse) to inform that the response was
successfully delivered to the terminal and the terminal has acknowledged it.
The ServletRequest and ServletResponse are the same objects that were
given to the servlet in the servlet.service() call.
WSP requests made using the connectionless WSP protocol are never confirmed or
aborted by the Nokia WAP Server.
For details, see the Nokia WAP Server API Reference.
Aborting a request. A servlet can also choose to abort a request. If the request is
aborted, the terminal does not need to provide an acknowledgement and thus saves it
sending a datagram. The request aborting can be done with the WapRequest
interface in the Nokia WAP Service API.
Limited data capacity of terminals. Terminals are devices that often have limited
processing power and memory capacity. The WSP protocol provides session negotiation
where the terminal can express the maximum packet data size it can receive. If a
servlet tries to send a response that is known by the Nokia WAP Server to be too big,
an error page is returned to the terminal and the servlet is informed if it has registered
an AckListener interface. Note that size limitations apply to actual data content,
so if the servlet replies with a WML page, the limitation applies to the encoded WML
page. The defined maximum size of a WSP data unit for terminals is 1400 bytes.