Skip to content

Commit

Permalink
Improved determinePublicHostName method
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemSempere committed Jul 15, 2019
1 parent e084fe5 commit d12d0d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.cirad</groupId>
<artifactId>Mgdb2BrapiImpl</artifactId>
<version>1.1-RC1</version>
<version>1.1-RC2</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>fr.cirad</groupId>
<artifactId>mgdb2</artifactId>
<version>2.1-RELEASE</version>
<version>2.2-RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
26 changes: 13 additions & 13 deletions src/fr/cirad/web/controller/rest/BrapiRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1207,19 +1207,19 @@ public String determinePublicHostName(HttpServletRequest request) throws Unknown
Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
mainLoop : for (; niEnum.hasMoreElements();)
{
NetworkInterface ni = niEnum.nextElement();
Enumeration<InetAddress> a = ni.getInetAddresses();
for (; a.hasMoreElements();)
{
InetAddress addr = a.nextElement();
String hostAddress = addr.getHostAddress();
if (!"127.0.1.1".equals(hostAddress) && hostAddress.split("\\.").length >= 4)
{
sHostName = hostAddress;
if (!ni.getDisplayName().toLowerCase().startsWith("wlan"))
break mainLoop; // otherwise we will keep searching in case we find an ethernet network
}
}
NetworkInterface ni = niEnum.nextElement();
Enumeration<InetAddress> a = ni.getInetAddresses();
for (; a.hasMoreElements();)
{
InetAddress addr = a.nextElement();
String hostAddress = addr.getHostAddress().replaceAll("/", "");
if (!hostAddress.startsWith("127.0.") && hostAddress.split("\\.").length >= 4)
{
sHostName = hostAddress;
if (!addr.isSiteLocalAddress() && !ni.getDisplayName().toLowerCase().startsWith("wlan"))
break mainLoop; // otherwise we will keep searching in case we find an ethernet network
}
}
}
if (sHostName == null)
LOG.error("Unable to convert local address to internet IP");
Expand Down

0 comments on commit d12d0d2

Please sign in to comment.