Skip to content

Commit b51aa47

Browse files
committed
refactoring interceptor to internal package
Signed-off-by: salaboy <[email protected]>
1 parent 99ba57f commit b51aa47

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/client/DaprWorkflowClient.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.dapr.config.Properties;
2222
import io.dapr.utils.NetworkUtils;
2323
import io.dapr.workflows.Workflow;
24+
import io.dapr.workflows.internal.APITokenClientInterceptor;
2425
import io.grpc.CallOptions;
2526
import io.grpc.Channel;
2627
import io.grpc.ClientCall;
@@ -262,25 +263,6 @@ public void close() throws InterruptedException {
262263
}
263264
}
264265

265-
public static ClientInterceptor WORKFLOW_INTERCEPTOR = new ClientInterceptor() {
266-
@Override
267-
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
268-
MethodDescriptor<ReqT, RespT> methodDescriptor,
269-
CallOptions options,
270-
Channel channel) {
271-
// TBD: do we need timeout in workflow client?
272-
ClientCall<ReqT, RespT> clientCall = channel.newCall(methodDescriptor, options);
273-
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(clientCall) {
274-
@Override
275-
public void start(final Listener<RespT> responseListener, final Metadata metadata) {
276-
String daprApiToken = Properties.API_TOKEN.get();
277-
if (daprApiToken != null) {
278-
metadata.put(Metadata.Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), daprApiToken);
279-
}
280-
super.start(responseListener, metadata);
281-
}
282-
};
283-
}
284-
};
266+
private static ClientInterceptor WORKFLOW_INTERCEPTOR = new APITokenClientInterceptor();
285267
}
286268

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.dapr.workflows.internal;
2+
3+
import io.dapr.client.Headers;
4+
import io.dapr.config.Properties;
5+
import io.grpc.CallOptions;
6+
import io.grpc.Channel;
7+
import io.grpc.ClientCall;
8+
import io.grpc.ClientInterceptor;
9+
import io.grpc.ForwardingClientCall;
10+
import io.grpc.Metadata;
11+
import io.grpc.MethodDescriptor;
12+
13+
public class APITokenClientInterceptor implements ClientInterceptor {
14+
@Override
15+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
16+
MethodDescriptor<ReqT, RespT> methodDescriptor,
17+
CallOptions options,
18+
Channel channel) {
19+
// TBD: do we need timeout in workflow client?
20+
ClientCall<ReqT, RespT> clientCall = channel.newCall(methodDescriptor, options);
21+
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(clientCall) {
22+
@Override
23+
public void start(final Listener<RespT> responseListener, final Metadata metadata) {
24+
String daprApiToken = Properties.API_TOKEN.get();
25+
if (daprApiToken != null) {
26+
metadata.put(Metadata.Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), daprApiToken);
27+
}
28+
super.start(responseListener, metadata);
29+
}
30+
};
31+
}
32+
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
import com.microsoft.durabletask.DurableTaskGrpcWorkerBuilder;
1717
import io.dapr.utils.NetworkUtils;
1818
import io.dapr.workflows.Workflow;
19-
import io.dapr.workflows.client.DaprWorkflowClient;
19+
import io.dapr.workflows.internal.APITokenClientInterceptor;
20+
import io.grpc.ClientInterceptor;
2021

2122
public class WorkflowRuntimeBuilder {
2223
private static volatile WorkflowRuntime instance;
2324
private DurableTaskGrpcWorkerBuilder builder;
25+
private static ClientInterceptor WORKFLOW_INTERCEPTOR = new APITokenClientInterceptor();
2426

2527
public WorkflowRuntimeBuilder() {
2628
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(
27-
NetworkUtils.buildGrpcManagedChannel(DaprWorkflowClient.WORKFLOW_INTERCEPTOR));
29+
NetworkUtils.buildGrpcManagedChannel(WORKFLOW_INTERCEPTOR));
2830
}
2931

3032
/**

0 commit comments

Comments
 (0)