Home
| | Sitemap
||Page number :13
Programmer's Guide Nokia WAP Server API 1.1 page 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
previous || guide home || next
5.4 Error handling
Like all programming, WAP programming must also handle errors. In WAP servlet programming, errors can occur in various phases of the processing. This section outlines the error types, defines the Nokia WAP Server behaviour in these situations and suggests how the servlets should handle errors.
- Service error. The servlet detects that there is an error, and the requested service can not be provided to the terminal user. E.g. there is insufficient input for the service or a broken database connection.
- Servlet error. The servlet works incorrectly, e.g. creates an invalid WML page, provides content type that is not supported by the terminal, provides content too large for the terminal, or the servlet goes into an infinite loop.
- Nokia WAP Server error. The WAP Server fails to convert, encode or deliver the given content.
- Servlets in the Nokia WAP Server
- WAP Protocol error. Delivering the data fails due to networking problems, terminal out of battery power, failed security, etc.
5.4.1 Service errors
Service errors are handled in WAP as they are handled in HTTP. A servlet should use either HttpServletResponse.sendError(code, msg) with the appropriate HTTP status code. If msg is provided, it is sent in a WML page to the terminal. The code is one of the SC_* error status codes defined in the HttpServletResponse. The servlet should use an error code from the 400 range of HTTP error codes.
The servlet can also decide to report a service error with an SC_OK status and provide a WML page describing the problem.
5.4.2 Servlet errors
These errors are detected by the Nokia WAP Server. The request is responded with an HTTP status code from the 500 range, and the servlet is provided the information via the AckListener interface if it has been registered.
If the servlet uses too much time for the service() call, the Nokia WAP Server will terminate the request processing, unload the servlet and then reload and initialise it again. The interrupted request is returned to the terminal with an SC_GATEWAY_TIMEOUTstatus.
The servlet can throw a ServletException or IOException when service() is called. If the ServletException is thrown, the Nokia WAP Server sets the status of the response to SC_SERVICE_UNAVAILABLE. The AckListenerinterface is not called for service() calls that have thrown an exception.
5.4.3 Nokia WAP Server errors
If the Nokia WAP Server fails to convert, encode or deliver the given content, the request is responded to with an HTTP status code from the 500 range, and the servlet is provided with the information via the AckListenerinterface.
5.4.4 WAP protocol error
If the delivery of the content fails at the protocol level (timeout, communication error), the servlet will be informed in case it has registered an AckListenerinterface. This applies to requests made using the connection-oriented WSP protocol. When the connectionless WSP protocol is used, these errors are never delivered to the servlet.
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.
Programmer's Guide Nokia WAP Server API 1.1 page 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
previous || guide home || next