Skip to content

Commit 44d3f33

Browse files
committed
fix(mqtt): read and respect noProxyAddresses for mqtt connection (#1393)
1 parent 0622f45 commit 44d3f33

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/com/aws/greengrass/mqttclient/MqttClient.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.io.Closeable;
3838
import java.time.Duration;
39+
import java.util.Arrays;
3940
import java.util.HashSet;
4041
import java.util.List;
4142
import java.util.Map;
@@ -185,8 +186,9 @@ public MqttClient(DeviceConfiguration deviceConfiguration, ScheduledExecutorServ
185186
} catch (MqttConnectionProviderException e) {
186187
throw new MqttException(e.getMessage());
187188
}
189+
String endpoint = Coerce.toString(deviceConfiguration.getIotDataEndpoint());
188190
builder.withCertificateAuthorityFromPath(null, Coerce.toString(deviceConfiguration.getRootCAFilePath()))
189-
.withEndpoint(Coerce.toString(deviceConfiguration.getIotDataEndpoint()))
191+
.withEndpoint(endpoint)
190192
.withPort((short) Coerce.toInt(mqttTopics.findOrDefault(DEFAULT_MQTT_PORT, MQTT_PORT_KEY)))
191193
.withCleanSession(false).withBootstrap(clientBootstrap).withKeepAliveMs(Coerce.toInt(
192194
mqttTopics.findOrDefault(DEFAULT_MQTT_KEEP_ALIVE_TIMEOUT, MQTT_KEEP_ALIVE_TIMEOUT_KEY)))
@@ -195,9 +197,19 @@ public MqttClient(DeviceConfiguration deviceConfiguration, ScheduledExecutorServ
195197
Coerce.toInt(mqttTopics.findOrDefault(DEFAULT_MQTT_PING_TIMEOUT, MQTT_PING_TIMEOUT_KEY)))
196198
.withSocketOptions(new SocketOptions()).withTimeoutMs(Coerce.toInt(
197199
mqttTopics.findOrDefault(DEFAULT_MQTT_SOCKET_TIMEOUT, MQTT_SOCKET_TIMEOUT_KEY)));
198-
HttpProxyOptions httpProxyOptions = ProxyUtils.getHttpProxyOptions(deviceConfiguration, proxyTlsContext);
200+
201+
HttpProxyOptions httpProxyOptions =
202+
ProxyUtils.getHttpProxyOptions(deviceConfiguration, proxyTlsContext);
199203
if (httpProxyOptions != null) {
200-
builder.withHttpProxyOptions(httpProxyOptions);
204+
String noProxy = Coerce.toString(deviceConfiguration.getNoProxyAddresses());
205+
boolean useProxy = true;
206+
// Only use the proxy when the endpoint we're connecting to is not in the NoProxyAddress list
207+
if (Utils.isNotEmpty(noProxy) && Utils.isNotEmpty(endpoint)) {
208+
useProxy = Arrays.stream(noProxy.split(",")).noneMatch(endpoint::matches);
209+
}
210+
if (useProxy) {
211+
builder.withHttpProxyOptions(httpProxyOptions);
212+
}
201213
}
202214
return builder;
203215
};

0 commit comments

Comments
 (0)