|
1 | 1 | /** |
2 | | - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -181,6 +181,12 @@ public class AWSIotMqttManager { |
181 | 181 | */ |
182 | 182 | private final String endpoint; |
183 | 183 |
|
| 184 | + /** |
| 185 | + * This is the hostname and port of the proxy, if any, to be used for connecting to AWS IoT |
| 186 | + */ |
| 187 | + private String proxyHost; |
| 188 | + private int proxyPort; |
| 189 | + |
184 | 190 | /** |
185 | 191 | * Turning on/off metrics collection. By default metrics collection is enabled. |
186 | 192 | * Client must call this to set metrics collection to false before calling connect in order to turn |
@@ -735,10 +741,32 @@ public void connectUsingALPN(KeyStore keyStore, |
735 | 741 | connect(keyStore, 443, statusCallback); |
736 | 742 | } |
737 | 743 |
|
| 744 | + /** |
| 745 | + * Initializes the MQTT session and connects to the specified MQTT server |
| 746 | + * using certificate and private key in keystore on port 8883 via the proxy specified by a |
| 747 | + * host and port combination. Keystore should be created using |
| 748 | + * {@link com.amazonaws.mobileconnectors.iot.AWSIotKeystoreHelper} to setup the |
| 749 | + * certificate and key aliases as expected by the underlying socket helper library. |
| 750 | + * |
| 751 | + * @param keyStore A keystore containing an keystore with a certificate and |
| 752 | + * private key. Use IotKeystoreHelper to get keystore. |
| 753 | + * @param proxyHost hostname of the proxy |
| 754 | + * @param proxyPort proxy port number |
| 755 | + * @param statusCallback When new MQTT session status is received the |
| 756 | + * function of callback will be called with new connection |
| 757 | + * status. |
| 758 | + */ |
| 759 | + public void connectWithProxy(KeyStore keyStore, final String proxyHost, final int proxyPort, |
| 760 | + final AWSIotMqttClientStatusCallback statusCallback) { |
| 761 | + this.proxyHost = proxyHost; |
| 762 | + this.proxyPort = proxyPort; |
| 763 | + connect(keyStore, 8883, statusCallback); |
| 764 | + } |
| 765 | + |
738 | 766 | /** |
739 | 767 | * Initializes the MQTT session and connects to the specified MQTT server |
740 | 768 | * using certificate and private key in keystore on port 8883. Keystore should be created |
741 | | - * using IotKeystoreHelper to setup the certificate and key aliases as |
| 769 | + * using {@link com.amazonaws.mobileconnectors.iot.AWSIotKeystoreHelper} to setup the certificate and key aliases as |
742 | 770 | * expected by the underlying socket helper library. |
743 | 771 | * |
744 | 772 | * @param keyStore A keystore containing an keystore with a certificate and |
@@ -800,7 +828,10 @@ private void connect(KeyStore keyStore, int portNumber, final AWSIotMqttClientSt |
800 | 828 | mqttClient = new MqttAsyncClient(mqttBrokerURL, mqttClientId, new MemoryPersistence()); |
801 | 829 | } |
802 | 830 |
|
803 | | - final SocketFactory socketFactory = AWSIotSslUtility.getSocketFactoryWithKeyStore(keyStore, portNumber); |
| 831 | + final SocketFactory socketFactory = (proxyHost != null) ? |
| 832 | + AWSIotSslUtility.getSocketFactoryWithKeyStoreAndProxy(keyStore, portNumber, proxyHost, proxyPort): |
| 833 | + AWSIotSslUtility.getSocketFactoryWithKeyStore(keyStore, portNumber) ; |
| 834 | + |
804 | 835 | final MqttConnectOptions options = new MqttConnectOptions(); |
805 | 836 |
|
806 | 837 | if (mqttLWT != null) { |
|
0 commit comments