package dk.thoerup.circuitbreaker.web; import java.io.IOException; import java.net.URLEncoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import dk.thoerup.circuitbreaker.AccountingCircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreakerManager; import dk.thoerup.circuitbreaker.LoggingCircuitBreaker; public class ActionCommand implements Command { private boolean readOnly; public ActionCommand(boolean readOnly) { this.readOnly = readOnly; } public String execute(HttpServletRequest req, HttpServletResponse resp) { String action = req.getParameter("action"); String breaker = req.getParameter("breaker"); CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker(breaker); if (readOnly == false) { if (action.equalsIgnoreCase("reset")) cb.reset(); if (action.equalsIgnoreCase("tripbreaker")) cb.tripBreaker(); if (action.equalsIgnoreCase("resetcounters")) { AccountingCircuitBreaker acb = (AccountingCircuitBreaker) cb; acb.resetCounters(); } if (action.equalsIgnoreCase("clearlog") ) { LoggingCircuitBreaker lcb = (LoggingCircuitBreaker) cb; lcb.clearLog(); } } try { String uri = req.getRequestURI() + "?command=view&breaker=" + URLEncoder.encode(breaker, "UTF-8"); resp.sendRedirect( uri ); } catch(IOException e) { // what should be done here ? } return ""; } }