/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/CircuitBreakerServletBase.java
ViewVC logotype

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/CircuitBreakerServletBase.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1291 - (hide annotations) (download)
Wed Apr 13 01:14:28 2011 UTC (13 years, 2 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/web/CircuitBreakerServletBase.java
File size: 2644 byte(s)
Only show 10 log entries in view command and add a new command do display the entire log
1 torben 467 package dk.thoerup.circuitbreaker.web;
2 torben 411
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 torben 417 *
22     * If you add a servlet init pameter to your deployment descriptor with the name 'readonly' and a integer value > 0, you can disable the
23     * control buttons:
24     * <p>
25     * &lt;init-param>&lt;param-name>readonly&lt;/param-name>&lt;param-value>1&lt;/param-value>&lt;/init-param>
26     * <!-- <init-param><param-name>readonly</param-name><param-value>1</param-value></init-param> -->
27     *
28 torben 411 */
29    
30 torben 416 public class CircuitBreakerServletBase extends javax.servlet.http.HttpServlet {
31 torben 411
32 torben 414 private static final long serialVersionUID = 1L;
33 torben 416
34 torben 417 private boolean readOnly = false;
35    
36    
37    
38     @Override
39     public void init() throws ServletException {
40     super.init();
41    
42     String readOnlyStr = getInitParameter("readonly");
43     if (readOnlyStr != null && readOnlyStr.trim().length() >0) {
44     int readOnlyInt = Integer.parseInt(readOnlyStr.trim());
45     readOnly = (readOnlyInt > 0);
46     }
47     }
48    
49 torben 416 private Command getCommand(String command) throws ServletException {
50     if (command == null || command.equals("list"))
51     return new ListCircuitBreakers();
52    
53     if (command.equals("view"))
54 torben 417 return new ViewCircuitBreaker(readOnly);
55     if (command.equals("action"))
56     return new ActionCommand(readOnly);
57 torben 1291 if (command.equals("log"))
58     return new LogViewCommand();
59 torben 416
60 torben 417 throw new ServletException("No such command:" + command);
61 torben 416 }
62 torben 414
63 torben 424 @Override
64 torben 411 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
65 torben 416 Command cmd = getCommand( req.getParameter("command"));
66 torben 411
67 torben 416 String response = cmd.execute(req,resp);
68 torben 411
69     resp.setDateHeader("Expires", 0);
70     resp.setHeader("Pragma", "no-cache");
71     resp.setHeader("Cache-Control", "no-cache");
72 torben 423 resp.setContentType("text/html");
73 torben 411
74     resp.getWriter().print(response);
75     }
76    
77 torben 416 @Override
78     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
79     doGet(req, resp);
80     }
81    
82 torben 411 }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20