Tuesday, October 4, 2011

How To Get Client IP Address For a Locking User

Visit the Below Website to access unlimited exam questions for all IT vendors and Get Oracle Certifications for FREE
http://www.free-online-exams.com
Problem: How To Get Client IP Address For a Locking User


Symptoms:
This document gives sample coding on getting the IP address of the client for forms deployed on the web.
The goal of this code is to store the information about the IP address in the DB system table v$session using WHEN-NEW-FORM-INSTANCE and WHEN-TIMER-EXPIRED triggers together and WebUtil
WebUtil can only start to communicate with the client once the Form has instantiated the WebUtil PJCs, so that a timer with small duration (2 ms) is created in the WHEN-NEW-FORM-INSTANCE trigger, then the call to the WebUtil is made in a WHEN-TIMER-EXPIRED trigger.



Solution:



Software Requirements/Prerequisites
This sample code is created using Forms Builder 10.1.2.0.2 and the corresponding WebUtil Version.
Configuring the Sample Code
WebUtil Environment Configuration:
Please configure your environment to run WebUtil demo, you can use the readme.html file of the webutil_demo, which can be downloaded from -Webutil Demo Download Location (Doc ID 1272222.1)
Running the Sample Code
For step (4), user needs execute privilege on DBMS_APPLICATION_INFO
For step (7), you need to connect to the DB using any user has a "Select" privilege on v$session
Caution
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
Sample Code
Create IP-Address Sample form
1. Install and configure your Developer installation to use webutil .

2. Create new form using webutil

3. Create a WHEN-NEW-FORM-INSTANCE trigger add the following:
declare
v_timer timer;
begin
v_timer := create_timer('ip_timer',2,no_repeat);
end;

4. Create a database procedure
create or replace procedure SETCLIENTINFO (p_info varchar2) is
begin
DBMS_APPLICATION_INFO.SET_CLIENT_INFO(p_info);
exception
when others then
raise_application_error(-20101,'SETCLIENTINFO: error: '||sqlerrm);
end;

5. Create a WHEN-TIMER-EXPIRED add the following code:
declare
v_trimer_name varchar2(30) := get_application_property(TIMER_NAME);
v_ip_address varchar2(40);
begin
if upper(v_trimer_name) = upper('ip_timer') THEN
v_ip_address := webutil_clientinfo.get_ip_address;
SETCLIENTINFO('Client IP='||v_ip_address);
end if;
end;
6. Call the form

7. Go to SQL*Plus or iSQL*Plus and run the following SQL statement:
select client_info from v$session where client_info is not null;

Sample Code Output
The SQL output in step (7) should be like :
Client IP = x.x.x.x
To avoid webutil performance issues, It is recommended to add this solution in the calling (parent) form of the forms application, and pass the client IP information to any other child form.

References:

How To Get Client IP Address For a Locking User [ID 403192.1]

NOTE:270940.1 - Oracle Forms WebUtil :Technical FAQ

Get Oracle Certifications for all Exams
Free Online Exams.com

No comments: