Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.status;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.concurrent.TimeUnit;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.log4j.Logger;
- public class StatusServlet extends HttpServlet {
- private static Logger log = Logger.getLogger(StatusServlet.class.getName());
- public void init() throws ServletException {
- log.info("StatusServlet.init()");
- }
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- res.setContentType("text/html");
- PrintWriter w = res.getWriter();
- w.println("<html><head><title>Status Monitor</title></head>");
- w.println("<body><h1>Status monitoring is ONLINE.</h1></body></html>");
- w.flush(); // Commits the response
- w.close();
- }
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- // ...
- }
- public void destroy() {
- log.info("Entering StatusServlet.destroy()");
- try {
- log.info("Simulating long shutdown sequence.");
- TimeUnit.MINUTES.sleep(5);
- log.info("Simulation complete--sequence finished.");
- } catch (InterruptedException e) {
- log.info("Caught the interrupt exception while sleeping.");
- }
- log.info("Exiting StatusServlet.destroy()");
- }
- public String getServletInfo() {
- return "....";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement