ponedeljek, 09. april 2012

Reading applet parameters in Oracle Forms

Reading oracle forms forum I have found out this question:

"Dears
We are working with system with 2 application server IPs and one Real IP (which is able to be accessed through internet)
I would like to know the URL is the user using in order to use his IP to open something else from the system.
Chcking the host name not usesful because if user connect from home using Real IP it return the AS host name which real IP redirct to it.
I need to know how to get the URL of the session from the form or to know whether the user connected using the Real IP or not.
(Oracle forms 10gR2)
"

The simple solution is to write down a java bean component (pjc) for Oracle Forms.
As you know the PJC must extends VBean object and also pass a IHandler instance to it.
From IHandler you can read Applet parameters like Applet.getDocumentBase. The getDocumentBase() method of Applet class returns the URL of the document in which this applet is embedded.

Below is the PJC which can read some user specific datas.
CLIENT_IP return the client ip number,
CLIENT_NAME return the name of local (client) computer
CLIENT_OS return the opetating system name
CLIENT_USER return the user name which is logged to the system
HOST_URL return the URL of the document in which the Oracle Forms application is embedded (run).

package in2.client;
 
import java.io.PrintStream;
import java.net.InetAddress;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
 
public class ClientInfo extends VBean
{
  private static final ID CLIENT_IP = ID.registerProperty("CLIENT_IP");
  private static final ID CLIENT_NAME = ID.registerProperty("CLIENT_NAME");
  private static final ID CLIENT_OS = ID.registerProperty("CLIENT_OS");
  private static final ID CLIENT_USER = ID.registerProperty("CLIENT_USER");
  private static final ID HOST_URL = ID.registerProperty("HOST_URL");
  
  private IHandler mHandler;
  private String hostAddress = "";
  private String hostName = "";
  private String hostOs = "";
  private String hostUser = "";
  private String hostURL = "";
 
  public ClientInfo()
  {
    try
    {
      
      System.out.println("+----------------------+");
      System.out.println("+  ClientInfro PJC     +");
      System.out.println("+  Peter Valencic      +");
      System.out.println("+----------------------+\n"); 
 
      this.hostAddress = InetAddress.getLocalHost().getHostAddress();
      this.hostName    = InetAddress.getLocalHost().getHostName();
      this.hostOs      = System.getProperty("os.name");
      this.hostUser    = System.getProperty("user.name");
 
      System.out.println("Host   adress: " + this.hostAddress);
      System.out.println("Host     name: " + this.hostAddress);
      System.out.println("Host op. syst: " + this.hostOs);
      System.out.println("Host username: " + this.hostUser);
      System.out.println("+----------------------+\n");
    }
    catch (Exception e)
    {
      System.out.println("Init error: " + e.toString());
    }
  }
 
  public void init(IHandler handler)
  {
    super.init(handler);
    this.mHandler = handler;
    
  }
 
  public Object getProperty(ID pid)
  {
    if (pid == CLIENT_IP) {
      System.out.println("Client IP: " + this.hostAddress);
 
      return "" + this.hostAddress;
    }
 
    if (pid == CLIENT_NAME) {
      System.out.println("Client Name: " + this.hostName);
 
      return "" + this.hostName;
    }
 
    if (pid == CLIENT_OS) {
      System.out.println("Client os: " + this.hostOs);
 
      return "" + this.hostOs;
    }
 
    if (pid == CLIENT_USER) {
      System.out.println("Clientuser: " + this.hostUser);
 
      return "" + this.hostUser;
    }
    
    if (pid == HOST_URL) {
      hostURL = this.mHandler.getApplet().getDocumentBase();
      System.out.println("Host Url: " + this.hostURL);
      return "" + this.hostURL;
    }
 
    return super.getProperty(pid);
  }
}