Home » Archived » EGL Development Tools » How can I get the IP Address of the client machine that runs mi RichUI app?
How can I get the IP Address of the client machine that runs mi RichUI app? [message #814962] |
Tue, 06 March 2012 22:53  |
Eclipse User |
|
|
|
First thing I checked was HTTPLib, but nope, it's not there. Maybe I have to code that myself, but I wouldn't know where to start. Since this isn't available in the JavaScript environment, I'm ruling out an ExternalType of type JavaScriptObject. But I have no idea of how to get to the headers of the HTTP Request by using an ExternalType of type JavaObject. Any ideas? Maybe this is already in the framework and I somehow overlooked it?
|
|
| | |
Re: How can I get the IP Address of the client machine that runs mi RichUI app? [message #817439 is a reply to message #815380] |
Fri, 09 March 2012 23:13   |
Eclipse User |
|
|
|
Ok, it worked!!!
I have this javascript externaltype "{myproj}/EGLSource/client/HttpClient.egl"
package client;
externalType HttpClient type JavascriptObject { relativePath = "client", externalName = "HttpClient" }
function getIP() returns (string);
end
Also, the Javascript implementation in "{myproj}/WebContent/client/HttpClient.js"
egl.defineClass(
'client', 'HttpClient',
{
"getIP": function () {
xhr = new XMLHttpRequest();
protocol = "http";
uri = protocol + ":" + "//localhost:8080/{someProj}/getIP.shtml";
// this string manipulation isn't really needed, I'm using it
// to avoid the warning about not being able to post links until
// having posted more than 25 messages in this forum.
xhr.open(uri, false);
xhr.send("");
ip = xhr.responseText;
return ip;
}
}
);
After enabling SSI in Tomcat, I can access getIP.shtml just fine, I will detail a how-to in another post in this thread, cause it's kinda tricky.
Then, I have the rui Handler "{myproj}/EGLSource/client/Test.egl"
package client;
import ...
handler Test type RUIHandler ...
...
client HttpClient {};
function start()
someTextField.text = client.getIP();
end
end
It works just fine!
Thank you so much, Brian!
|
|
| |
Re: How can I get the IP Address of the client machine that runs mi RichUI app? [message #823708 is a reply to message #818495] |
Sun, 18 March 2012 15:14   |
Eclipse User |
|
|
|
Since SSI (Server Includes) provide further info about the client, it occurred to me that I could wrap the .shtml as a service, and consuming it with @GetRest.
So I tried this:
{myProj}/WebContent/clientInfo.shtml
<clientInfo>
<accept><!--#echo var='HTTP_ACCEPT'--></accept>
<acceptCharset><!--#echo var='HTTP_ACCEPT_CHARSET'--></acceptCharset>
<acceptLanguage><!--#echo var='HTTP_ACCEPT_LANGUAGE'--></acceptLanguage>
<connection><!--#echo var='HTTP_CONNECTION'--></connection>
<remoteAddress><!--#echo var='REMOTE_ADDR'--></remoteAddress>
<remoteHost><!--#echo var='REMOTE_HOST'--></remoteHost>
<remotePort><!--#echo var='REMOTE_PORT'--></remotePort>
</clientInfo>
Of course, the Test Server will not serve any valid info, since it's not configured for serving SSI content, but at least it should serve the xml with null strings, so this doesn't bother me much yet.
Then, using "Records from XML" template in the "New Record" wizard, and using the test server URI to make sure I was getting the right content, I got this:
record ClientInfo{@XMLRootElement{name = "clientInfo"}}
remoteAddress string;
accept string;
acceptCharset string;
acceptLanguage string;
connection string;
remoteHost string;
remotePort string;
end
Then I created the interface IClientInfo like this:
interface IClientInfo
function getClientInfo() returns (ClientInfo) {@GetRest {uriTemplate = "clientInfo.shtml", requestFormat = XML}};
end
Then, in the Deployment Descriptor, in the Resource Bindings section, I added a REST Binding named clientInfo, using the base URI for the Test Server: http ://localhost:5590/{myProj} <--(blank added on purpose, to avoid the forum message about posting URLs)
Finally, in the RUIHandler I used this code:
...
function start()
clientInfo IClientInfo? {@Resource};
call clientInfo.getClientInfo()
returning to someCallback
onException someExceptionHandler;
end
...
Sadly, it's not working for me, it fails with CRRUI3655E, 'Object required'.
Of course, I also tried deploying this to Tomcat, updating the URI to point to it, still doesn't work.
It also fails with the same message when I try using JSON format in the .shtml, running the new Record wizard to use the JSON template and then changing the requestFormat in the interface to JSON.
I'm convinced this approach should work, but I must be missing something related to consuming the service.
Any hints?
|
|
|
Re: How can I get the IP Address of the client machine that runs mi RichUI app? [message #823716 is a reply to message #823708] |
Sun, 18 March 2012 15:32  |
Eclipse User |
|
|
|
The approach works!
My bad, I forgot to add the slash either in the URI in the Deployment Descriptor, or in the interface.
So I kept the URI in the Deployment Descriptor untouched, and added the backslash in the uriTemplate for the interface, that now looks like this:
interface IClientInfo
function getClientInfo() returns (ClientInfo) {@GetRest {uriTemplate = "/clientInfo.shtml", requestFormat = XML}};
end
Leaving the interface untouched and updating the URI in the Deployment Descriptor by appending the slash should work too.
PS: forgot to add the userAgent entry in the XML, could be useful, the SSI for that is:
<clientInfo>
<userAgent><!--#echo var='HTTP_USER_AGENT'--></userAgent>
...
</clientInfo>
|
|
|
Goto Forum:
Current Time: Wed Jul 02 03:38:33 EDT 2025
Powered by FUDForum. Page generated in 0.11453 seconds
|