Java Code Examples for io.grpc.internal.GrpcUtil#getGrpcUserAgent()

The following examples show how to use io.grpc.internal.GrpcUtil#getGrpcUserAgent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CronetClientTransport.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
CronetClientTransport(
    StreamBuilderFactory streamFactory,
    InetSocketAddress address,
    String authority,
    @Nullable String userAgent,
    Executor executor,
    int maxMessageSize,
    boolean alwaysUsePut,
    TransportTracer transportTracer) {
  this.address = Preconditions.checkNotNull(address, "address");
  this.authority = authority;
  this.userAgent = GrpcUtil.getGrpcUserAgent("cronet", userAgent);
  this.maxMessageSize = maxMessageSize;
  this.alwaysUsePut = alwaysUsePut;
  this.executor = Preconditions.checkNotNull(executor, "executor");
  this.streamFactory = Preconditions.checkNotNull(streamFactory, "streamFactory");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.attrs = Attributes.newBuilder()
      .set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)
      .build();
}
 
Example 2
Source File: OkHttpClientTransport.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
OkHttpClientTransport(InetSocketAddress address, String authority, @Nullable String userAgent,
    Executor executor, @Nullable SSLSocketFactory sslSocketFactory,
    @Nullable HostnameVerifier hostnameVerifier, ConnectionSpec connectionSpec,
    int maxMessageSize, int initialWindowSize, @Nullable ProxyParameters proxy,
    Runnable tooManyPingsRunnable, int maxInboundMetadataSize, TransportTracer transportTracer) {
  this.address = Preconditions.checkNotNull(address, "address");
  this.defaultAuthority = authority;
  this.maxMessageSize = maxMessageSize;
  this.initialWindowSize = initialWindowSize;
  this.executor = Preconditions.checkNotNull(executor, "executor");
  serializingExecutor = new SerializingExecutor(executor);
  // Client initiated streams are odd, server initiated ones are even. Server should not need to
  // use it. We start clients at 3 to avoid conflicting with HTTP negotiation.
  nextStreamId = 3;
  this.sslSocketFactory = sslSocketFactory;
  this.hostnameVerifier = hostnameVerifier;
  this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec");
  this.stopwatchFactory = GrpcUtil.STOPWATCH_SUPPLIER;
  this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
  this.proxy = proxy;
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.maxInboundMetadataSize = maxInboundMetadataSize;
  this.transportTracer = Preconditions.checkNotNull(transportTracer);
  initTransportTracer();
}
 
Example 3
Source File: OkHttpClientTransportTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void addDefaultUserAgent() throws Exception {
  initTransport();
  MockStreamListener listener = new MockStreamListener();
  OkHttpClientStream stream =
      clientTransport.newStream(method, new Metadata(), CallOptions.DEFAULT);
  stream.start(listener);
  Header userAgentHeader = new Header(GrpcUtil.USER_AGENT_KEY.name(),
          GrpcUtil.getGrpcUserAgent("okhttp", null));
  List<Header> expectedHeaders = Arrays.asList(SCHEME_HEADER, METHOD_HEADER,
          new Header(Header.TARGET_AUTHORITY, "notarealauthority:80"),
          new Header(Header.TARGET_PATH, "/" + method.getFullMethodName()),
          userAgentHeader, CONTENT_TYPE_HEADER, TE_HEADER);
  verify(frameWriter, timeout(TIME_OUT_MS))
      .synStream(eq(false), eq(false), eq(3), eq(0), eq(expectedHeaders));
  getStream(3).cancel(Status.CANCELLED);
  shutdownAndVerify();
}
 
