List of usage examples for javax.servlet.http HttpServletRequest upgrade
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException;
From source file:org.sample.protocolhandler.UpgradeServlet.java
/** * Processes requests for both HTTP//from w w w . j a v a 2 s . c om * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet UpgradeServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet UpgradeServlet at " + request.getContextPath() + "</h1>"); if (request.getHeader("Upgrade").equals("echo")) { response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS); response.setHeader("Connection", "Upgrade"); response.setHeader("Upgrade", "echo"); request.upgrade(MyProtocolHandler.class); System.out.println("Request upgraded to MyProtocolHandler"); } out.println("</body>"); out.println("</html>"); } }