Package com.motorola.oem.websession

Configure air link parameters associated/needed with an internet or MMS session; Trigger and perform OTA download of a new MIDlet.

See:
          Description

Interface Summary
WebSessionBrowserMsgListener A listener of browser message events.
 

Class Summary
OTADownload OTADownload API enables triggering OTA provisioning using the OTA Download start methods.
WebSession Holds internet configuration parameters associated/needed in a Web Session.
WebSessionManager WebSessionManager class provides a full control over the internet configuration.
 

Exception Summary
OTAException OTA API's specific exception.
WebSessionException WebSession API specific exception.
 

Package com.motorola.oem.websession Description

Configure air link parameters associated/needed with an internet or MMS session; Trigger and perform OTA download of a new MIDlet.

Example 1:

Update the standard Internet connection Web Session (for javax.microedition.io.* usage).

    import javax.microedition.io.*;
    import com.motorola.oem.*;

      public class WebSessionMIDlet extends MIDlet{
                ...
        public void startApp() {
                WebSession ws = new WebSession();
                ws.setSessionName("Java Session");
                ws.setProxy1("011.011.011.011");// gateway IP
                ws.setGprsApn("internet");
                ws.setGprsUserName("moto");
                ws.setGprsPassword("rola");

                try{
                    WebSessionManager.updateWebSession(ws, WebSessionManager.SESSION_INDEX_JAVA);
               }catch(WebSessionException e){
                   ...
               }
                ...
    }

          

Important WS that the User should configure is the MMS web session.
This will set the parameters for the next MMS send/receive. HomePage is a mandatory field for MMS Session.

Example 2:

MMS Web session.

   import com.motorola.oem.*;

        public class WebSessionMIDlet extends MIDlet{
                ...
        public void startApp() {
                WebSession ws = new WebSession();
                ws.setSessionName("Mms Session");
        ws.setHomePage("192.168.220.15/servlets/mms");
                ws.setProxy1("192.118.11.55");
                ws.setServiceType1(WebSession.SERVICE_TYPE_WAP);
                ws.setPort1(9201);
                ws.setServiceType2(WebSession.SERVICE_TYPE_WAP);
                ws.setGprsApn("wap.orange.co.il");
                ...
                try{
                    // Optional
                    WebSessionManager.updateWebSession(ws, WebSessionManager.SESSION_INDEX_MMS);
                }catch(WebSessionException oe){
                   ...
                    oe.printStackTrace();
                }

          

Example 3:

Add new user defined Internet connection Web Session.

   import javax.microedition.io.*;
   import com.motorola.oem.*;

     public class WebSessionMIDlet extends MIDlet{
        private  int UserSessionIndex;
                ...
        public void startApp() {
                WebSession ws = new WebSession();
                ws.setSessionName("User Session");
                ws.setProxy1 ("011.011.011.011");// gateway IP
                ws.setGprsApn ("internet");
                ws.setGprsUserName("moto");
                ws.setGprsPassword("rola");

                try{
                    // Optional(recommended) - Store session as a WebSession entry for a future use.
                    UserSessionIndex = WebSessionManager.addWebSession(ws);
                    // Set the current 'User Session' web session's parameters
                    WebSessionManager.setCurrentWebSession(UserSessionIndex);
                }catch(WebSessionException e){
                    ...
                }
                ...
    }
          

Example 4:

OTA Download start - using user defined web session.

     import com.motorola.oem.*;

     public class WebSessionMIDlet extends MIDlet{
             // Recommended - preserve the OTA dedicated WS entry reference for the future
             private int OTASessionIndex;
             ...
             public void startApp() {
             WebSession ws = new WebSession();
             ws.setSessionName("OTA Session");
             // set Server's URL for MIDlet download
             ws.setHomePage("www.motbrw.com/kjava/g24_cc/ota/vend.jad");
             ws.setGprsApn( "internet");
             ws.setGprsUserName("moto");
             ws.setGprsPassword("rola");
             try {
             // Store OTA session as a WebSession entry
             OTASessionIndex = WebSessionManager.addWebSession (ws);
             //SW update point reached
             OTADownload.startOTA (OTASessionIndex);
             } catch (Exception ex) {
             ...
             }
             ...

          

Example 5:

OTA Download start - Using special WS URL that use the default 'APP' web session

  
   import com.motorola.oem.*;

        public class WebSessionMIDlet extends MIDlet {
                private String OTASessionURL = "www.motbrw.com/kjava/g24_cc/ota/vend.jad";
                ...

        public void startApp() {
                try{
                    //SW update point reached
                    OTADownload.startOTA(OTASessionURL);
                }catch(WebSessionException e){
                        ...
                }
          

Example 6:

This MIDlet handles OTA provisioning through WAP push messages (browser messages).

  
import com.motorola.oem.websession.*;
import javax.microedition.midlet.MIDlet;

public class WebSessionExample extends MIDlet implements WebSessionBrowserMsgListener {

    // USERPIN code.
    // Used when receiving browser messages which requires USERPIN.
    private final static String pin1Code = "1234";

    // Stores the WebSessionManager only instance.
    private WebSessionManager webSessionManager;

    public void startApp() {
        try {
            webSessionManager = WebSessionManager.getInstance();
        } catch (WebSessionException wse) {
            System.out.println("Error: Cannot get WebSessionManager instance");
            wse.printStackTrace();
        }

        if (webSessionManager != null) {
            // Start listening to browser messages
            webSessionManager.setBrowserMsgListener(this);
            System.out.println("Browser message listener started");
        }
    }

    // Implements WebSessionBrowserMsgListener interface method.
    public void onBrowserMsgReceived(int securityMethod) {
        System.out.println("New settings arrived");

        int browserMsgType;

        try {
            if (securityMethod == WebSessionManager.AUTH_METHOD_NETWPIN) {
                // Security method does not require USERPIN
                browserMsgType = webSessionManager.acceptBrowserMsg();
            } else {
                // Security method requires USERPIN
                browserMsgType = webSessionManager.acceptBrowserMsg(pin1Code);
            }

            processProvSession(browserMsgType);
        } catch (WebSessionException wse) {
            System.out.println("Error: Cannot accept Web Session");
            wse.printStackTrace();
        }
    }

     // Copies the "Prov Session" web session to the "Java Session" web session or the "Mms Session" web session.
     // @param browserMsgType The type of web session that was provisioned
     // @throws com.motorola.oem.websession.WebSessionException Thrown if the "Prov Session" web session is not available or if the destination web session could not be updated
    private void processProvSession(int browserMsgType) throws WebSessionException {
        WebSession webSession = WebSessionManager.getWebSession(WebSessionManager.SESSION_INDEX_PROV);

        //  "Prov Session" access type is always read only, change it to read / write
        webSession.setAccessType(WebSession.ACCESS_RW);

        String sessionName;
        int sessionIndex;

        if (browserMsgType == WebSessionManager.BROWSER_SETTINGS_PROVISIONING_WEB) {
            sessionName = "Java Session";
            sessionIndex = WebSessionManager.SESSION_INDEX_JAVA;
        } else {
            sessionName = "Mms Session";
            sessionIndex = WebSessionManager.SESSION_INDEX_MMS;
        }

        webSession.setSessionName(sessionName);

        WebSessionManager.updateWebSession(webSession, sessionIndex);
        System.out.println(sessionName + " was updated");
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}