Example 4
Source File: OkHttpClientTransportTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void addDefaultUserAgent() throws Exception {
  initTransport();
  MockStreamListener listener = new MockStreamListener();
  OkHttpClientStream stream =
      clientTransport.newStream(method, new Metadata(), CallOptions.DEFAULT);
  stream.start(listener);
  Header userAgentHeader = new Header(GrpcUtil.USER_AGENT_KEY.name(),
          GrpcUtil.getGrpcUserAgent("okhttp", null));
  List<Header> expectedHeaders = Arrays.asList(HTTP_SCHEME_HEADER, METHOD_HEADER,
          new Header(Header.TARGET_AUTHORITY, "notarealauthority:80"),
          new Header(Header.TARGET_PATH, "/" + method.getFullMethodName()),
          userAgentHeader, CONTENT_TYPE_HEADER, TE_HEADER);
  verify(frameWriter, timeout(TIME_OUT_MS))
      .synStream(eq(false), eq(false), eq(3), eq(0), eq(expectedHeaders));
  getStream(3).cancel(Status.CANCELLED);
  shutdownAndVerify();
}
 
Example 5
Source File: InProcessTransport.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private InProcessTransport(String name, int maxInboundMetadataSize, String authority,
    String userAgent, Attributes eagAttrs,
    Optional<ServerListener> optionalServerListener, boolean includeCauseWithStatus) {
  this.name = name;
  this.clientMaxInboundMetadataSize = maxInboundMetadataSize;
  this.authority = authority;
  this.userAgent = GrpcUtil.getGrpcUserAgent("inprocess", userAgent);
  checkNotNull(eagAttrs, "eagAttrs");
  this.attributes = Attributes.newBuilder()
      .set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)
      .set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttrs)
      .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, new InProcessSocketAddress(name))
      .set(Grpc.TRANSPORT_ATTR_LOCAL_ADDR, new InProcessSocketAddress(name))
      .build();
  this.optionalServerListener = optionalServerListener;
  logId = InternalLogId.allocate(getClass(), name);
  this.includeCauseWithStatus = includeCauseWithStatus;
}
 
Example 6
Source File: OkHttpClientTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Create a transport connected to a fake peer for test.
 */
@VisibleForTesting
OkHttpClientTransport(
    String userAgent,
    Executor executor,
    FrameReader frameReader,
    FrameWriter testFrameWriter,
    int nextStreamId,
    Socket socket,
    Supplier<Stopwatch> stopwatchFactory,
    @Nullable Runnable connectingCallback,
    SettableFuture<Void> connectedFuture,
    int maxMessageSize,
    int initialWindowSize,
    Runnable tooManyPingsRunnable,
    TransportTracer transportTracer) {
  address = null;
  this.maxMessageSize = maxMessageSize;
  this.initialWindowSize = initialWindowSize;
  defaultAuthority = "notarealauthority:80";
  this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
  this.executor = Preconditions.checkNotNull(executor, "executor");
  serializingExecutor = new SerializingExecutor(executor);
  this.testFrameReader = Preconditions.checkNotNull(frameReader, "frameReader");
  this.testFrameWriter = Preconditions.checkNotNull(testFrameWriter, "testFrameWriter");
  this.socket = Preconditions.checkNotNull(socket, "socket");
  this.nextStreamId = nextStreamId;
  this.stopwatchFactory = stopwatchFactory;
  this.connectionSpec = null;
  this.connectingCallback = connectingCallback;
  this.connectedFuture = Preconditions.checkNotNull(connectedFuture, "connectedFuture");
  this.proxy = null;
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.maxInboundMetadataSize = Integer.MAX_VALUE;
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  initTransportTracer();
}
 
Example 7
Source File: NettyClientTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
NettyClientTransport(
    SocketAddress address, Class<? extends Channel> channelType,
    Map<ChannelOption<?>, ?> channelOptions, EventLoopGroup group,
    ProtocolNegotiator negotiator, int flowControlWindow, int maxMessageSize,
    int maxHeaderListSize, long keepAliveTimeNanos, long keepAliveTimeoutNanos,
    boolean keepAliveWithoutCalls, String authority, @Nullable String userAgent,
    Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes,
    LocalSocketPicker localSocketPicker) {
  this.negotiator = Preconditions.checkNotNull(negotiator, "negotiator");
  this.remoteAddress = Preconditions.checkNotNull(address, "address");
  this.group = Preconditions.checkNotNull(group, "group");
  this.channelType = Preconditions.checkNotNull(channelType, "channelType");
  this.channelOptions = Preconditions.checkNotNull(channelOptions, "channelOptions");
  this.flowControlWindow = flowControlWindow;
  this.maxMessageSize = maxMessageSize;
  this.maxHeaderListSize = maxHeaderListSize;
  this.keepAliveTimeNanos = keepAliveTimeNanos;
  this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
  this.keepAliveWithoutCalls = keepAliveWithoutCalls;
  this.authorityString = authority;
  this.authority = new AsciiString(authority);
  this.userAgent = new AsciiString(GrpcUtil.getGrpcUserAgent("netty", userAgent));
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.eagAttributes = Preconditions.checkNotNull(eagAttributes, "eagAttributes");
  this.localSocketPicker = Preconditions.checkNotNull(localSocketPicker, "localSocketPicker");
}
 
