use of io.grpc.ServerInterceptor in project grpc-java by grpc.
the class AbstractInteropTest method startStaticServer.
protected static void startStaticServer(AbstractServerImplBuilder<?> builder, ServerInterceptor... interceptors) {
testServiceExecutor = Executors.newScheduledThreadPool(2);
List<ServerInterceptor> allInterceptors = ImmutableList.<ServerInterceptor>builder().add(TestUtils.recordServerCallInterceptor(serverCallCapture)).add(TestUtils.recordRequestHeadersInterceptor(requestHeadersCapture)).addAll(TestServiceImpl.interceptors()).add(interceptors).build();
builder.addService(ServerInterceptors.intercept(new TestServiceImpl(testServiceExecutor), allInterceptors));
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, serverStatsFactory);
try {
server = builder.build().start();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of io.grpc.ServerInterceptor in project grpc-java by grpc.
the class TransportCompressionTest method startServer.
/** Start server. */
@BeforeClass
public static void startServer() {
compressors.register(FZIPPER);
compressors.register(Codec.Identity.NONE);
startStaticServer(NettyServerBuilder.forPort(0).maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).compressorRegistry(compressors).decompressorRegistry(decompressors), new ServerInterceptor() {
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
Listener<ReqT> listener = next.startCall(call, headers);
// TODO(carl-mastrangelo): check that encoding was set.
call.setMessageCompression(true);
return listener;
}
});
}
use of io.grpc.ServerInterceptor in project pinpoint by naver.
the class SpanServerTestMain method newSpanBindableService.
private ServerServiceDefinition newSpanBindableService(Executor executor) throws Exception {
GrpcStreamConfiguration streamConfiguration = newStreamConfiguration();
FactoryBean<ServerInterceptor> interceptorFactory = new StreamExecutorServerInterceptorFactory(executor, Executors.newSingleThreadScheduledExecutor(), streamConfiguration);
((StreamExecutorServerInterceptorFactory) interceptorFactory).setBeanName("SpanService");
ServerInterceptor interceptor = interceptorFactory.getObject();
SpanService spanService = new SpanService(new MockDispatchHandler(), new DefaultServerRequestFactory());
return ServerInterceptors.intercept(spanService, interceptor);
}
use of io.grpc.ServerInterceptor in project pinpoint by naver.
the class AbstractServerServiceFactory method getObject.
@Override
public ServerServiceDefinition getObject() throws Exception {
// WARNING singleton
// final ServerInterceptor interceptor = FactoryBean<ServerInterceptor>.getObject();
final ServerInterceptor interceptor = serverInterceptor;
if (interceptor == null) {
return newServerServiceDefinition();
}
final ServerServiceDefinition serverServiceDefinition = newServerServiceDefinition();
return ServerInterceptors.intercept(serverServiceDefinition, interceptor);
}
use of io.grpc.ServerInterceptor in project pinpoint by naver.
the class GrpcReceiver method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (Boolean.FALSE == this.enable) {
logger.warn("{} is {}", this.beanName, enable);
return;
}
Objects.requireNonNull(this.beanName, "beanName");
Objects.requireNonNull(this.bindAddress, "bindAddress");
Objects.requireNonNull(this.addressFilter, "addressFilter");
Assert.isTrue(CollectionUtils.hasLength(this.serviceList), "serviceList must not be empty");
Objects.requireNonNull(this.serverOption, "serverOption");
if (grpcSslConfiguration != null) {
final SslServerConfig sslServerConfig = grpcSslConfiguration.toSslServerConfig();
this.serverFactory = new ServerFactory(beanName, this.bindAddress.getIp(), this.bindAddress.getPort(), this.executor, serverOption, sslServerConfig);
} else {
this.serverFactory = new ServerFactory(beanName, this.bindAddress.getIp(), this.bindAddress.getPort(), this.executor, serverOption);
}
ServerTransportFilter permissionServerTransportFilter = new PermissionServerTransportFilter(this.beanName, addressFilter);
this.serverFactory.addTransportFilter(permissionServerTransportFilter);
TransportMetadataFactory transportMetadataFactory = new TransportMetadataFactory(beanName);
// Mandatory interceptor
final ServerTransportFilter metadataTransportFilter = new MetadataServerTransportFilter(transportMetadataFactory);
this.serverFactory.addTransportFilter(metadataTransportFilter);
if (CollectionUtils.hasLength(transportFilterList)) {
for (ServerTransportFilter transportFilter : transportFilterList) {
this.serverFactory.addTransportFilter(transportFilter);
}
}
// Mandatory interceptor
ServerInterceptor transportMetadataServerInterceptor = new TransportMetadataServerInterceptor();
this.serverFactory.addInterceptor(transportMetadataServerInterceptor);
if (CollectionUtils.hasLength(serverInterceptorList)) {
for (ServerInterceptor serverInterceptor : serverInterceptorList) {
this.serverFactory.addInterceptor(serverInterceptor);
}
}
if (channelzRegistry != null) {
this.serverFactory.setChannelzRegistry(channelzRegistry);
}
// Add service
addService();
this.server = serverFactory.build();
if (logger.isInfoEnabled()) {
logger.info("Start {} server {}", this.beanName, this.server);
}
try {
this.server.start();
} catch (Throwable th) {
final Throwable rootCause = NestedExceptionUtils.getRootCause(th);
if (rootCause instanceof BindException) {
logger.error("Server bind failed. {} address:{}", this.beanName, this.bindAddress, rootCause);
} else {
logger.error("Server start failed. {} address:{}", this.beanName, this.bindAddress);
}
throw th;
}
}
Aggregations