javax.microedition.io

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.io 
javax.microedition.io
I/O and Networking for the MID Profile

MID Profile includes networking support based on the Generic Connection framework from the Connected, Limited Device Configuration.

HTTP Networking

In addition to the javax.microedition.io classes specified in the Connected Limited Device Configuration the Mobile Information Device Profile includes the following interface for the HTTP access. An HttpConnection is returned from Connector.open() when an "http://" connection string is accessed.

  • javax.microedition.io.HttpConnection

The MIDP extends the connectivity support provided by the Connected, Limited Device Configuration (CLDC) with specific functionality for the GenericConnection framework. The MIDP supports a subset of the HTTP protocol, which can be implemented using both IP protocols such as TCP/IP and non-IP protocols such as WAP and i-Mode, utilizing a gateway to provide access to HTTP servers on the Internet.

The GenericConnection framework is used to support client-server and datagram networks. Using only the protocols specified by the MIDP will allow the application to be portable to all MIDs. MIDP implementations MUST provide support for accessing HTTP 1.1 servers and services.

There are wide variations in wireless networks. It is the joint responsibility of the device and the wireless network to provide the application service. It may require a gateway that can bridge between the wireless transports specific to the network and the wired Internet. The client application and the Internet server MUST NOT need to be required to know either that non-IP networks are being used or the characteristics of those networks. While the client and server MAY both take advantage of such knowledge to optimize their transmissions, they MUST NOT be required to do so.

For example, a MID MAY have no in-device support for the Internet Protocol (IP). In this case, it would utilize a gateway to access the Internet, and the gateway would be responsible for some services, such as DNS name resolution for Internet URLs. The device and network may define and implement security and network access policies that restrict access.

HTTP Network Connection

The GenericConnection framework from the CLDC provides the base stream and content interfaces. The interface HttpConnection provides the additional functionality needed to set request headers, parse response headers, and perform other HTTP specific functions.

The interface MUST support:

HTTP 1.1

Each device implementing the MIDP MUST support opening connections using the following URL schemes (RFC2396 Uniform Resource Identifiers (URI): Generic Syntax)

"http" as defined by RFC2616 Hypertext Transfer Protocol -- HTTP/1.1

Each device implementing the MIDP MUST support the full specification of RFC2616
HEAD, GET and POST requests. The implementation MUST also support the absolute forms of URIs.

The implementation MUST pass all request headers supplied by the application and response headers as supplied by the network server. The ordering of request and response headers MAY be changed. While the headers may be transformed in transit, they MUST be reconstructed as equivalent headers on the device and server. Any transformations MUST be transparent to the application and origin server. The HTTP implementation does not automatically include any headers. The application itself is responsible for setting any request headers that it needs.

Connections may be implemented with any suitable protocol providing the ability to reliably transport the HTTP headers and data.(RFC2616 takes great care to not to mandate TCP streams as the only required transport mechanism.)

HTTP Request Headers

The HTTP 1.1 specification provides a rich set of request and response headers that allow the application to negotiate the form, format, language, and other attributes of the content retrieved. In the MIDP, the application is responsible for selection and processing of request and response headers. Only the User-Agent header is described in detail. Any other header that is mutually agreed upon with the server may be used.

User-Agent and Accept-Language Request Headers

For the MIDP, a simple User-Agent field may be used to identify the current device. As specified by RFC2616, the field contains blank separated features where the feature contains a name and optional version number.

The application is responsible for formatting and requesting that the User-Agent field be included in HTTP requests via the setRequestProperty method in the interface javax.microedition.io.HttpConnection. It can supply any application-specific features that are appropriate, in addition to any of the profile-specific request header values listed below.

Applications are not required to be loaded onto the device using HTTP. But if they are, then the User-Agent request header should be included in requests to load an application descriptor or application JAR file onto the device. This will allow the server to provide the most appropriate application for the device.

The user-agent and accept-language fields SHOULD contain the following features as defined by system properties using java.lang.System.getProperty. If multiple values are present they will need to be reformatted into individual fields in the request header.

System Properties Used for User-Agent and Accept-Language Request Headers

System Property

Description

microedition.profiles

A blank (Unicode U+0020) separated list of the J2ME profiles that this device supports. For MIDP devices, this property MUST contain at least "MIDP-2.0".

microedition.configuration

The J2ME configuration supported by this device.

For example, "CLDC-1.0."

microedition.locale

The name of the current locale on this device.

For example, "en-US."

HTTP Request Header Example

User-Agent: Profile/MIDP-2.1 Configuration/CLDC-1.0
Accept-Language: en-US

StreamConnection Behavior

All MIDP StreamConnections have one underlying InputStream and one OutputStream. Opening a DataInputStream counts as opening an InputStream and opening a DataOutputStream counts as opening an OutputStream. Trying to open another InputStream or another OutputStream from a StreamConnections causes an IOException. Trying to open InputStream or OutputStream after they have been closed causes an IOException.

After calling the close method, regardless of open streams, further method calls to connection will result in IOExceptions for those methods that are declared to throw IOExceptions. For the methods that do not throw exceptions, unknown results may be returned.

