package dk.thoerup.curcuitbreaker.web; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.*; /** * This is a web interface for viewing and controlling the CircuitBreakers currently registered in CircuitBreakerManager *

* To use this servlet in you .war module just create a simple servlet that extends this class (instead of HttpServlet) * The new custom servlet doesn't need to implement any of the standard servlet methods - its all done in this implementation. * *

* Example: *

 * public class CircuitBreakerServlet extends CircuitBreakerServletBase {
 *   private static final long serialVersionUID = 1L;
 * }
 * 
*/ public class CircuitBreakerServletBase extends javax.servlet.http.HttpServlet { private static final long serialVersionUID = 1L; private Command getCommand(String command) throws ServletException { if (command == null || command.equals("list")) return new ListCircuitBreakers(); if (command.equals("view")) return new ViewCircuitBreaker(); throw new ServletException("No such action:" + command); } public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Command cmd = getCommand( req.getParameter("command")); String response = cmd.execute(req,resp); resp.setDateHeader("Expires", 0); resp.setHeader("Pragma", "no-cache"); resp.setHeader("Cache-Control", "no-cache"); resp.getWriter().print(response); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } }