update handling for upnp response with ip path

This commit is contained in:
BWS Systems
2018-11-12 16:25:15 -06:00
parent afc254720c
commit 3f13e957ad
2 changed files with 9 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>5.2.2b</version>
<version>5.2.1c</version>
<packaging>jar</packaging>
<name>HA Bridge</name>
@@ -114,7 +114,7 @@
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>

View File

@@ -7,13 +7,13 @@ import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
import com.bwssystems.HABridge.api.hue.HueConstants;
import com.bwssystems.HABridge.api.hue.HuePublicConfig;
import com.bwssystems.HABridge.util.ParseRoute;
import static spark.Spark.get;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketException;
/**
*
@@ -118,7 +118,7 @@ public class UpnpSettingsResource {
// added by https://github.com/pvint
// Ruthlessly stolen from https://stackoverflow.com/questions/22045165/java-datagrampacket-receive-how-to-determine-local-ip-interface
// Try to get a source IP that makes sense for the requester to contact for use in the LOCATION header in replies
private InetAddress getOutboundAddress(String remoteAddress, int remotePort) throws SocketException {
private InetAddress getOutboundAddress(String remoteAddress, int remotePort) {
InetAddress localAddress = null;
try {
DatagramSocket sock = new DatagramSocket();
@@ -130,7 +130,11 @@ public class UpnpSettingsResource {
sock.close();
sock = null;
} catch(Exception e) {
log.warn("Error <" + e.getMessage() + "> on determining interface to reply for <" + remoteAddress + ">. Using default route IP");
ParseRoute theRoute = ParseRoute.getInstance();
try {
localAddress = InetAddress.getByName(theRoute.getLocalIPAddress());
} catch(Exception e1) {}
}
return localAddress;
}