Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

This is a bunch of tips and techniques related to Oracle PL/SQL and Forms.

Publicité

Send message to Forms from the outside ? yes you can !

Purpose

Here is a Java bean that allows to transform a Forms module into a socket server.

This way, it can receive messages from the outside.
- In this example, the messages are sent through a telnet session.


Forms Socket Server

In this sample dialog, I have opened a telnet session:

   open localhost 4450

Then I can send messages to the Forms application.


- In another way, messages can also be sent by the database:

DECLARE
  c  utl_tcp.connection;  -- TCP/IP connection to the Socket server
  ret_val PLS_INTEGER;
BEGIN
  c := utl_tcp.open_connection(remote_host => '10.40.40.40',
                               remote_port =>  4450);  -- open connection
  ret_val := utl_tcp.write_line(c, 'Incoming Message Send by my Oracle DB');
  utl_tcp.close_connection(c);
END;



The Java code

     SocketServer.java     Server.java  



The implementation class of the Bean Item

     oracle.forms.fd.SocketServer


The methods you can call


Init the socket server

Set_Custom_Property('BLOCK.ITEM', 1, 'INIT_SERVER', 'port_number');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INIT_SERVER', '4450' ) ;
   
 

The event received from the Bean

SENDMSG


this event tells Forms that a message is sent by the Java Bean.
You can get it in a WHEN-CUSTOM-ITEM-EVENT event:

DECLARE
   
    eventName varchar2(30) := :system.custom_item_event;
    eventValues ParamList;
    eventValueType number;
    LC$Msg    varchar2(512);
    LC$Value  varchar2(256);
   
BEGIN
   
   IF (eventName='SENDMSG') THEN
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MESSAGEVALUE',eventValueType, LC$Msg);
      -- Display the message --
      :BL.MSGS := :BL.MSGS || LC$Msg || Chr(10) ;
      Synchronize ;           
   END IF;
   
END;


The sample dialog

     . Download the socketserver.zip file
     . Unzip the file
     . copy the socketserver.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the SOCKETSERVER.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

     the jar file must be signed.
     the jar file provided in this article is already signed.
Publicité
Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article
Z
hiI tried to use your bean in my main screen. I have some links in main screen, which opens other forms. Our goal was when we recieve a message in port, we wanted to show a form on top of other existing forms. It does the job, if there is only main screen. But, when we open a new form [using call_form or open_form] whenever a message is recieved an error message is shown 'cannot navigate to main_screen'. Then we tried to close the socket before opening other forms. And, opening the socket from the new form. But, this was not successful either. Because, we were unable to stop the socket server from listening. Only way, we could do this by showing two consecutive messages. And, only after that, the socket stops listening! Any idea how to resolve the issue? My question is why the socket server is not stopping as soon as we call set_custom_property passing 'STOP_SERVER' ?Thanks in advance.
Répondre
O
<br /> I'm not able to reproduce the issue. I have added a call_form() in the When-Custom-Item-Event trigger, then the other form is correctly called and displayed without any message (using JPI 1.5_014)<br /> <br /> <br />
K
Why do we have to have a static thread object in the SocketServer and why do we have this condition in its run method:<br /> Thread theThread = Thread.currentThread();        while (runner == theThread)        {?<br />  <br /> Thanks
Répondre
T
Hi Francois<br /> The solution to this is so simple that i should be ashamed to have asked you the question ;-)<br /> DECLARE  c  utl_tcp.connection;  -- TCP/IP connection to the Socket server  ret_val pls_integer; BEGIN  c := utl_tcp.open_connection(remote_host => 'localhost',                               remote_port =>  4450);  -- open connection  ret_val := utl_tcp.write_line(c, 'Incoming Message Send by my Oracle DB');  utl_tcp.close_connection(c);<br /> END;/<br /> Thanks again and best regardsTorben
Répondre
O
Fine. I will blog on this  ;o)
T
Hello Francois<br />  <br /> Thanks a lot for the Jinitiator update, it works with the Jinitiator update.<br /> Having to deliver Proof of Concept regarding Forms being able to recieve the Response from an Oracle Database Advanced queue,and having read the Oracle White paper <br /> Building Internet Applications with Oracle Forms 6i and Oracle8iAn Oracle Technical White PaperMarch 2000<br /> on Which i have seen your recommandation on Technet.<br /> This solution seems rather complicated though and is for Forms 6i and the 8i DB,as i stated we will be using Forms 10g 10.1.2.0.2 and a 10g DBand my immediate idea was to maybe shortcut this using the SocketServer variant and just to have a DB Stored procedure call the Socket Server without involving the AQ in first place.My deduction is that if the stored procedure can call the Socket Server then in a second step i can combine this with the AQs later on.<br /> In the First place i could make a stored procedure that via Java Stored procedure calls telnet on the OS and sends a Message to the Forms socketServer,The forms could then react to this message, so having provided a first Proof of Concept as to Forms being able to react to a generel DB event.<br /> I know its to much to hope for an comment on a Solution path for the proof of concept,but i thought id give a shoot anyway.<br /> Best regardsTorben
Répondre
T
Hi Francois<br /> Thanks for your quick response.<br /> I also figured this out reading your comments elsewhere recommending the general use of the SUN Java plug-in instead of  the JInitiator.<br /> Also thanks for providing the JInitiator JAR file<br /> Best Regards<br /> Torben<br />  <br />  <br />  
Répondre
O
The zip file contains now a JRE 1.3 .jar file and a 9.0.2 sample dialog.