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