Contents Previous Next Index

Chapter   8

Networking


This chapter describes porting and customizing the networking protocols of the MIDP Reference Implementation: HTTP, HTTPS, comm, Socket, Server Socket and UDP Datagram. The protocols are built on the Generic Connection Framework of CLDC, defined in the specification from the “J2ME™ Connected, Limited Device Configuration” (JSR-000030). For more information on CLDC, see
http://jcp.org/jsr/detail/30.jsp.

The networking protocols implementation has both a native layer and a Java™ programming language layer (Java layer). This chapter covers the layers in the sections:

Many files make up the networking implementation; they are listed in the sections below. Note that the MIDP 2.0 Specification requires support for HTTP and HTTPS, but it only recommends support for datagram connections, server socket stream connections, socket stream connections, and secure socket stream connections. If your port does not support one or more of the recommended protocols, you can remove its associated files to improve the footprint of your implementation. There is one exception: do not remove the com.sun.midp.ssl package. Deleting it will break the implementation of PKI secured permissions on signed JAR files.

In addition to porting the protocols in the MIDP Reference Implementation you can add other network protocols. For example, if you add support for the “Wireless Messaging API” (JSR-000120) to your MIDP port, you would add SMS (Short Message Service) and CBS (cell broadcast message) protocols.

8.1 Porting the Native Layer

Native code provides IP networking support. The socket and datagram implementations for the Windows 2000 operating system and the Solaris™ Operating Environment (OE) are very similar. They share the following files, which assume a Posix layer for the networking calls to socket, connect, bind, and so on. You will need to reimplement the functionality in these files if the networking on your device is not Posix based.

The MIDP Reference Implementation also has a set of native files that mediate between the Java layer and the shared files in the native layer. The code in the files handles arguments and checks parameters. The platform-specific files are:

8.2 Customizing the Java Layer

This section provides a high-level description of the Java layer of the networking code. It points out places where you could get improved performance or footprint by re-implementing the functionality in native code, and places where such replacement would probably not provide much improvement. It has the sections:

8.2.1 Generic Connections

The CLDC 1.0 Specification establishes the basic architecture for all stream based IO connections. The architecture is called the Generic Connection Framework (GCF). The architecture is both compact and extensible. A single class, Connector, is a factory for specific protocol handlers.

The MIDP reference implementation adds classes that handle the fundamental capabilities of generic connections.

These are Java programming language implementations of high level stream handling code. Although you could replace some of this functionality with native code, there might not be a significant savings in footprint or performance.

8.2.2 Comm

The Comm protocol provides a way to access external devices using a local serial port as a stream connection. The MIDP Reference Implementation implements the comm protocol in the following classes:

These classes should not need to be changed when you port the MIDP Reference Implementation to a new device.

8.2.3 IP Support

The MIDP Reference Implementation uses the following classes to provide IP networking support:

These classes should not need to be changed when you port the MIDP Reference Implementation to a new device.

8.2.4 Secure Connections

The following interfaces in the MIDP 2.0 Specification define the secure connection functionality:

The definition also includes the class javax.microedition.pki.CertificateException

According to the MIDP 2.0 Specification, a secure connection must implement one or more of the following specifications:

The MIDP Reference Implementation uses the following classes to provide Secure Socket Layer (SSL) functionality:

The interfaces and classes above support the HTTPS protocol and network connections that have URIs beginning with ssl://host:port. (For more information on HTTPS, see Section 8.2.6 "HTTPS" .) The SSL functionality also supports the PKI secured permissions on signed JAR files. (See Chapter 7, "Security” for more information on signed JAR files and other security topics.)

If your device will provide a secure connection using a different specification, do not remove the com.sun.midp.ssl package. Deleting it will break the implementation of PKI secured permissions on signed JAR files.

8.2.5 HTTP 1.1

The MIDP Reference Implementation implements the HTTP 1.1 protocol atop its socket URL support. (See Section 8.2.3 "IP Support" for more information.) The HTTP 1.1 implementation is in the following Java classes:

This organization provides for maximum portability but might not provide the most optimum performance or size. If your device has a native implementation of HTTP, you might gain efficiency if you change the classes to take advantage of your device’s native functionality.

8.2.5.1 HTTP Requests Using Proxies

A high level feature in the com.sun.midp.io.j2me.http.Protocol class is making requests through a proxy server. The implementation requires that HTTP proxy servers support the generic tunneling mechanism for TCP based protocols through Web proxy servers. See the following documents for more information on HTTP tunneling:

If you modify the HTTP implementation to be layered on top of a WAP Gateway, the WAP Gateway would replace the proxy access. Replace the references to a generic HTTP proxy with calls to a native WSP stack.

(To have the device emulator use a proxy server, set the com.sun.midp.io.http.proxy configuration parameter. See Using MIDP for more information.)

8.2.5.2 HTTP1.1 Persistent Connections

The MIDP 2.0 Specification supports HTTP 1.1 persistent connections. Do not change the implementation to include only HTTP 1.0 connection behavior. Persistent connections are important because they:

Persistent connections have many advantages, but on small devices with limited resources they can be a problem if they are not closed properly. The MIDP Reference Implementation uses the value of the configuration property com.sun.midp.io.http.persistent_connection_linger_time, set in com/sun/midp/io/j2me/http/Protocol.java, as the time that a connection can remain open and unused. Its default is 60000 ms. (60 seconds). Once the time limit is exceeded, the MIDP Reference Implementation closes the connection and removes it from the connection pool. (See Using MIDP for the location of the property in the midp executable’s configuration files.)

8.2.6 HTTPS

The MIDP 2.0 Specification requires a secure HTTP (HTTPS) connection be compliant one or more of the following specifications:

The HTTPS implementation in the MIDP Reference Implementation is built on top of HTTP. (See "HTTP 1.1" for more information.) It uses the secure socket layer (SSL) implementation to make secure connections, and uses the implementation of the SecureConnection for all certificate handling and data encryption. (See Section 8.2.4 "Secure Connections" for more information on SSL and on SecureConnection.)

The MIDP Reference Implementation implements HTTPS with the following Java classes:

The implementation of HTTPS does not expose an API to control the handshake listener. Exposing such an API would allow certain certificate errors to be over-ridden by higher level applications. It should not be possible for an end-user to override policy decisions about expired certificates. (Not exporting this API is compliant with the MIDP 2.0 Specification.)

The organization of the Java layer for HTTPS provides for maximum portability but might not provide the most optimum performance or size. If your device has a native implementation of HTTPS, you might gain efficiency if you change the classes to take advantage of your device’s native functionality. To replace the entire HTTPS implementation, replace the com.sun.midp.io.j2me.https package.

8.2.7 Internal Utilities

The MIDP Reference Implementation implements the following utilities in the Java programming language:

They should not need to be changed when the MIDP Reference Implementation is ported to a new device.

 


Contents Previous Next Index Porting MIDP
MIDP Reference Implementation, Version 2.0 FCS