use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project ballerina by ballerina-lang.
the class ServerHeaderInterceptor method interceptCall.
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
MessageContext ctx = MessageContext.DATA_KEY.get();
// Only initialize ctx if not yet initialized
ctx = ctx != null ? ctx : new MessageContext();
boolean found = false;
for (String keyName : headers.keys()) {
if (keyName.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
Metadata.Key<byte[]> key = Metadata.Key.of(keyName, Metadata.BINARY_BYTE_MARSHALLER);
Iterable<byte[]> values = headers.getAll(key);
if (values == null) {
continue;
}
for (byte[] value : values) {
ctx.put(key, value);
}
} else {
Metadata.Key<String> key = Metadata.Key.of(keyName, Metadata.ASCII_STRING_MARSHALLER);
Iterable<String> values = headers.getAll(key);
if (values == null) {
continue;
}
for (String value : values) {
ctx.put(key, value);
}
}
found = true;
}
if (found) {
return Contexts.interceptCall(Context.current().withValue(MessageContext.DATA_KEY, ctx), new HeaderForwardingServerCall<>(call), headers, next);
} else {
// Don't attach a context if there is nothing to attach
return next.startCall(new HeaderForwardingServerCall<>(call), headers);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project Saiy-PS by brandall76.
the class GoogleCredentialsInterceptor method interceptCall.
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, final Channel next) {
return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata headers) throws StatusException {
Metadata cachedSaved;
URI uri = serviceUri(next, method);
synchronized (GoogleCredentialsInterceptor.this) {
Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
if (mLastMetadata == null || mLastMetadata != latestMetadata) {
mLastMetadata = latestMetadata;
mCached = toHeaders(mLastMetadata);
}
cachedSaved = mCached;
}
headers.merge(cachedSaved);
delegate().start(responseListener, headers);
}
};
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project zipkin-gcp by openzipkin.
the class UnaryClientCall method beginUnaryCall.
void beginUnaryCall(ClientCall.Listener<RespT> listener) {
try {
call.start(listener, new Metadata());
call.request(1);
call.sendMessage(request);
call.halfClose();
} catch (RuntimeException | Error t) {
call.cancel(null, t);
throw t;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project motan by weibocom.
the class MotanServerCallHandler method unaryCall.
private <ReqT, RespT> Listener<ReqT> unaryCall(final ServerCall<ReqT, RespT> call, final Metadata headers) {
final ServerCallStreamObserverImpl<ReqT, RespT> responseObserver = new ServerCallStreamObserverImpl<ReqT, RespT>(call);
// see ServerCalls
call.request(2);
return new ServerCall.Listener<ReqT>() {
ReqT request;
@Override
public void onMessage(ReqT request) {
this.request = request;
}
@SuppressWarnings("unchecked")
@Override
public void onHalfClose() {
if (request != null) {
DefaultRequest motanRequest = getBaseMotanRequest(headers);
String ip = NetUtils.getHostName(call.attributes().get(ServerCall.REMOTE_ADDR_KEY));
if (ip != null) {
motanRequest.setAttachment(URLParamType.host.getName(), ip);
}
if (responseStream) {
motanRequest.setArguments(new Object[] { request, responseObserver });
} else {
motanRequest.setArguments(new Object[] { request });
}
Response response = null;
try {
response = provider.call(motanRequest);
if (response.getValue() != null) {
responseObserver.onNext((RespT) response.getValue());
responseObserver.onCompleted();
}
} catch (Exception e) {
responseObserver.onError(e);
return;
}
responseObserver.freeze();
if (call.isReady()) {
onReady();
}
} else {
call.close(Status.INTERNAL.withDescription("Half-closed without a request"), new Metadata());
}
}
@Override
public void onCancel() {
responseObserver.cancelled = true;
if (responseObserver.onCancelHandler != null) {
responseObserver.onCancelHandler.run();
}
}
@Override
public void onReady() {
if (responseObserver.onReadyHandler != null) {
responseObserver.onReadyHandler.run();
}
}
};
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project pinpoint by naver.
the class AgentHeaderFactory method newHeader.
public Metadata newHeader() {
Metadata headers = new Metadata();
headers.put(Header.AGENT_ID_KEY, agentId);
headers.put(Header.APPLICATION_NAME_KEY, applicationName);
headers.put(Header.SERVICE_TYPE_KEY, Integer.toString(serviceType));
headers.put(Header.AGENT_START_TIME_KEY, Long.toString(agentStartTime));
if (!StringUtils.isEmpty(agentName)) {
headers.put(Header.AGENT_NAME_KEY, agentName);
}
return headers;
}
Aggregations