Sample RMI session

Create and upload the RMI applet

Create the RMI applet

Create a RMIApplet with a Interface named "SampleInterface" with the JCOP RMI wizard. The Interface has declared only one method with the name "sampleMethod".

public short sampleMethod( short sh );
	

Open the previous created RMIApplet in the Java editor view.
It should contain the following code.

RMI applet code

package com.ibm.rmi;

import javacard.framework.Applet;
import javacard.framework.service.CardRemoteObject;
import javacard.framework.service.Dispatcher;
import javacard.framework.service.RMIService;
import javacard.framework.APDU;

/**
 * @author
 *
 */
public class RmiApplet extends Applet implements SampleInterface {
	private Dispatcher dispatcher;

	private RmiApplet() {
		CardRemoteObject.export(this);
		dispatcher = new Dispatcher((short) 1);
		dispatcher.addService(new RMIService(this), Dispatcher.PROCESS_COMMAND);
	}

	public static void install(byte[] bArray, short bOffset, byte bLength) {
		new RmiApplet()
				.register(bArray, (short) (bOffset + 1), bArray[bOffset]);
	}

	public void process(APDU apdu) {
		dispatcher.process(apdu);
	}

	/**
	 * method from interface "SampleInterface"
	 * return sh * 2
	 *
	 * @param short sh: input value
	 * @return short
	 */
	public short sampleMethod( short sh ) {
		return (short) (sh * 2) ;
	}
}

Upload the RMI applet

Load the previous created RMIApplet into the JCOP simulator or into a real card with the JCOP standard upload procedure (launch in run- or debug-mode with applet upload).

Sample JCShell RMI session

The following lines of codes should explain the usage of the RMI-Plugin commands to interact with a applet on a card or the simulator via Remote Method Invocation.

Upload and install the RMI applet

-  /term "Remote|localhost:8050"
--Opening terminal

>  /card -a a000000003000000 -c com.ibm.jc.CardManager
resetCard with timeout: 0 (ms)
--Waiting for card...
ATR=3B E9 00 00 81 31 FE 45 4A 43 4F 50 34 31 56 32 32 A7
ATR: T=1, N=0, IFSC=254, BWI=4/CWI=5, Hist="JCOP41V22"
Status: No Error

cm>  set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f

cm>  init-update 255
Status: No Error

cm>  ext-auth plain
Status: No Error

cm>  upload -d -b 250 "C:\runtime-workspace\rmi\bin\com\ibm\rmi\javacard\rmi.cap"
Status: No Error
Load report:
  1207 bytes loaded in 0.2 seconds
  effective code size on card:
      + package AID       7
      + applet AIDs       17
      + classes           67
      + methods           77
      + statics           0
      + exports           8
     ------------------------------
        overall           176  bytes

cm>  install -i 54455354524d492e3031  -q C9#() 54455354524d49 54455354524d492e3031
Status: No Error

cm>  card-info
Status: No Error

Card Manager AID   :  A000000003000000
Card Manager state :  OP_READY

    Application:  SELECTABLE (--------) "TESTRMI.01"
    Load File  :      LOADED (--------) A0000000035350   (Security Domain)
     Module    :                        A000000003535041
    Load File  :      LOADED (--------) "TESTRMI"
     Module    :                        "TESTRMI.01"

Select the RMI applet and activate the JCRMIPlugin

cm>  /sel |TESTRMI.01
Status: No Error
Remote Object:
  JC RMI server applet: "TESTRMI.01"
  JC RMI version: '0202'
  INVOKE instruction byte: '38'
  Remote ref. ID: 'DE47'
  Hash modifier: 'null'
  Class: com.ibm.rmi.RmiApplet

Declare a remote method and store the result in a JCShell variable

rmi>  method -m meth_sample DE47 sampleMethod "short(short)"

rmi>  /list-vars
Global:____________________________________________
   meth_sample=979C

List the remote methods

rmi>  list
------- Remote Object 1 -------
Remote Object:
  JC RMI server applet: "TESTRMI.01"
  JC RMI version: '0202'
  INVOKE instruction byte: '38'
  Remote ref. ID: 'DE47'
  Hash modifier: 'null
  Class: com.ibm.rmi.RmiApplet

Remote Method:
  Name: sampleMethod
  Signature: short(short)
  Descriptor: (S)S
  ID: '979C'

Invoke the remote method and store the result in a JCShell variable

rmi>  invoke -r req_result ${meth_sample} 1000
 => 00 38 02 02 06 DE 47 97 9C 10 00 00
 (11297 msec)
 <= 81 20 00 90 00                                     . ...
Status: No Error
Return value: 2000

rmi>  /echo Result of RMI-Method is: ${req_result}
Result of RMI-Method is: 2000

rmi>  invoke -r req_result ${meth_sample} 1500
 => 00 38 02 02 06 DE 47 97 9C 15 00 00                .8....A.....
 (15 msec)
 <= 81 2A 00 90 00                                     .*...
Status: No Error
Return value: 2A00

rmi>  /echo Result of RMI-Method is: ${req_result}
Result of RMI-Method is: 2A00

Delete all declared remote methods

rmi>  clear
rmi>  list
*** No remote object references ***