/[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 2448 - (hide annotations) (download)
Fri Mar 20 08:52:49 2015 UTC (9 years, 2 months ago) by torben
Original Path: miscJava/CircuitBreaker/src/dk/thoerup/circuitbreaker/web/CircuitBreakerServletBase.java
File size: 3023 byte(s)
move java components to java folder
1 torben 467 package dk.thoerup.circuitbreaker.web;
2 torben 411
3     import java.io.IOException;
4    
5     import javax.servlet.ServletException;
6 torben 1307 import javax.servlet.ServletRegistration;
7 torben 411 import javax.servlet.http.*;
8    
9     /**
10     * This is a web interface for viewing and controlling the CircuitBreakers currently registered in CircuitBreakerManager
11     * <p>
12 torben 414 * To use this servlet in you .war module just create a simple servlet that extends this class (instead of HttpServlet)
13     * The new custom servlet doesn't need to implement any of the standard servlet methods - its all done in this implementation.
14     *
15     * <p>
16 torben 411 * Example:
17     * <pre>
18 torben 414 * public class CircuitBreakerServlet extends CircuitBreakerServletBase {
19 torben 411 * private static final long serialVersionUID = 1L;
20     * }
21     * </pre>
22 torben 417 *
23     * If you add a servlet init pameter to your deployment descriptor with the name 'readonly' and a integer value > 0, you can disable the
24     * control buttons:
25     * <p>
26     * &lt;init-param>&lt;param-name>readonly&lt;/param-name>&lt;param-value>1&lt;/param-value>&lt;/init-param>
27     * <!-- <init-param><param-name>readonly</param-name><param-value>1</param-value></init-param> -->
28 torben 1307 *
29     * You could also configure it dynamically from a ContextListener:
30     * ServletRegistration.Dynamic dynconf = sce.getServletContext().addServlet("circuitbreaker", dk.thoerup.circuitbreaker.web.CircuitBreakerServletBase.class );
31     * dynconf.addMapping("/CircuitBreakerServlet");
32     * dynconf.setInitParameter("readonly", "1");
33 torben 417 *
34 torben 411 */
35    
36 torben 416 public class CircuitBreakerServletBase extends javax.servlet.http.HttpServlet {
37 torben 411
38 torben 414 private static final long serialVersionUID = 1L;
39 torben 416
40 torben 417 private boolean readOnly = false;
41    
42    
43    
44     @Override
45     public void init() throws ServletException {
46     super.init();
47    
48     String readOnlyStr = getInitParameter("readonly");
49     if (readOnlyStr != null && readOnlyStr.trim().length() >0) {
50     int readOnlyInt = Integer.parseInt(readOnlyStr.trim());
51     readOnly = (readOnlyInt > 0);
52     }
53     }
54    
55 torben 416 private Command getCommand(String command) throws ServletException {
56     if (command == null || command.equals("list"))
57     return new ListCircuitBreakers();
58    
59     if (command.equals("view"))
60 torben 417 return new ViewCircuitBreaker(readOnly);
61     if (command.equals("action"))
62     return new ActionCommand(readOnly);
63 torben 1291 if (command.equals("log"))
64     return new LogViewCommand();
65 torben 416
66 torben 417 throw new ServletException("No such command:" + command);
67 torben 416 }
68 torben 414
69 torben 424 @Override
70 torben 411 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
71 torben 416 Command cmd = getCommand( req.getParameter("command"));
72 torben 411
73 torben 416 String response = cmd.execute(req,resp);
74 torben 411
75     resp.setDateHeader("Expires", 0);
76     resp.setHeader("Pragma", "no-cache");
77     resp.setHeader("Cache-Control", "no-cache");
78 torben 423 resp.setContentType("text/html");
79 torben 411
80     resp.getWriter().print(response);
81     }
82    
83 torben 416 @Override
84     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
85     doGet(req, resp);
86     }
87    
88 torben 411 }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20