Skip to content

Commit d01e9b8

Browse files
jmklixbretambrose
andauthored
Greengrass china endpoint (#162)
* Temporary fix for connection with greengrass china endpoint * replace '-' with '.' * Compile errors, refactor * add override to allow unique endpoint to be used * add javadoc comments and remove region parameter Co-authored-by: Bret Ambrose <[email protected]>
1 parent 38d4035 commit d01e9b8

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

sdk/src/main/java/software/amazon/awssdk/iot/discovery/DiscoveryClient.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ public void onResponseComplete(HttpStream httpStream, int errorCode) {
106106
}
107107

108108
private static String getHostname(final DiscoveryClientConfig config) {
109-
return String.format("greengrass-ats.iot.%s.%s",
110-
config.getRegion(), AWS_DOMAIN_SUFFIX_MAP.getOrDefault(config.getRegion(), AWS_DOMAIN_DEFAULT));
109+
//allow greengrass server endpoint to be manualy set for unique endpoints
110+
if (config.getGGServerName().equals("")) {
111+
return String.format("greengrass-ats.iot.%s.%s",
112+
config.getRegion(), AWS_DOMAIN_SUFFIX_MAP.getOrDefault(config.getRegion(), AWS_DOMAIN_DEFAULT));
113+
} else {
114+
return String.format(config.getGGServerName());
115+
}
111116
}
112117

113118
@Override

sdk/src/main/java/software/amazon/awssdk/iot/discovery/DiscoveryClientConfig.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public class DiscoveryClientConfig implements AutoCloseable {
1616
final private String region;
1717
final private int maxConnections;
1818
final private HttpProxyOptions proxyOptions;
19+
final private String ggServerName;
1920

2021
/**
22+
* Constructor for DiscoveryClientConfig creates the correct endpoint if not in a special region
2123
*
2224
* @param bootstrap client bootstrap to use to establish network connections
2325
* @param tlsContextOptions tls configuration for client network connections. For greengrass discovery, the
@@ -41,6 +43,35 @@ public DiscoveryClientConfig(
4143
this.region = region;
4244
this.maxConnections = maxConnections;
4345
this.proxyOptions = proxyOptions;
46+
this.ggServerName = "";
47+
}
48+
49+
/**
50+
* Default Constructor for DiscoveryClientConfig that allows the specification of a specific ggServerName to use in special regions
51+
*
52+
* @param bootstrap client bootstrap to use to establish network connections
53+
* @param tlsContextOptions tls configuration for client network connections. For greengrass discovery, the
54+
* tls context must be initialized with the certificate and private key of the
55+
* device/thing that is querying greengrass core availability.
56+
* @param socketOptions socket configuration for client network connections
57+
* @param maxConnections maximum concurrent http connections within the client
58+
* @param proxyOptions proxy configuration for client network connections
59+
* @param ggServerName full endpoint to use when connecting in special regions
60+
*/
61+
public DiscoveryClientConfig(
62+
final ClientBootstrap bootstrap,
63+
final TlsContextOptions tlsContextOptions,
64+
final SocketOptions socketOptions,
65+
final int maxConnections,
66+
final HttpProxyOptions proxyOptions,
67+
final String ggServerName) {
68+
this.bootstrap = bootstrap;
69+
this.tlsContext = new TlsContext(tlsContextOptions);
70+
this.socketOptions = socketOptions;
71+
this.region = "";
72+
this.maxConnections = maxConnections;
73+
this.proxyOptions = proxyOptions;
74+
this.ggServerName = ggServerName;
4475
}
4576

4677
/**
@@ -85,6 +116,10 @@ public HttpProxyOptions getProxyOptions() {
85116
return proxyOptions;
86117
}
87118

119+
public String getGGServerName() {
120+
return ggServerName;
121+
}
122+
88123
@Override
89124
public void close() {
90125
if(tlsContext != null) {

0 commit comments

Comments
 (0)