Class ServletAdapter
- java.lang.Object
- 
- io.grpc.servlet.ServletAdapter
 
- 
 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5066") public final class ServletAdapter extends Object An adapter that transformsHttpServletRequestinto gRPC request and lets a gRPC server process it, and transforms the gRPC response intoHttpServletResponse. An adapter can be instantiated byServletServerBuilder.buildServletAdapter().In a servlet, calling doPost(HttpServletRequest, HttpServletResponse)insideHttpServlet.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. 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Call this method when the adapter is no longer needed.voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)Call this method insideHttpServlet.doGet(HttpServletRequest, HttpServletResponse)to serve gRPC GET request.voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)Call this method insideHttpServlet.doPost(HttpServletRequest, HttpServletResponse)to serve gRPC POST request.static booleanisGrpc(javax.servlet.http.HttpServletRequest request)Checks whether an incomingHttpServletRequestmay come from a gRPC client.
 
- 
- 
- 
Method Detail- 
doGetpublic void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOExceptionCall 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 reqandrespbefore or after calling this method. However, callingresp.setBufferSize()before invocation is allowed.- Throws:
- IOException
 
 - 
doPostpublic void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOExceptionCall this method insideHttpServlet.doPost(HttpServletRequest, HttpServletResponse)to serve gRPC POST request.Do not modify reqandrespbefore or after calling this method. However, callingresp.setBufferSize()before invocation is allowed.- Throws:
- IOException
 
 - 
destroypublic void destroy() Call this method when the adapter is no longer needed. The gRPC server will be terminated.
 - 
isGrpcpublic static boolean isGrpc(javax.servlet.http.HttpServletRequest request) Checks whether an incomingHttpServletRequestmay come from a gRPC client.- Returns:
- true if the request comes from a gRPC client
 
 
- 
 
-