@@ -146,6 +146,9 @@ public static class ClientOptions {
146
146
/** Optional TChannel transport headers */
147
147
private final Map <String , String > transportHeaders ;
148
148
149
+ /** Optional TChannel headers */
150
+ private final Map <String , String > headers ;
151
+
149
152
private ClientOptions (Builder builder ) {
150
153
this .rpcTimeoutMillis = builder .rpcTimeoutMillis ;
151
154
if (builder .clientAppName == null ) {
@@ -169,6 +172,12 @@ private ClientOptions(Builder builder) {
169
172
} else {
170
173
this .transportHeaders = ImmutableMap .of ();
171
174
}
175
+
176
+ if (builder .headers != null ) {
177
+ this .headers = ImmutableMap .copyOf (builder .headers );
178
+ } else {
179
+ this .headers = ImmutableMap .of ();
180
+ }
172
181
}
173
182
174
183
/** @return Returns the rpc timeout value in millis. */
@@ -203,6 +212,10 @@ public Map<String, String> getTransportHeaders() {
203
212
return transportHeaders ;
204
213
}
205
214
215
+ public Map <String , String > getHeaders () {
216
+ return headers ;
217
+ }
218
+
206
219
/**
207
220
* Builder is the builder for ClientOptions.
208
221
*
@@ -218,6 +231,7 @@ public static class Builder {
218
231
public String serviceName ;
219
232
private Scope metricsScope ;
220
233
private Map <String , String > transportHeaders ;
234
+ private Map <String , String > headers ;
221
235
222
236
/**
223
237
* 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) {
298
312
return this ;
299
313
}
300
314
315
+ public Builder setHeaders (Map <String , String > headers ) {
316
+ this .headers = headers ;
317
+ return this ;
318
+ }
319
+
301
320
/**
302
321
* Builds and returns a ClientOptions object.
303
322
*
@@ -349,7 +368,7 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
349
368
throw new IllegalArgumentException ("0 or negative port" );
350
369
}
351
370
this .options = options ;
352
- this .thriftHeaders = getThriftHeaders ();
371
+ this .thriftHeaders = getThriftHeaders (options );
353
372
// this.metricsReporter = new MetricsReporter(options.getMetricsClient());
354
373
// Need to create tChannel last in order to prevent leaking when an exception is thrown
355
374
this .tChannel = new TChannel .Builder (options .getClientAppName ()).build ();
@@ -380,13 +399,13 @@ public WorkflowServiceTChannel(String host, int port, ClientOptions options) {
380
399
*/
381
400
public WorkflowServiceTChannel (SubChannel subChannel , ClientOptions options ) {
382
401
this .options = options ;
383
- this .thriftHeaders = getThriftHeaders ();
402
+ this .thriftHeaders = getThriftHeaders (options );
384
403
// this.metricsReporter = new MetricsReporter(options.getMetricsClient());
385
404
this .tChannel = null ;
386
405
this .subChannel = subChannel ;
387
406
}
388
407
389
- private static Map <String , String > getThriftHeaders () {
408
+ private static Map <String , String > getThriftHeaders (ClientOptions options ) {
390
409
String envUserName = System .getenv ("USER" );
391
410
String envHostname ;
392
411
try {
@@ -395,12 +414,20 @@ private static Map<String, String> getThriftHeaders() {
395
414
envHostname = "localhost" ;
396
415
}
397
416
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 ();
404
431
}
405
432
406
433
/** Returns the endpoint in the format service::method" */
0 commit comments