Example 8
Source File: InProcessTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
public InProcessTransport(
    String name, int maxInboundMetadataSize, String authority, String userAgent) {
  this.name = name;
  this.clientMaxInboundMetadataSize = maxInboundMetadataSize;
  this.authority = authority;
  this.userAgent = GrpcUtil.getGrpcUserAgent("inprocess", userAgent);
}
 
Example 9
Source File: CronetClientTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
CronetClientTransport(
    StreamBuilderFactory streamFactory,
    InetSocketAddress address,
    String authority,
    @Nullable String userAgent,
    Attributes eagAttrs,
    Executor executor,
    int maxMessageSize,
    boolean alwaysUsePut,
    TransportTracer transportTracer,
    boolean useGetForSafeMethods,
    boolean usePutForIdempotentMethods) {
  this.address = Preconditions.checkNotNull(address, "address");
  this.logId = InternalLogId.allocate(getClass(), address.toString());
  this.authority = authority;
  this.userAgent = GrpcUtil.getGrpcUserAgent("cronet", userAgent);
  this.maxMessageSize = maxMessageSize;
  this.alwaysUsePut = alwaysUsePut;
  this.executor = Preconditions.checkNotNull(executor, "executor");
  this.streamFactory = Preconditions.checkNotNull(streamFactory, "streamFactory");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.attrs = Attributes.newBuilder()
      .set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)
      .set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttrs)
      .build();
  this.useGetForSafeMethods = useGetForSafeMethods;
  this.usePutForIdempotentMethods = usePutForIdempotentMethods;
}
 
Example 10
Source File: NettyClientTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
NettyClientTransport(
    SocketAddress address, ChannelFactory<? extends Channel> channelFactory,
    Map<ChannelOption<?>, ?> channelOptions, EventLoopGroup group,
    ProtocolNegotiator negotiator, boolean autoFlowControl, int flowControlWindow,
    int maxMessageSize, int maxHeaderListSize,
    long keepAliveTimeNanos, long keepAliveTimeoutNanos,
    boolean keepAliveWithoutCalls, String authority, @Nullable String userAgent,
    Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes,
    LocalSocketPicker localSocketPicker, ChannelLogger channelLogger,
    boolean useGetForSafeMethods) {
  this.negotiator = Preconditions.checkNotNull(negotiator, "negotiator");
  this.negotiationScheme = this.negotiator.scheme();
  this.remoteAddress = Preconditions.checkNotNull(address, "address");
  this.group = Preconditions.checkNotNull(group, "group");
  this.channelFactory = channelFactory;
  this.channelOptions = Preconditions.checkNotNull(channelOptions, "channelOptions");
  this.autoFlowControl = autoFlowControl;
  this.flowControlWindow = flowControlWindow;
  this.maxMessageSize = maxMessageSize;
  this.maxHeaderListSize = maxHeaderListSize;
  this.keepAliveTimeNanos = keepAliveTimeNanos;
  this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
  this.keepAliveWithoutCalls = keepAliveWithoutCalls;
  this.authorityString = authority;
  this.authority = new AsciiString(authority);
  this.userAgent = new AsciiString(GrpcUtil.getGrpcUserAgent("netty", userAgent));
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.eagAttributes = Preconditions.checkNotNull(eagAttributes, "eagAttributes");
  this.localSocketPicker = Preconditions.checkNotNull(localSocketPicker, "localSocketPicker");
  this.logId = InternalLogId.allocate(getClass(), remoteAddress.toString());
  this.channelLogger = Preconditions.checkNotNull(channelLogger, "channelLogger");
  this.useGetForSafeMethods = useGetForSafeMethods;
}
 
