Java[tm] Smart Ticket Demo 1.1.1 > Configuring the Sample Application

Configuring the Sample Application

This section describes the steps needed to set up features of the sample application which are not supported by the default configuration.

Connecting to a Different Server

By default, the client is set to connect to a server running on localhost at port 8000.

To change the server to which the client connects, open {smarticket.dir}/bin/smarticket.jad in a text editor. (If you edit {smarticket.dir}/src/smarticket.jad, you ensure that each time you rebuild the application, the changes are permanent. However, you must rebuild the application after following these instructions.)

Look for the following lines:

SMARTicket-Servlet-URL: http://localhost:8000/SmarTicketApp/servlet/
SMARTicket-Poster-URL: http://localhost:8000/SmarTicketApp/
SMARTicket-Splash-URL: http://localhost:8000/SmarTicketApp/

Replace all occurrences of localhost and 8000 with the name of the host and the port on which the server is running.

Connecting over HTTPS

This section describes how to configure the Java Smart Ticket Demo to use HTTP over SSL (HTTPS). The J2ME Wireless Toolkit supports HTTPS, although not all MIDP devices are required to support it.

  1. Edit the JAD file to point to the secure port of the J2EE SDK server.

    Open {smarticket.dir}/bin/smarticket.jad in a text editor. (If you edit {smarticket.dir}/src/smarticket.jad, you ensure that each time you rebuild the application, the changes are permanent. However, you must rebuild the application after following these instructions.)

    Look for the following lines:

    SMARTicket-Servlet-URL: http://localhost:8000/SmarTicketApp/servlet/
    SMARTicket-Poster-URL: http://localhost:8000/SmarTicketApp/
    SMARTicket-Splash-URL: http://localhost:8000/SmarTicketApp/

    Change them to:

    SMARTicket-Servlet-URL: https://localhost:7000/SmarTicketApp/servlet/
    SMARTicket-Poster-URL: https://localhost:7000/SmarTicketApp/
    SMARTicket-Splash-URL: https://localhost:7000/SmarTicketApp/

    The default port for HTTPS is 7000. You can verify this by looking at the output when you start the J2EE SDK server with the -verbose option. The output contains a line like the following:

    Starting secure web service at port:7000
  2. Create a public/private key-pair for the J2EE SDK server.

    The J2ME Wireless Toolkit will not recognize the server key-pair that comes with the J2EE SDK server. Therefore, you have to create a new key-pair to replace the old one.

    1. Delete the server key-pair from the J2EE SDK server keystore.

      On Solaris or Linux, open a shell prompt, and enter the following command (all on one line):

      keytool -delete -keystore $J2EE_HOME/lib/security/keystore.jks 
      -alias server -storepass changeit

      On Windows, open a command prompt, and enter the following command (all on one line):

      keytool -delete -keystore %J2EE_HOME%\lib\security\keystore.jks
      -alias server -storepass changeit
    2. Generate a new server key-pair for the J2EE server.

      On Solaris or Linux, open a shell prompt, and enter the following command (all on one line):

      keytool -genkey -keystore $J2EE_HOME/lib/security/keystore.jks
      -keyalg RSA -alias server -storepass changeit -validity 10000

      On Windows, open a command prompt, and enter the following command (all on one line):

      keytool -genkey -keystore %J2EE_HOME%\lib\security\keystore.jks
      -keyalg RSA -alias server -storepass changeit -validity 10000

      The keytool will ask you a series of questions to establish the owner of the new key.

      When asked for your first and last name, enter localhost, which is the name of the server specified in the JAD file. If the name you give to keytool does not match the name of the server specified in the JAD file, then the application will not work.

      For the remaining questions you can type something appropriate (or just type Return to accept Unknown as the answer), until you are asked to confirm all your previous answers, at which point you should respond yes.

      Finally the keytool prompts you for a password for the key pair, and you can just type Return to make the key's password the same as the keystore's password.

      The following transcript illustrates a sample interaction with the keytool:

      C:\>keytool -genkey -keystore %J2EE_HOME%\lib\security\keystore.jks 
      -keyalg RSA -alias server -storepass changeit -validity 10000
      What is your first and last name?
      [Unknown]: localhost
      What is the name of your organizational unit?
      [Unknown]:
      What is the name of your organization?
      [Unknown]:
      What is the name of your City or Locality?
      [Unknown]:
      What is the name of your State or Province?
      [Unknown]:
      What is the two-letter country code for this unit?
      [Unknown]:
      Is <CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown>
      correct?
      [no]: yes

      Enter key password for <server>
      (RETURN if same as keystore password):

    After completing this step, the J2EE SDK server's keystore has a new version of the key-pair identified by the alias server. The public key is wrapped in a self-signed certificate, stored as a single-element certificate chain.

  3. Import the server's public key into the J2ME Wireless Toolkit keystore.

    Normally at this stage you would use the keytool's -certreq option, and ask some Certificate Authority (CA) to sign your server's public key certificate, while ensuring that the CA's root certificate was in the J2ME Wireless Toolkit's keystore.

    However, for testing purposes, you can just put the server's public key certificate into the J2ME Wireless Toolkit's keystore as a trusted certificate, effectively telling the toolkit that it can trust the J2EE SDK server.

    On Solaris or Linux, open a shell prompt, change the current directory to $J2MEWTK_HOME, and enter the following command (all on one line):

    java -jar bin\MEKeyTool.jar -import -alias server
    -keystore $J2EE_HOME/lib/security/keystore.jks -storepass changeit

    On Windows, open a command prompt, change the current directory to %J2MEWTK_HOME%, and enter the following command (all on one line):

    java -jar bin\MEKeyTool.jar -import -alias server
    -keystore %J2EE_HOME%\lib\security\keystore.jks -storepass changeit

Using a Different Character Set and Encoding

The Java Smart Ticket Demo is internationalized. It is also localized in US English, French and Japanese. However, the US English and French localizations use different character sets and encodings from the Japanese localization. This section describes how to change the character set and encoding used by the J2ME Wireless Toolkit.

The section Building the Sample Application describes how to build the Java Smart Ticket Demo with Japanese localized messages. To display these messages properly on the J2ME Wireless Toolkit emulator, follow these steps:

  1. Add an emulator which supports the desired character set.

    1. Make sure the required fonts are installed on your system.

      For example, to show Japanese fonts, you might use the MS Mincho font family.

    2. Copy the contents of %J2MEWTK_HOME%\wtklib\devices\DefaultColorPhone\ into a new directory, %J2MEWTK_HOME%\wtklib\devices\<device name>\.

      For example, the new directory might be %J2MEWTK_HOME%\wtklib\devices\JapaneseColorPhone\.

    3. Rename the file %J2MEWTK_HOME%\wtklib\devices\<device name>\DefaultColorPhone.properties to %J2MEWTK_HOME%\wtklib\devices\<device name>\<device name>.properties, and open this file in a text editor.

      For example, you would rename the file to %J2MEWTK_HOME%\wtklib\devices\JapaneseColorPhone\JapaneseColorPhone.properties.

    4. Replace the existing font names with the equivalent Japanese font names (in lines beginning with font).

      For example, some of the lines you would change might be as follows:

      font.default=SansSerif-plain-10
      font.system.plain.small: SansSerif-plain-9
      font.monospace.plain.small: Monospaced-plain-9

      You would need to change those lines to:

      font.default=MS\ Mincho-plain-10
      font.system.plain.small: MS\ Mincho-plain-9
      font.monospace.plain.small: MS\ PMincho-plain-9

      For these lines, a backslash ('\') is necessary wherever a space appears.

  2. Change the emulator's default encoding.

    1. Open the configuration file %J2MEWTK_HOME%\lib\system.config.

    2. Set the microedition.encoding property to the encoding of the file containing the localized messages.

      For example, the Japanese messages in ja_JP.properties are encoded in Shift-JIS. To use that encoding, set the microedition.encoding property as follows:

      microedition.encoding: SJIS

      For a complete list of supported encodings, consult the Java 2 SDK, Standard Edition Documentation.

For more information on configuring the J2ME Wireless Toolkit to support other languages, consult its documentation.


© 2002 Sun Microsystems, Inc. All rights reserved.