Class ServletAdapter
HttpServletRequest
into gRPC request and lets a gRPC server process it, and
transforms the gRPC response into HttpServletResponse
. An adapter can be instantiated by
ServletServerBuilder.buildServletAdapter()
.
In a servlet, calling doPost(HttpServletRequest, HttpServletResponse)
inside
HttpServlet.doPost(HttpServletRequest, HttpServletResponse)
makes the servlet backed by
the gRPC server associated with the adapter. The servlet must support Asynchronous Processing and must be deployed to
a container that supports servlet 4.0 and enables HTTP/2.
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.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Call this method when the adapter is no longer needed.void
doGet
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) Call this method insideHttpServlet.doGet(HttpServletRequest, HttpServletResponse)
to serve gRPC GET request.void
doPost
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) Call this method insideHttpServlet.doPost(HttpServletRequest, HttpServletResponse)
to serve gRPC POST request.static boolean
isGrpc
(jakarta.servlet.http.HttpServletRequest request) Checks whether an incomingHttpServletRequest
may come from a gRPC client.<T> T
otherAdapter
(ServletAdapter.AdapterConstructor<T> constructor)
-
Method Details
-
otherAdapter
@ExperimentalApi("deephaven only, not submitted upstream") public <T> T otherAdapter(ServletAdapter.AdapterConstructor<T> constructor) -
doGet
public void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws IOException Call this method insideHttpServlet.doGet(HttpServletRequest, HttpServletResponse)
to serve gRPC GET request.This method is currently not implemented.
Note that in rare case gRPC client sends GET requests.
Do not modify
req
andresp
before or after calling this method. However, callingresp.setBufferSize()
before invocation is allowed.- Throws:
IOException
-
doPost
public void doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws IOException Call this method insideHttpServlet.doPost(HttpServletRequest, HttpServletResponse)
to serve gRPC POST request.Do not modify
req
andresp
before or after calling this method. However, callingresp.setBufferSize()
before invocation is allowed.- Throws:
IOException
-
destroy
public void destroy()Call this method when the adapter is no longer needed. The gRPC server will be terminated. -
isGrpc
public static boolean isGrpc(jakarta.servlet.http.HttpServletRequest request) Checks whether an incomingHttpServletRequest
may come from a gRPC client.- Returns:
- true if the request comes from a gRPC client
-