@After
 public void dispose() throws Exception {
   server1.stop();
   server2.stop();
   balancer.stop();
   client.stop();
 }
 @After
 public void destroy() throws Exception {
   if (server != null) {
     server.stop();
     server.join();
   }
   if (proxy != null) {
     proxy.stop();
     proxy.join();
   }
   factory.stop();
 }
  public void testServerShutdownAfterConnect() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final CountDownLatch stopLatch = new CountDownLatch(1);

    Server server = new Server();
    Connector connector = new SocketConnector();
    server.addConnector(connector);
    server.setHandler(
        new AbstractHandler() {
          public void handle(
              String target,
              Request request,
              HttpServletRequest httpRequest,
              HttpServletResponse httpResponse)
              throws IOException, ServletException {
            request.setHandled(true);
            if (target.endsWith("/connect")) {
              connectLatch.countDown();
              try {
                Thread.sleep(10000);
              } catch (InterruptedException e) {
                stopLatch.countDown();
              }
            }
          }
        });
    server.start();
    try {
      RHTTPClient client = createClient(connector.getLocalPort(), "test5");
      try {
        final CountDownLatch serverLatch = new CountDownLatch(1);
        client.addClientListener(
            new ClientListener.Adapter() {
              @Override
              public void connectClosed() {
                serverLatch.countDown();
              }
            });
        client.connect();

        assertTrue(connectLatch.await(2000, TimeUnit.MILLISECONDS));

        server.stop();
        assertTrue(stopLatch.await(2000, TimeUnit.MILLISECONDS));

        assertTrue(serverLatch.await(2000, TimeUnit.MILLISECONDS));
      } finally {
        destroyClient(client);
      }
    } finally {
      server.stop();
    }
  }
  @AfterClass
  public static void stopServer() throws Exception {
    httpClient.stop();

    server.stop();
    server.join();
  }
 public void endServer() {
   if (updateTask != null) {
     updateTask.cancel();
   }
   if (context != null) {
     try {
       context.stop();
       if (!context.isStopped()) {
         hcw.getDataBukkit().writeError("Context failed to stop.");
       }
     } catch (Exception e) {
       hcw.getDataBukkit().writeError(e);
     }
   }
   if (server != null) {
     try {
       server.stop();
       if (!server.isStopped()) {
         hcw.getDataBukkit().writeError("Server failed to stop.");
       }
     } catch (Exception e) {
       hcw.getDataBukkit().writeError(e);
     }
   }
 }
Beispiel #6
0
  public static void main(String[] args) throws Exception {
    Server server = new Server();

    SslContextFactory factory = new SslContextFactory();
    factory.setKeyStorePath("src/test/keystore.jks");
    factory.setKeyStorePassword("storepass");
    factory.setKeyManagerPassword("keypass");
    SslSocketConnector connector = new SslSocketConnector(factory);
    connector.setPort(8443);
    server.addConnector(connector);
    InheritedChannelConnector inheritedChannelConnector = new InheritedChannelConnector();
    inheritedChannelConnector.setPort(8080);
    server.addConnector(inheritedChannelConnector);

    WebAppContext context = new WebAppContext();
    context.setConfigurationClasses(
        new String[] {WebInfConfiguration.class.getName(), WebXmlConfiguration.class.getName()});
    context.setResourceBase("src/main/webapp");
    context.setContextPath(CONTEXT_PATH);
    context.setParentLoaderPriority(true);
    server.setHandler(context);

    try {
      server.start();
      if (!context.isAvailable()) throw new IllegalStateException("context deployed failed");
      server.join();
    } catch (Exception e) {
      server.stop();
      throw new IllegalStateException("jetty failed to start: " + e.getMessage(), e);
    }
  }
