Class GrpcServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
io.grpc.servlet.GrpcServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5066") public class GrpcServlet extends javax.servlet.http.HttpServlet
A simple servlet backed by a gRPC server. Must set asyncSupported to true. The /contextRoot/urlPattern must match the gRPC services' path, which is "/full-service-name/short-method-name".

The API is experimental. The authors would like to know more about the real usecases. Users are welcome to provide feedback by commenting on the tracking issue.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
     
    private final ServletAdapter
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrpcServlet(ServletAdapter servletAdapter)
     
    GrpcServlet(List<? extends BindableService> bindableServices)
    Instantiate the servlet serving the given list of gRPC services.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected final void
    doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     
    protected final void
    doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     
    private static ServletAdapter
    loadServices(List<? extends BindableService> bindableServices)
     

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service

    Methods inherited from class javax.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • loadServices

      private static ServletAdapter loadServices(List<? extends BindableService> bindableServices)
    • doGet

      protected final void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Throws:
      IOException
    • doPost

      protected final void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      IOException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface javax.servlet.Servlet
      Overrides:
      destroy in class javax.servlet.GenericServlet