Ravi Srinivasan
2018-09-11 b9209f6413cb6985c0089f9677f4db9b52ca1395
commit | author | age
b9209f 1 /*
RS 2  * JBoss, Home of Professional Open Source
3  * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
4  * contributors by the @authors tag. See the copyright.txt in the
5  * distribution for a full listing of individual contributors.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package com.redhat.training.servlet;
18
19 import java.io.IOException;
20 import java.io.PrintWriter;
21
22 import javax.servlet.ServletException;
23 import javax.servlet.annotation.WebServlet;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 /**
29  * <p>
30  * A simple servlet taking advantage of features added in 3.0.
31  * </p>
32  *
33  * <p>
34  * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet
35  * @HttpServlet}.
36  * </p>
37  *
38  * @author Pete Muir
39  *
40  */
41 @SuppressWarnings("serial")
42 @WebServlet("/health")
43 public class PingServlet extends HttpServlet {
44
45     static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>";
46
47     static String PAGE_FOOTER = "</body></html>";
48
49     @Override
50     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
51         resp.setContentType("text/html");
52         PrintWriter writer = resp.getWriter();
53         writer.println(PAGE_HEADER);
54         writer.println("<h1>OK.</h1>");
55         writer.println("It is now " + new java.util.Date().toString() + " at the server.");
56         writer.println(PAGE_FOOTER);
57         writer.close();
58     }
59
60 }