example.http
Class HttpExample

java.lang.Object
  extended by javax.microedition.midlet.MIDlet
      extended by example.http.HttpExample
All Implemented Interfaces:
java.lang.Runnable

public class HttpExample
extends javax.microedition.midlet.MIDlet
implements java.lang.Runnable

sample http example MIDlet.


Field Summary
(package private)  java.lang.StringBuffer buffer
          string buffer for assembling HTTP requests.
(package private)  javax.microedition.lcdui.Form form
          user interface screen for displaying progress gauge.
(package private)  javax.microedition.lcdui.Gauge gauge
          user interface component for displaying network progress.
(package private)  java.lang.String url
          example URL for HTTP GET
 
Constructor Summary
HttpExample()
          Create the progress form and gauge.
 
Method Summary
 void destroyApp(boolean unconditional)
          Destroy must cleanup everything.
(package private)  void getViaContentConnection(java.lang.String url)
          Simple read of a url using ContentConnection.
(package private)  void getViaHttpConnection(java.lang.String url)
          Read the HTTP headers and the data using HttpConnection.
(package private)  void getViaStreamConnection(java.lang.String url)
          Simple read of a url using StreamConnection.
 void pauseApp()
          Pause, discontinue with the http tests
(package private)  void postViaHttpConnection(java.lang.String url)
          Post a request with some headers and content to the server and process the headers and content.
(package private)  void process(byte b)
          Process the data one character at a time.
(package private)  void process(byte[] b)
          Process the data from the array.
(package private)  void processType(java.lang.String type)
          Process the type.
 void run()
          Run the examples.
(package private)  void setRequestHeaders(javax.microedition.io.HttpConnection c)
          Add request properties for the configuration, profiles, and locale of this system.
 void startApp()
          Start a thread to run the examples.
 
Methods inherited from class javax.microedition.midlet.MIDlet
checkPermission, getAppProperty, notifyDestroyed, notifyPaused, platformRequest, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

java.lang.String url
example URL for HTTP GET


buffer

java.lang.StringBuffer buffer
string buffer for assembling HTTP requests.


gauge

javax.microedition.lcdui.Gauge gauge
user interface component for displaying network progress.


form

javax.microedition.lcdui.Form form
user interface screen for displaying progress gauge.

Constructor Detail

HttpExample

public HttpExample()
Create the progress form and gauge. This program is not interactive, it will exit when done.

Method Detail

startApp

public void startApp()
Start a thread to run the examples.

Specified by:
startApp in class javax.microedition.midlet.MIDlet

run

public void run()
Run the examples.

Specified by:
run in interface java.lang.Runnable

pauseApp

public void pauseApp()
Pause, discontinue with the http tests

Specified by:
pauseApp in class javax.microedition.midlet.MIDlet

destroyApp

public void destroyApp(boolean unconditional)
Destroy must cleanup everything. The thread is signaled to stop and no result is produced.

Specified by:
destroyApp in class javax.microedition.midlet.MIDlet
Parameters:
unconditional - true if forced shutdown.

getViaStreamConnection

void getViaStreamConnection(java.lang.String url)
                      throws java.io.IOException
Simple read of a url using StreamConnection. No HTTP specific behavior is needed or used.

Connector.open is used to open url and a StreamConnection is returned. From the StreamConnection the InputStream is opened. It is used to read every character until end of file (-1). If an exception is thrown the connection and stream is closed.

Parameters:
url - the URL to process.
Throws:
java.io.IOException

getViaContentConnection

void getViaContentConnection(java.lang.String url)
                       throws java.io.IOException
Simple read of a url using ContentConnection. No HTTP specific behavior is needed or used.

Connector.open is used to open url and a ContentConnection is returned. The ContentConnection may be able to provide the length. If the length is available, it is used to read the data in bulk. From the StreamConnection the InputStream is opened. It is used to read every character until end of file (-1). If an exception is thrown the connection and stream is closed.

Parameters:
url - the URL to process.
Throws:
java.io.IOException

getViaHttpConnection

void getViaHttpConnection(java.lang.String url)
                    throws java.io.IOException
Read the HTTP headers and the data using HttpConnection. Check the response code to insure successful retrieval.

Connector.open is used to open url and a HttpConnection is returned. The HTTP headers are read and processed. If the length is available, it is used to read the data in bulk. From the HttpConnection the InputStream is opened. It is used to read every character until end of file (-1). If an exception is thrown the connection and stream is closed.

Parameters:
url - the URL to process.
Throws:
java.io.IOException

setRequestHeaders

void setRequestHeaders(javax.microedition.io.HttpConnection c)
                 throws java.io.IOException
Add request properties for the configuration, profiles, and locale of this system.

Parameters:
c - current HttpConnection to apply request headers
Throws:
java.io.IOException

postViaHttpConnection

void postViaHttpConnection(java.lang.String url)
                     throws java.io.IOException
Post a request with some headers and content to the server and process the headers and content.

Connector.open is used to open url and a HttpConnection is returned. The request method is set to POST and request headers set. A simple command is written and flushed. The HTTP headers are read and processed. If the length is available, it is used to read the data in bulk. From the StreamConnection the InputStream is opened. It is used to read every character until end of file (-1). If an exception is thrown the connection and stream is closed.

Parameters:
url - the URL to process.
Throws:
java.io.IOException

processType

void processType(java.lang.String type)
Process the type.

Parameters:
type - that type

process

void process(byte b)
Process the data one character at a time.

Parameters:
b - one byte of data

process

void process(byte[] b)
Process the data from the array.

Parameters:
b - an array of bytes.