Example 11
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
OkHttpClientTransport(
    InetSocketAddress address,
    String authority,
    @Nullable String userAgent,
    Attributes eagAttrs,
    Executor executor,
    @Nullable SocketFactory socketFactory,
    @Nullable SSLSocketFactory sslSocketFactory,
    @Nullable HostnameVerifier hostnameVerifier,
    ConnectionSpec connectionSpec,
    int maxMessageSize,
    int initialWindowSize,
    @Nullable HttpConnectProxiedSocketAddress proxiedAddr,
    Runnable tooManyPingsRunnable,
    int maxInboundMetadataSize,
    TransportTracer transportTracer,
    boolean useGetForSafeMethods) {
  this.address = Preconditions.checkNotNull(address, "address");
  this.defaultAuthority = authority;
  this.maxMessageSize = maxMessageSize;
  this.initialWindowSize = initialWindowSize;
  this.executor = Preconditions.checkNotNull(executor, "executor");
  serializingExecutor = new SerializingExecutor(executor);
  // Client initiated streams are odd, server initiated ones are even. Server should not need to
  // use it. We start clients at 3 to avoid conflicting with HTTP negotiation.
  nextStreamId = 3;
  this.socketFactory = socketFactory == null ? SocketFactory.getDefault() : socketFactory;
  this.sslSocketFactory = sslSocketFactory;
  this.hostnameVerifier = hostnameVerifier;
  this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec");
  this.stopwatchFactory = GrpcUtil.STOPWATCH_SUPPLIER;
  this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
  this.proxiedAddr = proxiedAddr;
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.maxInboundMetadataSize = maxInboundMetadataSize;
  this.transportTracer = Preconditions.checkNotNull(transportTracer);
  this.logId = InternalLogId.allocate(getClass(), address.toString());
  this.attributes = Attributes.newBuilder()
      .set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttrs).build();
  this.useGetForSafeMethods = useGetForSafeMethods;
  initTransportTracer();
}
 
Example 12
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Create a transport connected to a fake peer for test.
 */
@VisibleForTesting
OkHttpClientTransport(
    String userAgent,
    Executor executor,
    FrameReader frameReader,
    FrameWriter testFrameWriter,
    OkHttpFrameLogger testFrameLogger,
    int nextStreamId,
    Socket socket,
    Supplier<Stopwatch> stopwatchFactory,
    @Nullable Runnable connectingCallback,
    SettableFuture<Void> connectedFuture,
    int maxMessageSize,
    int initialWindowSize,
    Runnable tooManyPingsRunnable,
    TransportTracer transportTracer) {
  useGetForSafeMethods = false;
  address = null;
  this.maxMessageSize = maxMessageSize;
  this.initialWindowSize = initialWindowSize;
  defaultAuthority = "notarealauthority:80";
  this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
  this.executor = Preconditions.checkNotNull(executor, "executor");
  serializingExecutor = new SerializingExecutor(executor);
  this.socketFactory = SocketFactory.getDefault();
  this.testFrameReader = Preconditions.checkNotNull(frameReader, "frameReader");
  this.testFrameWriter = Preconditions.checkNotNull(testFrameWriter, "testFrameWriter");
  this.testFrameLogger = Preconditions.checkNotNull(testFrameLogger, "testFrameLogger");
  this.socket = Preconditions.checkNotNull(socket, "socket");
  this.nextStreamId = nextStreamId;
  this.stopwatchFactory = stopwatchFactory;
  this.connectionSpec = null;
  this.connectingCallback = connectingCallback;
  this.connectedFuture = Preconditions.checkNotNull(connectedFuture, "connectedFuture");
  this.proxiedAddr = null;
  this.tooManyPingsRunnable =
      Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
  this.maxInboundMetadataSize = Integer.MAX_VALUE;
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.logId = InternalLogId.allocate(getClass(), String.valueOf(socket.getInetAddress()));
  initTransportTracer();
}