Adding notification of ip/hostname of client (so we can get "source" of the connection inside user services)

This commit is contained in:
Adolfo Gómez 2012-12-14 11:11:50 +00:00
parent 1d8a0c1353
commit 6667544c39
5 changed files with 56 additions and 4 deletions

View File

@ -27,7 +27,8 @@ public class LinuxApplet implements OsApplet {
nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs"; nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs";
jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar"; jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar";
//System.out.println(nxFileName); // Notifies to broker the hostname/ip
util.notifyHostname(baseUrl, params.get("is"));
String width = params.get("width"); String width = params.get("width");
String height = params.get("height"); String height = params.get("height");

View File

@ -27,7 +27,8 @@ public class MacApplet implements OsApplet {
nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs"; nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs";
jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar"; jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar";
//System.out.println(nxFileName); // Notifies to broker the hostname/ip
util.notifyHostname(baseUrl, params.get("is"));
String width = params.get("width"); String width = params.get("width");
String height = params.get("height"); String height = params.get("height");

View File

@ -36,7 +36,8 @@ public class WindowsApplet implements OsApplet {
nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs"; nxFileName = tmpDir + UUID.randomUUID().toString() + ".nxs";
jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar"; jarFileName = tmpDir + UUID.randomUUID().toString() + ".jar";
//System.out.println(nxFileName); // Notifies to broker the hostname/ip
util.notifyHostname(baseUrl, params.get("is"));
String width = params.get("width"); String width = params.get("width");
String height = params.get("height"); String height = params.get("height");

View File

@ -1,8 +1,11 @@
package es.virtualcable.nx; package es.virtualcable.nx;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
public class util { public class util {
@ -39,11 +42,57 @@ public class util {
out.close(); out.close();
} catch(Exception e) { } catch(Exception e) {
System.out.println("Unable to download component, already present or network error? " + e.getMessage()); System.out.println("Unable to download file, already present or network error? " + e.getMessage());
return false; return false;
} }
return true; return true;
} }
public static String getUrl(String url) {
try {
java.net.URL u = new java.net.URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
StringBuilder data = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null) {
data.append(inputLine);
data.append("\n");
}
in.close();
return data.toString();
} catch(Exception e) {
System.out.println("Unable to get url. Network error? " + e.getMessage());
return null;
}
}
@SuppressWarnings("deprecation")
public static void notifyHostname(String baseUrl, String serviceId) {
String[] urlComponents = baseUrl.split("/");
String hostname;
String ip;
String url="";
try {
hostname = java.net.InetAddress.getLocalHost().getHostName();
ip = java.net.InetAddress.getLocalHost().getHostAddress();
} catch(Exception e) {
hostname = "unknown";
ip = "0.0.0.0";
}
try {
// An url is "http[s]://.....:/,
url = urlComponents[0] + "//" + urlComponents[2] + "/sernotify/" + serviceId + "/hostname?hostname="+URLEncoder.encode(hostname)+"&ip="+URLEncoder.encode(ip);
getUrl(url);
} catch(Exception e) {
System.out.println("Unable to get url? " + e.getMessage());
}
}
} }