Beispiel #7
0
 public void stop() {
   try {
     server.stop();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 @After
 public void stopServer() throws Exception {
   if (server != null) {
     server.stop();
     server.join();
   }
 }
Beispiel #9
0
  public static void main(String[] args) throws Exception {
    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.setConnectors(new Connector[] {connector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      while (System.in.available() == 0) {
        Thread.sleep(5000);
      }
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
  /** Stops Jetty. */
  private void stopJetty() {
    // Jetty does not really stop the server if port is busy.
    try {
      if (httpSrv != null) {
        // If server was successfully started, deregister ports.
        if (httpSrv.isStarted()) ctx.ports().deregisterPorts(getClass());

        // Record current interrupted status of calling thread.
        boolean interrupted = Thread.interrupted();

        try {
          httpSrv.stop();
        } finally {
          // Reset interrupted flag on calling thread.
          if (interrupted) Thread.currentThread().interrupt();
        }
      }
    } catch (InterruptedException ignored) {
      if (log.isDebugEnabled()) log.debug("Thread has been interrupted.");

      Thread.currentThread().interrupt();
    } catch (Exception e) {
      U.error(log, "Failed to stop Jetty HTTP server.", e);
    }
  }
 public void stop() {
   try {
     server.stop();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Beispiel #12
0
 public void stop() {
   try {
     server.stop();
   } catch (Exception ex) {
     logger.error("Cannot stop jetty", ex);
   }
 }
 @After
 public void destroyConnector() throws Exception {
   if (server != null) {
     server.stop();
     server.join();
   }
 }
 @After
 public void stopServer() throws Exception {
   if (_server.isRunning()) {
     _server.stop();
     _server.join();
   }
 }
 public void shutDown() {
   try {
     underlyingServer.stop();
   } catch (Exception e) {
     logger.error("Problem shutting down HTTP Server", e);
   }
 }
  /**
   * @param httppost A well-formed {@link HttpUriRequest}
   * @param owlsim An initialized {@link OWLSim} instance. It is expected that the {@link
   *     OWLGraphWrapper} is already loaded with an ontology.
   * @throws Exception
   */
  protected void runServerCommunication(HttpUriRequest httppost, OwlSim owlsim) throws Exception {
    // create server
    Server server = new Server(9031);
    server.setHandler(new OWLServer(g, owlsim));
    try {
      server.start();

      // create a client
      HttpClient httpclient = new DefaultHttpClient();

      // run request
      LOG.info("Executing=" + httppost);
      HttpResponse response = httpclient.execute(httppost);
      LOG.info("Executed=" + httpclient);

      // check response
      HttpEntity entity = response.getEntity();
      StatusLine statusLine = response.getStatusLine();
      LOG.info("Status=" + statusLine.getStatusCode());
      if (statusLine.getStatusCode() == 200) {
        String responseContent = EntityUtils.toString(entity);
        handleResponse(responseContent);
      } else {
        EntityUtils.consumeQuietly(entity);
      }
    } finally {
      // clean up
      server.stop();
    }
  }
  @Override
  public void tearDown() throws Exception {

    // if (log.isInfoEnabled())
    log.warn("tearing down test: " + getName());

    if (m_fixture != null) {

      m_fixture.stop();

      m_fixture = null;
    }

    if (m_indexManager != null && namespace != null) {

      dropTripleStore(m_indexManager, namespace);

      m_indexManager = null;
    }

    namespace = null;

    m_rootURL = null;
    m_serviceURL = null;

    m_repo.close();

    m_client.stop();

    log.info("tear down done");

    super.tearDown();
  }
Beispiel #18
0
 // NOTE: we retry server stop because of a concurrency issue inside Jetty that is not
 // easily solvable.
 public synchronized void stop() throws Exception {
   LOG.debug("shutting down jetty on port {}", m_config.port());
   try {
     m_server.stop();
   } catch (final InterruptedException e) {
     LOG.debug(
         "Interrupted while attempting to shut down Jetty, propagating interrupt and trying again.",
         e);
     Thread.currentThread().interrupt();
     m_server.stop();
   } catch (final RuntimeException e) {
     LOG.debug("An exception occurred while attempting to shut down Jetty.", e);
     m_server.stop();
     throw e;
   }
 }
 public void shutdown() {
   try {
     server.stop();
   } catch (Exception e) {
     LOGGER.error("", e);
   }
 }
  @Test
  public void testReplaceHandler() throws Exception {
    ServletContextHandler servletContextHandler = new ServletContextHandler();
    ServletHolder sh = new ServletHolder(new TestServlet());
    servletContextHandler.addServlet(sh, "/foo");
    final AtomicBoolean contextInit = new AtomicBoolean(false);
    final AtomicBoolean contextDestroy = new AtomicBoolean(false);

    servletContextHandler.addEventListener(
        new ServletContextListener() {

          @Override
          public void contextInitialized(ServletContextEvent sce) {
            if (sce.getServletContext() != null) contextInit.set(true);
          }

          @Override
          public void contextDestroyed(ServletContextEvent sce) {
            if (sce.getServletContext() != null) contextDestroy.set(true);
          }
        });
    ServletHandler shandler = servletContextHandler.getServletHandler();

    ResourceHandler rh = new ResourceHandler();

    servletContextHandler.insertHandler(rh);
    assertEquals(shandler, servletContextHandler.getServletHandler());
    assertEquals(rh, servletContextHandler.getHandler());
    assertEquals(rh.getHandler(), shandler);
    _server.setHandler(servletContextHandler);
    _server.start();
    assertTrue(contextInit.get());
    _server.stop();
    assertTrue(contextDestroy.get());
  }
Beispiel #21
0
  void runJettyBenchmark(int port, int iterations, int clientCount, int delay, int responseSize)
      throws Exception {
    System.gc();
    Server s = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    s.addConnector(connector);

    s.setHandler(new JettyHandler(delay, responseSize));
    s.start();

    HTTPClient[] clients = new HTTPClient[clientCount];
    for (int i = 0; i < clientCount; i++) {
      clients[i] = new HTTPClient(iterations, port);
    }

    long start = System.nanoTime();
    for (int i = 0; i < clientCount; i++) {
      clients[i].start();
    }
    for (int i = 0; i < clientCount; i++) {
      clients[i].join();
    }
    long finish = System.nanoTime();

    double seconds = (finish - start) / (1000d * 1000d * 1000d);
    double rate = (iterations * clientCount) / seconds;
    System.out.printf("Simple bench did %.2f iterations / sec.\n", rate);

    s.stop();
    s.join();
    s = null;
  }
Beispiel #22
0
  @Override
  public void run() {

    System.out.println(
        "/n>>> About to execute: " + Runner.class.getName() + ".run() to clean up before JV");
    if (webapp.isStarted()) {
      try {
        webapp.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (connector.isStarted()) {
      try {
        connector.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (server.isStarted()) {
      try {
        server.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    System.out.println(">>> Finished execution: " + Runner.class.getName() + ".run()");
  }
Beispiel #23
0
 @AfterTest
 public void stop() throws Exception {
   JOptionPane.showConfirmDialog(null, "Stop");
   server.stop();
   server = null;
   JOptionPane.showConfirmDialog(null, "Stoped");
 }
Beispiel #24
0
  public static void main(String[] args) {
    ApplicationContext appContext =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/jetty-server.xml");

    Server server = appContext.getBean(Server.class);

    try {

      WebAppContext webAppContext = new WebAppContext();
      webAppContext.setContextPath("/");
      webAppContext.setWar(IDE_WAR_LOCATION);

      webAppContext.setServer(server);
      server.setHandler(webAppContext);
      server.start();
      server.join();
      System.out.println("Zorba web server running....");
      System.out.println("Enter :q and hit enter to quit: ");
      while (true) {

        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        String str = bufferRead.readLine();
        if (str != null && !str.isEmpty())
          if (str.trim().equals(":q")) {
            System.out.println("exiting system...");
            server.stop();
            System.exit(0);
          }
        Thread.sleep(1000);
      }

    } catch (Exception e) {
      logger.error("Error when starting", e);
    }
  }
  @AfterMethod(alwaysRun = true)
  public void tearDown() throws Exception {
    if (server != null) {
      server.stop();
    }

    httpClient.close();
  }
  protected void shutdownTest(ITestContext context) throws Exception {
    connectorServer.stop();
    connectorServer.destroy();

    serverConnectorFramework.release();
    localConnectorFramework.release();
    Reporter.log("Jetty Server Stopped", true);
  }
 public void restart() {
   try {
     adminServer.stop();
     adminServer.start();
   } catch (Exception e) {
     Log.error(e.getMessage(), e);
   }
 }
  @After
  public void destroyCometDServer() throws Exception {
    destroyPage();

    server.stop();
    server.join();
    cookies.clear();
  }
Beispiel #29
0
 /** Stops this server. */
 public void stopServer() throws IOException {
   try {
     httpServer.stop(); // yes, .stop() throws "Exception"
   } catch (Exception e) {
     LOG.warning("Fatal error stopping http server.", e);
   }
   LOG.fine("server shutdown.");
 }
  public void run() {
    while (serverSocket != null) {
      Socket socket = null;
      try {
        socket = serverSocket.accept();
        socket.setSoLinger(false, 0);
        LineNumberReader lin = new LineNumberReader(new InputStreamReader(socket.getInputStream()));

        String key = lin.readLine();
        if (!this.key.equals(key)) {
          continue;
        }
        String cmd = lin.readLine();
        if ("stop".equals(cmd)) {
          try {
            socket.close();
          } catch (Exception e) {
            LOGGER.debug("Exception when stopping server", e);
          }
          try {
            socket.close();
          } catch (Exception e) {
            LOGGER.debug("Exception when stopping server", e);
          }
          try {
            serverSocket.close();
          } catch (Exception e) {
            LOGGER.debug("Exception when stopping server", e);
          }

          serverSocket = null;

          try {
            LOGGER.info("Stopping server due to received '{}' command...", cmd);
            server.stop();
          } catch (Exception e) {
            LOGGER.error("Exception when stopping server", e);
          }

          // We've stopped the server. No point hanging around any more...
          return;
        } else {
          LOGGER.info("Unsupported monitor operation");
        }
      } catch (Exception e) {
        LOGGER.error("Exception during monitoring Server", e);
      } finally {
        if (socket != null) {
          try {
            socket.close();
          } catch (Exception e) {
            LOGGER.debug("Exception when stopping server", e);
          }
        }
        socket = null;
      }
    }
  }