Home » Archived » EGL Development Tools » How can I get the IP Address of the client machine that runs mi RichUI app?
| | |
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] |
Sat, 10 March 2012 04:13 |
Daniel Rippa Messages: 10 Registered: March 2012 |
Junior Member |
|
|
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 19:14 |
Daniel Rippa Messages: 10 Registered: March 2012 |
Junior Member |
|
|
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?
|
|
| |
Goto Forum:
Current Time: Thu Dec 26 12:20:48 GMT 2024
Powered by FUDForum. Page generated in 0.06822 seconds
|