Skip to content

Commit

Permalink
Update proxy-enabled samples and mqtt connection builder with new pro…
Browse files Browse the repository at this point in the history
…xy support (#161)
  • Loading branch information
bretambrose authored May 18, 2021
1 parent 26b1779 commit c20e36a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
18 changes: 9 additions & 9 deletions samples/BasicPubSub/src/main/java/pubsub/PubSub.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,19 @@ public void onConnectionResumed(boolean sessionPresent) {
.withCleanSession(true)
.withProtocolOperationTimeoutMs(60000);

HttpProxyOptions proxyOptions = null;
if (proxyHost != null && proxyPort > 0) {
proxyOptions = new HttpProxyOptions();
proxyOptions.setHost(proxyHost);
proxyOptions.setPort(proxyPort);

builder.withHttpProxyOptions(proxyOptions);
}

if (useWebsockets) {
builder.withWebsockets(true);
builder.withWebsocketSigningRegion(region);

HttpProxyOptions proxyOptions = null;
if (proxyHost != null && proxyPort > 0) {
proxyOptions = new HttpProxyOptions();
proxyOptions.setHost(proxyHost);
proxyOptions.setPort(proxyPort);

builder.withWebsocketProxyOptions(proxyOptions);
}

if (useX509Credentials) {
try (TlsContextOptions x509TlsOptions = TlsContextOptions.createWithMtlsFromPath(x509CertPath, x509KeyPath)) {
if (x509RootCaPath != null) {
Expand Down
19 changes: 10 additions & 9 deletions samples/PubSubStress/src/main/java/pubsubstress/PubSubStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,20 @@ public static void main(String[] args) {
builder.withCertificateAuthorityFromPath(null, rootCaPath)
.withEndpoint(endpoint)
.withCleanSession(true)
.withBootstrap(clientBootstrap);
.withBootstrap(clientBootstrap)
.withProtocolOperationTimeoutMs(10000);

if (proxyHost != null && proxyPort > 0) {
HttpProxyOptions proxyOptions = new HttpProxyOptions();
proxyOptions.setHost(proxyHost);
proxyOptions.setPort(proxyPort);

builder.withHttpProxyOptions(proxyOptions);
}

if (useWebsockets) {
builder.withWebsockets(true);
builder.withWebsocketSigningRegion(region);

if (proxyHost != null && proxyPort > 0) {
HttpProxyOptions proxyOptions = new HttpProxyOptions();
proxyOptions.setHost(proxyHost);
proxyOptions.setPort(proxyPort);

builder.withWebsocketProxyOptions(proxyOptions);
}
}

try {
Expand Down
2 changes: 1 addition & 1 deletion sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.12.4</version>
<version>0.12.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,24 @@ public AwsIotMqttConnectionBuilder withWebsocketHandshakeTransform(Consumer<Webs
}

/**
* @deprecated use withHttpProxyOptions instead
* Configures any http proxy options to use if the connection uses websockets
*
* @param proxyOptions http proxy options to use when establishing a websockets-based connection
*/
public AwsIotMqttConnectionBuilder withWebsocketProxyOptions(HttpProxyOptions proxyOptions) {
this.config.setWebsocketProxyOptions(proxyOptions);
this.config.setHttpProxyOptions(proxyOptions);

return this;
}

/**
* Configures any http proxy options to use
*
* @param proxyOptions http proxy options to use when establishing a connection
*/
public AwsIotMqttConnectionBuilder withHttpProxyOptions(HttpProxyOptions proxyOptions) {
this.config.setHttpProxyOptions(proxyOptions);

return this;
}
Expand Down

0 comments on commit c20e36a

Please sign in to comment.