• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19971

01 Sep 2025 07:40AM UTC coverage: 88.568% (+0.02%) from 88.547%
#19971

push

github

web-flow
allow java21 in jre matrix (#12281)

34692 of 39170 relevant lines covered (88.57%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.33
/../servlet/src/main/java/io/grpc/servlet/GrpcServlet.java
1
/*
2
 * Copyright 2018 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.servlet;
18

19
import io.grpc.BindableService;
20
import io.grpc.ExperimentalApi;
21
import java.io.IOException;
22
import java.util.List;
23
import javax.servlet.http.HttpServlet;
24
import javax.servlet.http.HttpServletRequest;
25
import javax.servlet.http.HttpServletResponse;
26

27
/**
28
 * A simple servlet backed by a gRPC server. Must set {@code asyncSupported} to true. The {@code
29
 * /contextRoot/urlPattern} must match the gRPC services' path, which is
30
 * "/full-service-name/short-method-name".
31
 *
32
 * <p>The API is experimental. The authors would like to know more about the real usecases. Users
33
 * are welcome to provide feedback by commenting on
34
 * <a href=https://github.com/grpc/grpc-java/issues/5066>the tracking issue</a>.
35
 */
36
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5066")
37
public class GrpcServlet extends HttpServlet {
38
  private static final long serialVersionUID = 1L;
39

40
  @SuppressWarnings("serial")
41
  private final ServletAdapter servletAdapter;
42

43
  GrpcServlet(ServletAdapter servletAdapter) {
1✔
44
    this.servletAdapter = servletAdapter;
1✔
45
  }
1✔
46

47
  /**
48
   * Instantiate the servlet serving the given list of gRPC services. ServerInterceptors can be
49
   * added on each gRPC service by {@link
50
   * io.grpc.ServerInterceptors#intercept(BindableService, io.grpc.ServerInterceptor...)}
51
   */
52
  public GrpcServlet(List<? extends BindableService> bindableServices) {
53
    this(loadServices(bindableServices));
×
54
  }
×
55

56
  private static ServletAdapter loadServices(List<? extends BindableService> bindableServices) {
57
    ServletServerBuilder serverBuilder = new ServletServerBuilder();
×
58
    bindableServices.forEach(serverBuilder::addService);
×
59
    return serverBuilder.buildServletAdapter();
×
60
  }
61

62
  @Override
63
  protected final void doGet(HttpServletRequest request, HttpServletResponse response)
64
      throws IOException {
65
    servletAdapter.doGet(request, response);
×
66
  }
×
67

68
  @Override
69
  protected final void doPost(HttpServletRequest request, HttpServletResponse response)
70
      throws IOException {
71
    servletAdapter.doPost(request, response);
1✔
72
  }
1✔
73

74
  @Override
75
  public void destroy() {
76
    servletAdapter.destroy();
1✔
77
    super.destroy();
1✔
78
  }
1✔
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc