Use An Https Connection - Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
9.
Create a run()method and within it implement a dialog object to ask the BlackBerry device user for login information.
UiApplication.getUiApplication().invokeAndWait(new Runnable())
{
public void run()
{
dialogResponse = Dialog.ask;
(Dialog.D_YES_NO,"Unauthorized Access:\n Do you wish to log in?");
}
}
10. To process the login information, create code to manage a Yes dialog response.
a.
Retrieve the login information and close the current connection.
if (dialogResponse == Dialog.YES)
{String login = "username:password";
//Close the connection.
s.close();
b.
Encode the login information.
byte[] encoded = Base64OutputStream.encode(login.getBytes(),
0, login.length(), false, false);
11.
Invoke HTTPConnection.setRequestProperty() using the encoded login information to access the
protected resource.
s = (StreamConnection)Connector.open("http://mysite.com/
myProtectedFile.txt ");
httpConn = (HttpConnection)s;
httpConn.setRequestProperty("Authorization", "Basic " + new String
(encoded));

Use an HTTPS connection

If your BlackBerry device is associated with a BlackBerry® Enterprise Server and uses an HTTPS proxy server that requires
authentication, you will not be able to use end-to-end TLS.
1.
Import the following classes:
• net.rim.device.api.system.CoverageInfo
• javax.microedition.io.Connector
2.
Import the following interfaces:
• net.rim.device.api.system.CoverageStatusListener
• javax.microedition.io.HttpsConnection
56
Connections

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents