Skip to content

Commit 7f85e92

Browse files
authored
Expose methods to allow user to add headers in Thrift request (#255)
* Expose methods in TChannel service to allow user to add headers in Thrift request * Update changelog
1 parent b83f643 commit 7f85e92

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v2.3.1
4+
- Added support for SignalWithStart Service API
5+
- Expose methods in TChannel service to allow user to add headers in Thrift request
6+
37
## v2.3.0
48
- Added cron schedule support.
59
- Fix infinite retryer in activity and workflow worker due to non-retryable error.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ googleJavaFormat {
3737
}
3838

3939
group = 'com.uber.cadence'
40-
version = '2.3.0'
40+
version = '2.3.1'
4141

4242
description = """Uber Cadence Java Client"""
4343

src/main/java/com/uber/cadence/serviceclient/WorkflowServiceTChannel.java

+36-9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public static class ClientOptions {
146146
/** Optional TChannel transport headers */
147147
private final Map<String, String> transportHeaders;
148148

149+
/** Optional TChannel headers */
150+
private final Map<String, String> headers;
151+
149152
private ClientOptions(Builder builder) {
150153
this.rpcTimeoutMillis = builder.rpcTimeoutMillis;
151154
if (builder.clientAppName == null) {
@@ -169,6 +172,12 @@ private ClientOptions(Builder builder) {
169172
} else {
170173
this.transportHeaders = ImmutableMap.of();
171174
}
175+
176+
if (builder.headers != null) {
177+
this.headers = ImmutableMap.copyOf(builder.headers);
178+
} else {
179+
this.headers = ImmutableMap.of();
180+
}
172181
}
173182

174183
/** @return Returns the rpc timeout value in millis. */
@@ -203,6 +212,10 @@ public Map<String, String> getTransportHeaders() {
203212
return transportHeaders;
204213
}
205214

215+
public Map<String, String> getHeaders() {
216+
return headers;
217+
}
218+
206219
/**
207220
* Builder is the builder for ClientOptions.
208221
*
@@ -218,6 +231,7 @@ public static class Builder {
218231
public String serviceName;
219232
private Scope metricsScope;
220233
private Map<String, String> transportHeaders;
234+
private Map<String, String> headers;
221235

222236
/**
223237
* Sets the rpc timeout value for non query and non long poll calls. Default is 1000.
@@ -298,6 +312,11 @@ public Builder setTransportHeaders(Map<String, String> transportHeaders) {
298312
return this;
299313
}
300314

315+
public Builder setHeaders(Map<String, String> headers) {
316+
this.headers = headers;
317+
return this;
318+
}
319+
301320
/**
302321
* Builds and returns a ClientOptions object.
303322
*
@@ -349,7 +368,7 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
349368
throw new IllegalArgumentException("0 or negative port");
350369
}
351370
this.options = options;
352-
this.thriftHeaders = getThriftHeaders();
371+
this.thriftHeaders = getThriftHeaders(options);
353372
// this.metricsReporter = new MetricsReporter(options.getMetricsClient());
354373
// Need to create tChannel last in order to prevent leaking when an exception is thrown
355374
this.tChannel = new TChannel.Builder(options.getClientAppName()).build();
@@ -380,13 +399,13 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
380399
*/
381400
public WorkflowServiceTChannel(SubChannel subChannel, ClientOptions options) {
382401
this.options = options;
383-
this.thriftHeaders = getThriftHeaders();
402+
this.thriftHeaders = getThriftHeaders(options);
384403
// this.metricsReporter = new MetricsReporter(options.getMetricsClient());
385404
this.tChannel = null;
386405
this.subChannel = subChannel;
387406
}
388407

389-
private static Map<String, String> getThriftHeaders() {
408+
private static Map<String, String> getThriftHeaders(ClientOptions options) {
390409
String envUserName = System.getenv("USER");
391410
String envHostname;
392411
try {
@@ -395,12 +414,20 @@ private static Map<String, String> getThriftHeaders() {
395414
envHostname = "localhost";
396415
}
397416

398-
return ImmutableMap.<String, String>builder()
399-
.put("user-name", envUserName)
400-
.put("host-name", envHostname)
401-
.put("cadence-client-library-version", Version.LIBRARY_VERSION)
402-
.put("cadence-client-feature-version", Version.FEATURE_VERSION)
403-
.build();
417+
ImmutableMap.Builder<String, String> builder =
418+
ImmutableMap.<String, String>builder()
419+
.put("user-name", envUserName)
420+
.put("host-name", envHostname)
421+
.put("cadence-client-library-version", Version.LIBRARY_VERSION)
422+
.put("cadence-client-feature-version", Version.FEATURE_VERSION);
423+
424+
if (options.headers != null) {
425+
for (Map.Entry<String, String> entry : options.headers.entrySet()) {
426+
builder.put(entry.getKey(), entry.getValue());
427+
}
428+
}
429+
430+
return builder.build();
404431
}
405432

406433
/** Returns the endpoint in the format service::method" */

0 commit comments

Comments
 (0)