Beispiel #1
0
 private void testAlreadyRunning() throws Exception {
   Server server = Server.createWebServer("-webPort", "8182", "-properties", "null");
   server.start();
   assertTrue(server.getStatus().indexOf("server running") >= 0);
   Server server2 = Server.createWebServer("-webPort", "8182", "-properties", "null");
   assertEquals("Not started", server2.getStatus());
   try {
     server2.start();
     fail();
   } catch (Exception e) {
     assertTrue(e.toString().indexOf("port may be in use") >= 0);
     assertTrue(server2.getStatus().indexOf("could not be started") >= 0);
   }
   server.stop();
 }
  @Override
  public boolean rawInvocation(Request request, Response response) throws Exception {
    if (Play.mode.isDev() && request.path.equals("/@db")) {
      response.status = Http.StatusCode.MOVED;

      // For H2 embeded database, we'll also start the Web console
      if (h2Server != null) {
        h2Server.stop();
      }
      h2Server = org.h2.tools.Server.createWebServer();
      h2Server.start();

      response.setHeader("Location", "http://localhost:8082/");
      return true;
    }
    return false;
  }
  @Action(
      value = "h2-db-web-console-start",
      results = {@Result(name = "sucess", location = "h2-db-web-console-stop.jsp")})
  public String start() throws Exception {
    synchronized (lock) {
      Server server = (Server) application.get("h2DbWebServer");
      if (server != null && server.isRunning(false)) {
        URL urlObj = new URL(ServletActionContext.getRequest().getRequestURL().toString());
        StringBuffer sb = new StringBuffer();
        sb.append(urlObj.getProtocol())
            .append("://")
            .append(urlObj.getHost())
            .append(":")
            .append(server.getPort())
            .append("/");
        url = sb.toString();
      } else {
        server =
            Server.createWebServer(
                "-webPort", port.toString(), "-baseDir", ".", "-webAllowOthers", "-webDaemon");
        server.start();
        application.put("h2DbWebServer", server);

        URL urlObj = new URL(ServletActionContext.getRequest().getRequestURL().toString());
        StringBuffer sb = new StringBuffer();
        sb.append(urlObj.getProtocol())
            .append("://")
            .append(urlObj.getHost())
            .append(":")
            .append(port)
            .append("/");
        url = sb.toString();
      }
    }

    return "sucess";
  }