use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class GoogleAuthLibraryCallCredentials method applyRequestMetadata.
@Override
public void applyRequestMetadata(MethodDescriptor<?, ?> method, Attributes attrs, Executor appExecutor, final MetadataApplier applier) {
String authority = checkNotNull(attrs.get(ATTR_AUTHORITY), "authority");
final URI uri;
try {
uri = serviceUri(authority, method);
} catch (StatusException e) {
applier.fail(e.getStatus());
return;
}
appExecutor.execute(new Runnable() {
@Override
public void run() {
try {
// Credentials is expected to manage caching internally if the metadata is fetched over
// the network.
//
// TODO(zhangkun83): we don't know whether there is valid cache data. If there is, we
// would waste a context switch by always scheduling in executor. However, we have to
// do so because we can't risk blocking the network thread. This can be resolved after
// https://github.com/google/google-auth-library-java/issues/3 is resolved.
//
// Some implementations may return null here.
Map<String, List<String>> metadata = creds.getRequestMetadata(uri);
// Re-use the headers if getRequestMetadata() returns the same map. It may return a
// different map based on the provided URI, i.e., for JWT. However, today it does not
// cache JWT and so we won't bother tring to save its return value based on the URI.
Metadata headers;
synchronized (GoogleAuthLibraryCallCredentials.this) {
if (lastMetadata == null || lastMetadata != metadata) {
lastMetadata = metadata;
lastHeaders = toHeaders(metadata);
}
headers = lastHeaders;
}
applier.apply(headers);
} catch (Throwable e) {
applier.fail(Status.UNAUTHENTICATED.withCause(e));
}
}
});
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class HealthStatusManagerTest method checkStatusNotFound.
@Test
public void checkStatusNotFound() throws Exception {
//setup
manager.setStatus("", status);
HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("invalid").build();
@SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
//test
health.check(request, observer);
//verify
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
verify(observer, times(1)).onError(exception.capture());
assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
verify(observer, never()).onCompleted();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project core-java by SpineEventEngine.
the class StreamObserversShould method return_Error_extracted_form_StatusException_metadata.
@Test
public void return_Error_extracted_form_StatusException_metadata() {
final Error expectedError = Error.getDefaultInstance();
final Metadata metadata = MetadataConverter.toMetadata(expectedError);
final StatusException statusException = INVALID_ARGUMENT.asException(metadata);
assertEquals(expectedError, StreamObservers.fromStreamError(statusException).get());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project bookkeeper by apache.
the class TestStorageContainerResponseHandler method testStatusException.
@SuppressWarnings("unchecked")
@Test
public void testStatusException() {
StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
StatusException exception = new StatusException(Status.NOT_FOUND);
handler.accept(null, exception);
verify(observer, times(0)).onNext(any());
verify(observer, times(0)).onCompleted();
verify(observer, times(1)).onError(exception);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.
the class PinpointGrpcServer method close.
public void close(SocketStateCode toState) {
logger.info("close() will be started. ( remoteAddress:{}, agentInfo:{}, closeState:{}", remoteAddress, agentInfo.getAgentKey(), toState);
if (onCloseHandler != null) {
onCloseHandler.run();
}
synchronized (this) {
try {
SocketStateCode currentState = getState();
if (SocketStateCode.isRun(currentState)) {
if (toState == SocketStateCode.BEING_CLOSE_BY_SERVER || toState == SocketStateCode.BEING_CLOSE_BY_CLIENT) {
toState(toState);
requestObserver.onCompleted();
} else {
toState(toState);
requestObserver.onError(new StatusException(Status.UNKNOWN));
}
}
} catch (Exception e) {
// It could throw exception when requestObserver is already completed.
logger.warn("Exception occurred while requestObserver invokes onCompleted. message:{}", e.getMessage(), e);
}
try {
SocketStateCode currentStateCode = getState();
if (SocketStateCode.BEING_CLOSE_BY_SERVER == currentStateCode) {
toState(SocketStateCode.CLOSED_BY_SERVER);
} else if (SocketStateCode.BEING_CLOSE_BY_CLIENT == currentStateCode) {
toState(SocketStateCode.CLOSED_BY_CLIENT);
} else if (SocketStateCode.isClosed(currentStateCode)) {
logger.warn("stop(). Socket has closed state({}).", currentStateCode);
} else {
toState(SocketStateCode.ERROR_ILLEGAL_STATE_CHANGE);
logger.warn("stop(). Socket has unexpected state({})", currentStateCode);
}
} finally {
logger.info("{} <=> local all streamChannels will be close.", agentInfo.getAgentKey());
streamChannelRepository.close(StreamCode.STATE_CLOSED);
}
}
}
Aggregations