Java Code Examples for javax.servlet.http.HttpServletRequest.upgrade()

The following are Jave code examples for showing how to use upgrade() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Mastering-Java-EE-Development-with-WildFly   File: UpgradeServlet.java   View Source Code Vote up 6 votes
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(SC_SWITCHING_PROTOCOLS);
			response.setHeader("Connection", "Upgrade");
			response.setHeader("Upgrade", "echo");
			request.upgrade(SampleProtocolHandler.class);
			logger.info("Request upgraded to SampleProtocolHandler");
		}
		out.println("</body>");
		out.println("</html>");
	}
}