You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StatusServlet.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.util;
  5. import java.io.IOException;
  6. import java.io.Writer;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. @SuppressWarnings("serial")
  15. public class StatusServlet extends HttpServlet {
  16. public static DateFormat dfHuman = new SimpleDateFormat(
  17. "yyyy-MM-dd HH:mm:ss");
  18. /**
  19. * Version number of this release. For example "5.0.0".
  20. */
  21. public static final String VERSION;
  22. /**
  23. * Major version number. For example 5 in 5.1.0.
  24. */
  25. public static final int VERSION_MAJOR;
  26. /**
  27. * Minor version number. For example 1 in 5.1.0.
  28. */
  29. public static final int VERSION_MINOR;
  30. /**
  31. * Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
  32. */
  33. public static final String VERSION_BUILD;
  34. /* Initialize version numbers from string replaced by build-script. */
  35. static {
  36. if ("@VERSION@".equals("@" + "VERSION" + "@")) {
  37. VERSION = "5.9.9-INTERNAL-NONVERSIONED-DEBUG-BUILD";
  38. } else {
  39. VERSION = "@VERSION@";
  40. }
  41. final String[] digits = VERSION.split("\\.");
  42. VERSION_MAJOR = Integer.parseInt(digits[0]);
  43. VERSION_MINOR = Integer.parseInt(digits[1]);
  44. VERSION_BUILD = digits[2];
  45. }
  46. @Override
  47. public void init(javax.servlet.ServletConfig servletConfig)
  48. throws javax.servlet.ServletException {
  49. super.init(servletConfig);
  50. }
  51. @Override
  52. protected void service(HttpServletRequest request,
  53. HttpServletResponse response) throws ServletException, IOException {
  54. Writer w = response.getWriter();
  55. // not cacheable
  56. response.setHeader("Cache-Control", "no-cache");
  57. response.setHeader("Pragma", "no-cache");
  58. response.setDateHeader("Expires", 0);
  59. response.setContentType("text/html");
  60. String p = "";
  61. p += "<p>StatusServlet " + dfHuman.format(new Date()) + "</p>";
  62. for (int i = 0; i < 30; i++) {
  63. System.gc();
  64. }
  65. long inUse = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
  66. .freeMemory());
  67. p += "<p>Memory:<br />\n<memused>" + inUse
  68. + "</memused> (Used)<br />\n" + "<memtotal>"
  69. + Runtime.getRuntime().totalMemory()
  70. + "<memtotal> (Total)<br />\n" + "<memfree>"
  71. + Runtime.getRuntime().freeMemory() + "<memfree> (Free)</p>\n";
  72. w.write("<html>\n" + p + "</html>\n");
  73. }
  74. }