Search in sources :

Example 1 with ServerInterceptor

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);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ServerInterceptor(io.grpc.ServerInterceptor) IOException(java.io.IOException)

Example 2 with ServerInterceptor

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;
        }
    });
}
Also used : ForwardingClientCallListener(io.grpc.ForwardingClientCallListener) Listener(io.grpc.ServerCall.Listener) ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) BeforeClass(org.junit.BeforeClass)

Example 3 with ServerInterceptor

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);
}
Also used : GrpcStreamConfiguration(com.navercorp.pinpoint.collector.grpc.config.GrpcStreamConfiguration) ServerInterceptor(io.grpc.ServerInterceptor) SpanService(com.navercorp.pinpoint.collector.receiver.grpc.service.SpanService) DefaultServerRequestFactory(com.navercorp.pinpoint.collector.receiver.grpc.service.DefaultServerRequestFactory) StreamExecutorServerInterceptorFactory(com.navercorp.pinpoint.collector.receiver.grpc.service.StreamExecutorServerInterceptorFactory)

Example 4 with ServerInterceptor

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);
}
Also used : ServerInterceptor(io.grpc.ServerInterceptor) ServerServiceDefinition(io.grpc.ServerServiceDefinition)

Example 5 with ServerInterceptor

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;
    }
}
Also used : TransportMetadataServerInterceptor(com.navercorp.pinpoint.grpc.server.TransportMetadataServerInterceptor) ServerInterceptor(io.grpc.ServerInterceptor) TransportMetadataFactory(com.navercorp.pinpoint.grpc.server.TransportMetadataFactory) TransportMetadataServerInterceptor(com.navercorp.pinpoint.grpc.server.TransportMetadataServerInterceptor) BindException(java.net.BindException) ServerFactory(com.navercorp.pinpoint.grpc.server.ServerFactory) ServerTransportFilter(io.grpc.ServerTransportFilter) MetadataServerTransportFilter(com.navercorp.pinpoint.grpc.server.MetadataServerTransportFilter) MetadataServerTransportFilter(com.navercorp.pinpoint.grpc.server.MetadataServerTransportFilter) SslServerConfig(com.navercorp.pinpoint.grpc.security.SslServerConfig)

Aggregations

ServerInterceptor (io.grpc.ServerInterceptor)37 Metadata (io.grpc.Metadata)23 Test (org.junit.Test)15 ServerCall (io.grpc.ServerCall)10 ServerCallHandler (io.grpc.ServerCallHandler)9 SimpleForwardingServerCallListener (io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener)7 Server (io.grpc.Server)6 IOException (java.io.IOException)6 SimpleForwardingServerCall (io.grpc.ForwardingServerCall.SimpleForwardingServerCall)4 Status (io.grpc.Status)4 ManagedChannel (io.grpc.ManagedChannel)3 Listener (io.grpc.ServerCall.Listener)3 ServerTransportFilter (io.grpc.ServerTransportFilter)3 InetSocketAddress (java.net.InetSocketAddress)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TraceContext (brave.propagation.TraceContext)2 GrpcStreamConfiguration (com.navercorp.pinpoint.collector.grpc.config.GrpcStreamConfiguration)2 DefaultServerRequestFactory (com.navercorp.pinpoint.collector.receiver.grpc.service.DefaultServerRequestFactory)2 StreamExecutorServerInterceptorFactory (com.navercorp.pinpoint.collector.receiver.grpc.service.StreamExecutorServerInterceptorFactory)2 MetadataServerTransportFilter (com.navercorp.pinpoint.grpc.server.MetadataServerTransportFilter)2