The methods of StreamConnections are not synchronized. The only stream method that can be called safely in another thread is close. When close is invoked on a stream that is executing in another thread, any pending I/O method MUST throw an InterruptedIOException. In the above case implementations SHOULD try to throw the exception in a timely manner. When all open streams have been closed, and when the StreamConnections is closed, any pending I/O operations MUST be interrupted in a timely manner.

Secure Networking

Since the MIDP release additional interfaces are available for secure communication with WWW network services. Secure interfaces are provided by HTTPS and SSL/TLS protocol access over the IP network. Refer to the package documentation of javax.microedition.pki for the details of certificate profile that applies to secure connections. An HttpsConnection is returned from Connector.open() when an "https://" connection string is accessed. A SecureConnection is returned from Connector.open() when an "ssl://" connection string is accessed.

  • javax.microedition.io.HttpsConnection
  • javax.microedition.io.SecureConnection
  • javax.microedition.io.SecurityInfo
  • javax.microedition.pki.Certificate
  • javax.microedition.pki.CertificateException

Low Level IP Networking

Since the MIDP release, the MIDP specification also includes optional networking support for TCP/IP sockets and UDP/IP datagrams. For each of the following schemes, a host is specified for an outbound connection and the host is omitted for an inbound connection. The host can be a host name, a literal IPv4 address or a literal IPv6 address (according to RFC2732 square bracket characters '[' ']' may be used to designate an IPv6 address in URL strings). Implementations MUST be able to parse the URL string and recognize the address format used, but are not required to support all address formats and associated protocols.

When the host and port number are both omitted from the socket or datagram connection, the system will allocate an available port. The host and port numbers allocated in this fashion can be discovered using the getLocalAddress and getLocalPort methods. The colon (:) may be omitted when the connection string does not include the port parameter.

A SocketConnection is returned from Connector.open() when a "socket://host:port" connection string is accessed. A ServerSocketConnection is returned from Connector.open() when a "socket://:port" connection string is accessed. A UDPDatagramConnection is returned from Connector.open() when a "datagram://host:port" connection string is accessed.

  • javax.microedition.io.SocketConnection
  • javax.microedition.io.ServerSocketConnection
  • javax.microedition.io.DatagramConnection
  • javax.microedition.io.Datagram
  • javax.microedition.io.UDPDatagramConnection

Push Applications

A PushRegistry is available in the MIDP release which provides a MIDlet with a means of registering for network connection events, which may be delivered when the application is not currently running.

  • javax.microedition.io.PushRegistry

Serial Port Communications

A CommConnection is available in the MIDP release which provides a MIDlet with a means of registering for network accessing a local serial port as a stream connection.

  • javax.microedition.io.CommConnection

Security of Networking Functions

The security model is found in the package javax.microedition.midlet and provides a framework that allows APIs and functions to be restricted to MIDlet suites that have been granted permissions either by signing or explicitly by the user. (See Security for MIDlet suites for details about granting specific permissions to a MIDlet suite.)

The risks associated with a MIDlet suite's use of the network are related the potential for network abuse and to costs to the device owner since network use may result in charges. MIDP provides a security framework in which network functions can be protected and allowed only to those applications that have requested and been granted appropriate permissions.

Each protocol is accessed by invoking javax.microedition.io.Connector.open with a URI including the protocol and arguments. The permissions below allow access to be granted individually to protocols. The functionality of the protocols is specified by subclasses of Connection interface that defines the syntax of the URI and any protocol specific methods. Devices are NOT REQUIRED to implement every protocol. If a protocol is implemented, the security framework specifies the naming of permissions according to the package and class name of the APIs used to access the protocol extended with the protocol name. The API providing access is javax.microedition.io.Connector.open. The table below defines the corresponding permissions for the protocols defined within this specification.

Permission

Protocol

javax.microedition.io.Connector.http

http

javax.microedition.io.Connector.https

https

javax.microedition.io.Connector.datagram

datagram

javax.microedition.io.Connector.datagramreceiver

datagram server (without host)

javax.microedition.io.Connector.socket

socket

javax.microedition.io.Connector.serversocket

server socket (without host)

javax.microedition.io.Connector.ssl

ssl

javax.microedition.io.Connector.comm

comm

Security of PushRegistry

The PushRegistry is protected using the security framework and permissions. The MIDlet suite must have the javax.microedition.io.PushRegistry permission to register an alarm based launch, to register dynamically using the PushRegistry, to make a static registration in the application descriptor and to determine if the user needs to be prompted prior to invoking MIDlet suite in response to a Push connection event or alarm. The protection domain defines the general behavior for user permissions with the interaction modes of "oneshot", "session", and "blanket". For the PushRegistry and the AMS, launching behavior is specialized:

  • Oneshot: The user is prompted before the MIDlet suite is invoked to handle a push event or alarm and for each PushRegistry request; for example to register an alarm or a connection.
  • Session: The user is prompted before the MIDlet suite is invoked to handle a push event or alarm, or before the first PushRegistry request; for example to register an alarm or a connection. Subsequently, when a MIDlet uses the PushRegistry the user is not prompted.
  • Blanket: The user is prompted only once during installation, before the first time the MIDlet suite is invoked to handle a push event or alarm, or uses the PushRegistry.

