1 |
torben |
411 |
package dk.thoerup.curcuitbreaker.web;
|
2 |
|
|
|
3 |
|
|
import java.io.IOException;
|
4 |
|
|
|
5 |
|
|
import javax.servlet.ServletException;
|
6 |
|
|
import javax.servlet.http.*;
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* This is a web interface for viewing and controlling the CircuitBreakers currently registered in CircuitBreakerManager
|
10 |
|
|
* <p>
|
11 |
torben |
414 |
* To use this servlet in you .war module just create a simple servlet that extends this class (instead of HttpServlet)
|
12 |
|
|
* The new custom servlet doesn't need to implement any of the standard servlet methods - its all done in this implementation.
|
13 |
|
|
*
|
14 |
|
|
* <p>
|
15 |
torben |
411 |
* Example:
|
16 |
|
|
* <pre>
|
17 |
torben |
414 |
* public class CircuitBreakerServlet extends CircuitBreakerServletBase {
|
18 |
torben |
411 |
* private static final long serialVersionUID = 1L;
|
19 |
|
|
* }
|
20 |
|
|
* </pre>
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
torben |
416 |
public class CircuitBreakerServletBase extends javax.servlet.http.HttpServlet {
|
24 |
torben |
411 |
|
25 |
torben |
414 |
private static final long serialVersionUID = 1L;
|
26 |
torben |
416 |
|
27 |
|
|
private Command getCommand(String command) throws ServletException {
|
28 |
|
|
if (command == null || command.equals("list"))
|
29 |
|
|
return new ListCircuitBreakers();
|
30 |
|
|
|
31 |
|
|
if (command.equals("view"))
|
32 |
|
|
return new ViewCircuitBreaker();
|
33 |
|
|
|
34 |
|
|
throw new ServletException("No such action:" + command);
|
35 |
|
|
}
|
36 |
torben |
414 |
|
37 |
torben |
411 |
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
38 |
torben |
416 |
Command cmd = getCommand( req.getParameter("command"));
|
39 |
torben |
411 |
|
40 |
torben |
416 |
String response = cmd.execute(req,resp);
|
41 |
torben |
411 |
|
42 |
|
|
resp.setDateHeader("Expires", 0);
|
43 |
|
|
resp.setHeader("Pragma", "no-cache");
|
44 |
|
|
resp.setHeader("Cache-Control", "no-cache");
|
45 |
|
|
|
46 |
|
|
resp.getWriter().print(response);
|
47 |
|
|
}
|
48 |
|
|
|
49 |
torben |
416 |
@Override
|
50 |
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
51 |
|
|
doGet(req, resp);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
torben |
411 |
}
|