In Chapter 7, Implementing WebSockets, in the Negotiated subprotocols section, we introduced the multiprotocol function. With this function, we can establish what protocol to use for the client-server communication, and even use of a custom protocol to use in secure system, for example.
Servlets 3.1 introduce the javax.servlet.http.HttpUpgradeHandler interface. This interface encapsulates the upgrade protocol processing. The upgrade protocol allows us to switch from the HTTP base protocol to another new protocol.
In the following example, we will call a servlet accepting an header, and it will upgrade the current HTTP base protocol to a custom echo protocol. This is the servlet implementation:
@WebServlet(urlPatterns = { "/UpgradeServlet" })
public class UpgradeServlet extends HttpServlet {
...
protected void doGet(HttpServletRequest request, HttpServletResponse...