The push mechanism uses protocols in which the device is acting as the server and connections can be accepted from other elements of the network. To use the push mechanisms the MIDlet suite will need the permission to use the server connection. For example, to register a chat program that can be started via push might use the following attributes in the manifest:

MIDlet-Push-1: socket://:79, com.sun.example.SampleChat, *
MIDlet-Permissions: javax.microedition.io.PushRegistry, javax.microedition.io.Connector.serversocket
     
@since MIDP 1.0
Java Source File NameTypeComment
CommConnection.javaInterface This interface defines a logical serial port connection. A "logical" serial port is defined as a logical connection through which bytes are transferring serially.
Connection.javaInterface This is the most basic type of generic connection.
ConnectionNotFoundException.javaClass This class is used to signal that a connection target cannot be found, or the protocol type is not supported.
Connector.javaClass This class is factory for creating new Connection objects.

The creation of Connections is performed dynamically by looking up a protocol implementation class whose name is formed from the platform name (read from a system property) and the protocol name of the requested connection (extracted from the parameter string supplied by the application programmer.) The parameter string that describes the target should conform to the URL format as described in RFC 2396. This takes the general form:

{scheme}:[{target}][{params}]

where {scheme} is the name of a protocol such as http}.

The {target} is normally some kind of network address.

Any {params} are formed as a series of equates of the form ";x=y".

ContentConnection.javaInterface This interface defines the stream connection over which content is passed.
Datagram.javaInterface This class defines an abstract interface for datagram packets. The implementations of this interface hold data to be sent or received from a DatagramConnection object.

Since this is an interface class, the internal structure of the datagram packets is not defined here.

DatagramConnection.javaInterface This interface defines the capabilities that a datagram connection must have.

Reminder: Since the CLDC Specification does not define any actual network protocol implementations, the syntax for datagram addressing is not defined in the CLDC Specification. Rather, syntax definition takes place at the level of J2ME profiles such as MIDP.

In the sample implementation that is provided as part of the CLDC implementation, the following addressing scheme is used:

The parameter string describing the target of a connection in the CLDC implementation takes the following form:

 {protocol}://[{host}]:[{port}]
 
A datagram connection can be opened in a "client" mode or "server" mode. If the "//{host}" part is missing then the connection is opened as a "server" (by "server", we mean that a client application initiates communication).
HttpConnection.javaInterface This interface defines the necessary methods and constants for an HTTP connection.

HTTP is a request-response protocol in which the parameters of request must be set before the request is sent. The connection exists in one of three states:

  • Setup, in which the request parameters can be set
  • Connected, in which request parameters have been sent and the response is expected
  • Closed, the final state, in which the HTTP connection as been terminated
The following methods may be invoked only in the Setup state:
  • setRequestMethod
  • setRequestProperty
The transition from Setup to Connected is caused by any method that requires data to be sent to or received from the server.
HttpsConnection.javaInterface This interface defines the necessary methods and constants to establish a secure network connection. The URI format with scheme https when passed to Connector.open will return a HttpsConnection. RFC 2818 defines the scheme.

A secure connection MUST be implemented by one or more of the following specifications:

HTTPS is the secure version of HTTP (IETF RFC2616), a request-response protocol in which the parameters of the request must be set before the request is sent.

In addition to the normal IOExceptions that may occur during invocation of the various methods that cause a transition to the Connected state, CertificateException (a subtype of IOException) may be thrown to indicate various failures related to establishing the secure link.

InputConnection.javaInterface This interface defines the capabilities that an input stream connection must have.
OutputConnection.javaInterface This interface defines the capabilities that an output stream connection must have.
PushRegistry.javaClass The PushRegistry maintains a list of inbound connections.
SecureConnection.javaInterface This interface defines the secure socket stream connection. A secure connection is established using Connector.open with the scheme "ssl" and the secure connection is established before open returns. If the secure connection cannot be established due to errors related to certificates a CertificateException is thrown.

A secure socket is accessed using a generic connection string with an explicit host and port number.

SecurityInfo.javaInterface This interface defines methods to access information about a secure network connection. Protocols that implement secure connections may use this interface to report the security parameters of the connection.

It provides the certificate, protocol, version, and cipher suite, etc.

ServerSocketConnection.javaInterface This interface defines the server socket stream connection.

A server socket is accessed using a generic connection string with the host omitted.

SocketConnection.javaInterface This interface defines the socket stream connection.

A socket is accessed using a generic connection string with an explicit host and port number.

StreamConnection.javaInterface This interface defines the capabilities that a stream connection must have.

In a typical implementation of this interface (for instance in MIDP), all StreamConnections have one underlying InputStream and one OutputStream. Opening a DataInputStream counts as opening an InputStream and opening a DataOutputStream counts as opening an OutputStream.

StreamConnectionNotifier.javaInterface This interface defines the capabilities that a connection notifier must have.
TestResourceLimit.javaClass
UDPDatagramConnection.javaInterface This interface defines a datagram connection which knows it's local end point address. The protocol is transaction oriented, and delivery and duplicate protection are not guaranteed.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.