FileDocCategorySizeDatePackage
SipPushTest.javaAPI DocphoneME MR2 API (J2ME)5654Wed May 02 18:00:40 BST 2007examples

SipPushTest

public class SipPushTest extends javax.microedition.midlet.MIDlet implements CommandListener, SipServerConnectionListener
Attempt various push connection registrations with static push registrations.

Fields Summary
SipConnectionNotifier[]
scn
Array of active connections.
String[]
connections
Array of URL connections.
Command
exitCommand
Terminate MIDlet button.
TextBox
textBox
Message array for user communication.
Display
display
Current user interface handle.
Constructors Summary
Methods Summary
public voidcommandAction(Command command, Displayable screen)
Callback for user interface interactions.

param
command the user interface element
param
screen the context for the selected user interface element.

	if (command == exitCommand) {
	    destroyApp(false);
	    notifyDestroyed();
	}
    
public voiddestroyApp(boolean unconditional)
Destroys the MIDlet and cleans up all opened resources.

param
unconditional flag indicating that the MIDlet will be destroyed

	for (int i = 0; i < connections.length; i++) {
	    if (scn[i] != null) {
		try {
		    scn[i].close();
		} catch (Exception ex) {
		}
	    }
	}
    
public voidnotifyRequest(SipConnectionNotifier scn)
Callback listener for inbound messages.

param
scn the accepted inbound connection handle.

	try {
	    SipServerConnection ssc;
	    // retrieve the request received
	    ssc = scn.acceptAndOpen();
	    
	    // Check for NOTIFY message
	    if (ssc.getMethod().equals("NOTIFY")) {
		updateScreen(ssc.getMethod());
	    } else {
		updateScreen(ssc.getMethod());
	    }
	} catch (Exception ex) {
	    // handle Exceptions
            ex.printStackTrace();
	    updateScreen(ex.getMessage());
	}
    
public voidpauseApp()
Pauses the MIDlet.

 
public voidstartApp()
Launches the MIDlet.

	
	// Attempt dynamic registration with port
	try {
	    PushRegistry
		.registerConnection("sip:5081",
				    "examples.SipPushTest",
				    "*");
	} catch (Exception ex) { 
	    ex.printStackTrace();
	    updateScreen(ex.getMessage());
	}
	try {
	    PushRegistry
		.unregisterConnection("sip:5081");
	} catch (Exception ex) { 
	    ex.printStackTrace();
	    updateScreen(ex.getMessage());
	}

	// Attempt dynamic registration with port and transport
	try {
	    PushRegistry
		.registerConnection("sip:5081;transport=udp",
				    "examples.SipPushTest",
				    "*");
	} catch (Exception ex) { 
	    ex.printStackTrace();
	    updateScreen(ex.getMessage());
	}
	try {
	    PushRegistry
		.unregisterConnection("sip:5081;transport=udp");
	} catch (Exception ex) { 
	    ex.printStackTrace();
	    updateScreen(ex.getMessage());
	}

	// Verify dynamic registration with port and transport=tcp
	// is blocked.
	try {
	    PushRegistry
		.registerConnection("sip:5081;transport=tcp",
				    "examples.SipPushTest",
				    "*");
	} catch (Exception ex) { 
	    // Should fail - "transport=tcp" not supported
	}

	// Verify dynamic registration for sips is blocked
	try {
	    PushRegistry
		.registerConnection("sips:5081",
				    "examples.SipPushTest",
				    "*");
	} catch (Exception ex) { 
	    // Should fail - "sips" not supported
	}

	// Check the list of pending connections
	connections = PushRegistry.listConnections(false);
	if (connections != null &&
	    connections.length > 0) {
	    scn = new SipConnectionNotifier[connections.length];
	    for (int i = 0; i < connections.length; i++) {
		
		// Open connection for the designated push registration
		try { 
		    scn[i] = (SipConnectionNotifier)
			Connector.open(connections[i]);
		    // Register callback method
		    scn[i].setListener(this);
		} catch (Exception ex) {
		    // handle Exceptions
		    ex.printStackTrace();
		    updateScreen(ex.getMessage());
		}
	    }
	}
    
public voidupdateScreen(java.lang.String s)
Constructs a messgae array and quit button and displays message to end user.

param
s the string to present to the user.

	exitCommand = new Command("Exit", Command.EXIT, 1);
	textBox = new TextBox("SipPushTest", s, s.length(),
			      TextField.ANY | TextField.UNEDITABLE);
	textBox.addCommand(exitCommand);
	textBox.setCommandListener(this);

	display = Display.getDisplay(this);
	display.setCurrent(textBox);