EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
  • 1.  How to retrive PC's IP adress

    Posted Fri April 17, 2015 01:20 PM

    Hi

    i would need to know,  if the page web request,  came from internal lan  o esternal lan respect to the iSeries IP adress , where run my EGL application as; in practice depneding if it internal  or external, it have to open a page web pointing  to a private or  public address.

    Example:

    request from internal lan :  http://192.168.0.1:2050/webaccess/iWA5250...........

    request from external lan : http://myiseries.mydom.com:2050/webaccess/iWA5250...........

    How can i solve this

    thanks

     

    giocot


  • 2.  Re: How to retrive PC's IP adress

    Posted Mon April 20, 2015 08:10 AM

    I have not found any reliable client-only way to accomplish this with javascript.

    I assume this is because of security restrictions and therefore don't think it will be possible with RUI.

     

    I would try to make my application independent of the users's location. 

    A possible workaround is resolving the ip address differently locally or externally, but always using myIseries.mydom.com.

     

    Kind regards,

     

    Bram

    Bram_Callewaert


  • 3.  Re: How to retrive PC's IP adress

    Posted Mon April 20, 2015 08:44 AM

    Hi Bram

    thanks;

    i change my request: is it possible to "retrive" the URL/URI that launched the EGL application ?

    Thanks

     

    P.S. how do you manage test and production database environment  ?

     

    giocot


  • 4.  Re: How to retrive PC's IP adress

    Posted Mon April 20, 2015 08:55 AM

    I created a java externaltype in my service to retrieve the hostname of the server:

        public static final String getHostname(){                try {                        return (InetAddress.getLocalHost().getHostName());                } catch (Exception e) {                        System.out.println("GeneralOperations.getHostname: " + e.getMessage());                        return "";                        // TODO: handle exception                }        }

     

    Our production and test environment both write to the same database, run on the same host, and only have the port number as difference. This port number is stored in a library, so it only has to be changed in one location.

    The build script has a parameter to set this port number before building.

    We use the above function to have a different path to access files on the network if it runs on AS400 (QNTC)

    Bram_Callewaert


  • 5.  Re: How to retrive PC's IP adress

    Posted Mon April 20, 2015 10:12 AM

    Hi Bram

     

    be patient..  i'm not expert.. could please post (if possible) an complete esample  ..  service and EGL example call

     

    Thanks and sorry for my "stupid" request

    Thanks in advance anyway

     

    giocot


  • 6.  Re: How to retrive PC's IP adress

    Posted Mon April 20, 2015 10:31 AM

    There is nothing odd about your request.

    Just to be clear: the above example returns the hostname of the server running the service, not the RUI client generating the service call.

    Step 1: create java class under "java resources/src" and a new package of your choosing (mine is com.molcy.fileoperations)

    package com.molcy.fileoperations;import java.net.InetAddress;import com.itextpdf.text.pdf.events.PdfPageEventForwarder;public class GeneralOperations {    public static final String getHostname(){                try {                        return (InetAddress.getLocalHost().getHostName());                } catch (Exception e) {                        System.out.println("GeneralOperations.getHostname: " + e.getMessage());                        return "";                        // TODO: handle exception                }        }                }

    Step 2: create an egl source file under "EglSource" and a package of your choosing (mine is com.molcy.webservices.externaltypes.java.io)

    package com.molcy.webservices.externaltypes.java.io;externalType GeneralOperations type JavaObject{packageName = "com.molcy.fileoperations", javaName = "GeneralOperations"}            static function getHostname() returns (String);end

    Step 3: use the function in a service or a library (egl library, not the one with the books:) )

        function testHostname() returns (String)                return (GeneralOperations.getHostname());          end

    That's it on the service side...

     

     

    In the meantime I have found a possible solution for retrieving the address in the address bar on the client side in RUI. This did not undergo extended testing.

    it is again an externaltype (javascript this time)

    Step 1: create a file under webcontent folder (best in a subdirectory, I store mine in "customJavaScript/widgets") and call it BrowserFuncts.js

    egl.defineClass(    'customJavaScript.widgets', 'BrowserFuncts',                                        {                    "eze$$initializeDOMElement": function(){                                        },                "constructor": function(){                        //theWidget=this;                },        "getHostFromAddressbar": function(){                        return (window.location.host);                },                 "getHostNameFromAddressbar": function(){                        return (window.location.hostname);                },                 "getHostFromUrl": function(url){                        var l = document.createElement("a");                    l.href = url;                    return l.host;                                      },                 "getHostNameFromUrl": function(url){                        var l = document.createElement("a");                    l.href = url;                    return l.hostname;                                  }    });    

    Step 2: Under EglSource: create a package named Externaltypes and put in a egl source file named BrowserFunctions:

    package externalTypes;externalType BrowserFunctions extends Widget type JavaScriptObject {        relativePath = "customJavaScript/widgets",                javaScriptName = "BrowserFuncts"        }                function getHostFromAddressbar() returns (String);                function getHostNameFromAddressbar() returns (String);                function getHostFromUrl(href String in) returns (String);                function getHostNameFromUrl(href String in) returns (String);end

    Step 3: use the externaltype in a Rui handler or widget:

        b BrowserFunctions{};        SysLib.writeStdout(b.getHostFromAddressbar());         syslib.writeStdout(b.getHostNameFromAddressbar());    

     

    Give it a shot and let me know if this works for you.

     

    Kind regards,

     

    Bram

    Bram_Callewaert


  • 7.  Re: How to retrive PC's IP adress

    Posted Thu April 23, 2015 04:13 AM

    Hi Bram

    thanks .. your examples works fine ..  (the best for me is the 2° example, with which i can also retrive the port number)

    sorry if I take advantage of your availability: can your better explain this concept:

    "Our production and test environment both write to the same database, run on the same host, and only have the port number as difference. This port number is stored in a library, so it only has to be changed in one location.

    The build script has a parameter to set this port number before building.

    We use the above function to have a different path to access files on the network if it runs on AS400 (QNTC)"

    Thanks again

     

     

    giocot


  • 8.  Re: How to retrive PC's IP adress

    Posted Thu April 23, 2015 05:48 AM

    We have 1 server running two websphere instances on two different ports.

    Both websphere instances run the same egl application, and both connect to the same database.

    So if we want to access the test environment we go to http://<dns address>:<portA>/applicationblahblahblah

    If we want to access the production environment we go to http://<dns address>:<portB>/applicationblahblahblah

    The only difference for us between production and test is that production is only updated once a month, and doesn't go offline during working hours.

    The test environment is frequently updated with the latest changes, but can be updated during working hours.

     

    We don't have a test team. The end users test the new parts of our application.

    If the user comes to us with a change request, we update our sources, deliver the changes in RTC and request a build with the build engine to update the test environment. Once complete the user is notified that he can test in the test environment, knowing that the test environment could go offline for updates. If he really needs to use this change he can choose to work in the test environment for the remainder of the month, as this works on the same database as the production environment.

     

    The build script has a parameter which indicates the port number of the environment we are updating. It requires these ports to change the wsdl files in the rui project (to go let rui go to the correct port for the web service) and for updating the egl library which contains the port number.

    So if we need to access some other application on websphere from egl (eg provide an url to some other application), it is looked up in the library.
     

    The last sentence with regards to QNTC: Other than our test and production environment, we also have each developers' machine which runs Tomcat for testing the web services.

    We use our application a lot for accessing files. We have chosen to put the files on our file server on the network. The database contains the path to the file as it is logical in the windows world (eg. \\servername\folder\filename).

    If we want to access the file from AS400 we have to adapt this path, and change it to /QNTC/servername/folder/filename. This does not need to happen on the developers' machine, and therefore we use the function provided earlier to know if we are running on our as400, or on our tomcat installation in windows.

    Just let me know if this raises more questions.

     

    Kind regards,

     

    Bram
     

    Bram_Callewaert