Skip to content

Commit c20e36a

Browse files
authored
Update proxy-enabled samples and mqtt connection builder with new proxy support (#161)
1 parent 26b1779 commit c20e36a

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

samples/BasicPubSub/src/main/java/pubsub/PubSub.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,19 @@ public void onConnectionResumed(boolean sessionPresent) {
251251
.withCleanSession(true)
252252
.withProtocolOperationTimeoutMs(60000);
253253

254+
HttpProxyOptions proxyOptions = null;
255+
if (proxyHost != null && proxyPort > 0) {
256+
proxyOptions = new HttpProxyOptions();
257+
proxyOptions.setHost(proxyHost);
258+
proxyOptions.setPort(proxyPort);
259+
260+
builder.withHttpProxyOptions(proxyOptions);
261+
}
262+
254263
if (useWebsockets) {
255264
builder.withWebsockets(true);
256265
builder.withWebsocketSigningRegion(region);
257266

258-
HttpProxyOptions proxyOptions = null;
259-
if (proxyHost != null && proxyPort > 0) {
260-
proxyOptions = new HttpProxyOptions();
261-
proxyOptions.setHost(proxyHost);
262-
proxyOptions.setPort(proxyPort);
263-
264-
builder.withWebsocketProxyOptions(proxyOptions);
265-
}
266-
267267
if (useX509Credentials) {
268268
try (TlsContextOptions x509TlsOptions = TlsContextOptions.createWithMtlsFromPath(x509CertPath, x509KeyPath)) {
269269
if (x509RootCaPath != null) {

samples/PubSubStress/src/main/java/pubsubstress/PubSubStress.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,20 @@ public static void main(String[] args) {
337337
builder.withCertificateAuthorityFromPath(null, rootCaPath)
338338
.withEndpoint(endpoint)
339339
.withCleanSession(true)
340-
.withBootstrap(clientBootstrap);
340+
.withBootstrap(clientBootstrap)
341+
.withProtocolOperationTimeoutMs(10000);
342+
343+
if (proxyHost != null && proxyPort > 0) {
344+
HttpProxyOptions proxyOptions = new HttpProxyOptions();
345+
proxyOptions.setHost(proxyHost);
346+
proxyOptions.setPort(proxyPort);
347+
348+
builder.withHttpProxyOptions(proxyOptions);
349+
}
341350

342351
if (useWebsockets) {
343352
builder.withWebsockets(true);
344353
builder.withWebsocketSigningRegion(region);
345-
346-
if (proxyHost != null && proxyPort > 0) {
347-
HttpProxyOptions proxyOptions = new HttpProxyOptions();
348-
proxyOptions.setHost(proxyHost);
349-
proxyOptions.setPort(proxyPort);
350-
351-
builder.withWebsocketProxyOptions(proxyOptions);
352-
}
353354
}
354355

355356
try {

sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>software.amazon.awssdk.crt</groupId>
4444
<artifactId>aws-crt</artifactId>
45-
<version>0.12.4</version>
45+
<version>0.12.6</version>
4646
</dependency>
4747
<dependency>
4848
<groupId>junit</groupId>

sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqttConnectionBuilder.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,24 @@ public AwsIotMqttConnectionBuilder withWebsocketHandshakeTransform(Consumer<Webs
363363
}
364364

365365
/**
366+
* @deprecated use withHttpProxyOptions instead
366367
* Configures any http proxy options to use if the connection uses websockets
367368
*
368369
* @param proxyOptions http proxy options to use when establishing a websockets-based connection
369370
*/
370371
public AwsIotMqttConnectionBuilder withWebsocketProxyOptions(HttpProxyOptions proxyOptions) {
371-
this.config.setWebsocketProxyOptions(proxyOptions);
372+
this.config.setHttpProxyOptions(proxyOptions);
373+
374+
return this;
375+
}
376+
377+
/**
378+
* Configures any http proxy options to use
379+
*
380+
* @param proxyOptions http proxy options to use when establishing a connection
381+
*/
382+
public AwsIotMqttConnectionBuilder withHttpProxyOptions(HttpProxyOptions proxyOptions) {
383+
this.config.setHttpProxyOptions(proxyOptions);
372384

373385
return this;
374386
}

0 commit comments

Comments
 (0)