Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 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] Wed, 07 March 2012 03:53 Go to next message
Daniel Rippa is currently offline Daniel Rippa
Messages: 10
Registered: March 2012
Junior Member
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 #815373 is a reply to message #814962] Wed, 07 March 2012 15:29 Go to previous messageGo to next message
Brian Svihovec is currently offline Brian Svihovec
Messages: 55
Registered: July 2009
Member
Daniel,

I am not aware of any features in the runtime framework that would provide the IP address. Some possible solutions include:

1) Write an external type to get the hostname of the current page (a) and then send this value to a service that can convert a hostname into an IP address.

2) Write your own service and invoke it using an external type from the client, as described in the EGL Cafe. (b)

3) Write your own service that is capable of placing the client IP address in the response headers, and then access the headers in your client using the following:

// add "http IHTTP in" as the last parameter to your service callback function
function serviceCallback(response string in, http IHTTP in)
  SysLib.writestdout(http.getResponse().headers["ip"]);


NOTE: I have not tried any of these solutions, but let us know what you find.

Broken Links (to avoid the 25 message restriction in the forum):
a - http: //www.w3schools.com/jsref/obj_location.asp
b - https: //www.ibm.com/developerworks/forums/thread.jspa?messageID=14497871&#14497871

-Brian
Re: How can I get the IP Address of the client machine that runs mi RichUI app? [message #815380 is a reply to message #815373] Wed, 07 March 2012 15:36 Go to previous messageGo to next message
Daniel Rippa is currently offline Daniel Rippa
Messages: 10
Registered: March 2012
Junior Member
Will try this and post my results here. Thanks for the pointers, Brian!
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 Go to previous messageGo to next message
Daniel Rippa is currently offline 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 #818495 is a reply to message #817439] Sun, 11 March 2012 18:40 Go to previous messageGo to next message
Brian Svihovec is currently offline Brian Svihovec
Messages: 55
Registered: July 2009
Member
Glad this worked for you. Thanks to Dan Darnell as well for posting this solution in the EGL Cafe.

-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 Go to previous messageGo to next message
Daniel Rippa is currently offline 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?
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 19:32 Go to previous message
Daniel Rippa is currently offline Daniel Rippa
Messages: 10
Registered: March 2012
Junior Member
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>

Previous Topic:Preview Mode issue
Next Topic:New Blog - Changes to String type in EDT .8
Goto Forum:
  


Current Time: Sat Oct 25 07:52:14 GMT 2014

Powered by FUDForum. Page generated in 0.01790 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software