Пример #1
0
 @After
 public void stopServer() throws Exception {
   if (_server.isRunning()) {
     _server.stop();
     _server.join();
   }
 }
Пример #2
0
 /** Stops the server */
 public void stop() {
   if (server.isRunning()) {
     try {
       server.stop();
       LOG.info("VRaptor context stopped");
     } catch (Exception e) {
       throw new VRaptorException("Unable to stop vraptor", e);
     }
   }
 }
 private void stopServer() {
   if (server != null && server.isRunning()) {
     try {
       server.stop();
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
 /** Shuts down the Jetty server. */
 public void shutdown() {
   // Remove listener for certificate events
   if (certificateListener != null) {
     CertificateManager.removeListener(certificateListener);
   }
   //noinspection ConstantConditions
   try {
     if (adminServer != null && adminServer.isRunning()) {
       adminServer.stop();
     }
   } catch (Exception e) {
     Log.error("Error stopping admin console server", e);
   }
   adminServer = null;
 }
Пример #5
0
 /** Starts a new request */
 public Request at(String relative) {
   if (!server.isRunning()) {
     throw new IllegalStateException("Jetty did not start properly or already stopped.");
   }
   return Restfulie.at("http://localhost:" + port + relative).accept("text/html");
 }
Пример #6
0
  protected void init() {

    String name = "structr-ui-test-" + System.nanoTime();

    // set up base path
    basePath = "/tmp/" + name;

    try {

      // HTML Servlet
      HtmlServlet htmlServlet = new HtmlServlet();
      ServletHolder htmlServletHolder = new ServletHolder(htmlServlet);
      Map<String, String> htmlInitParams = new HashMap<String, String>();

      htmlInitParams.put("Authenticator", "org.structr.web.auth.HttpAuthenticator");
      htmlServletHolder.setInitParameters(htmlInitParams);
      htmlServletHolder.setInitOrder(1);

      // CSV Servlet
      //			CsvServlet csvServlet     = new CsvServlet(DefaultResourceProvider.class.newInstance(),
      // PropertyView.All, AbstractNode.uuid);
      //			ServletHolder csvServletHolder    = new ServletHolder(csvServlet);
      //			Map<String, String> servletParams = new HashMap<String, String>();
      //
      //			servletParams.put("Authenticator", "org.structr.web.auth.HttpAuthenticator");
      //			csvServletHolder.setInitParameters(servletParams);
      //			csvServletHolder.setInitOrder(2);

      // WebSocket Servlet
      WebSocketServlet wsServlet = new WebSocketServlet(AbstractNode.uuid);
      ServletHolder wsServletHolder = new ServletHolder(wsServlet);
      Map<String, String> wsInitParams = new HashMap<String, String>();

      wsInitParams.put("Authenticator", "org.structr.web.auth.UiAuthenticator");
      wsInitParams.put("IdProperty", "uuid");
      wsServletHolder.setInitParameters(wsInitParams);
      wsServletHolder.setInitOrder(3);

      server =
          Structr.createServer(Ui.class, "structr UI", httpPort)
              .host(host)
              .basePath(basePath)
              .addServlet(htmlUrl + "/*", htmlServletHolder)
              .addServlet(wsUrl + "/*", wsServletHolder)
              // .addServlet("/structr/csv/*", csvServletHolder)

              .addResourceHandler(
                  "/structr", "src/main/resources/structr", true, new String[] {"index.html"})
              .enableRewriteFilter()
              // .logRequests(true)

              .resourceProvider(UiResourceProvider.class)
              .authenticator(UiAuthenticator.class)
              .start(false, true);

      running = server.isRunning();

    } catch (Throwable t) {

      t.printStackTrace();
    }
  }
Пример #7
0
  /* ------------------------------------------------------------ */
  protected void handleRequest() throws IOException {
    boolean error = false;

    String threadName = null;
    try {
      if (LOG.isDebugEnabled()) {
        threadName = Thread.currentThread().getName();
        Thread.currentThread().setName(threadName + " - " + _uri);
      }

      // Loop here to handle async request redispatches.
      // The loop is controlled by the call to async.unhandle in the
      // finally block below.  If call is from a non-blocking connector,
      // then the unhandle will return false only if an async dispatch has
      // already happened when unhandle is called.   For a blocking connector,
      // the wait for the asynchronous dispatch or timeout actually happens
      // within the call to unhandle().

      final Server server = _server;
      boolean handling = _request._async.handling() && server != null && server.isRunning();
      while (handling) {
        _request.setHandled(false);

        String info = null;
        try {
          _uri.getPort();
          info = URIUtil.canonicalPath(_uri.getDecodedPath());
          if (info == null && !_request.getMethod().equals(HttpMethods.CONNECT))
            throw new HttpException(400);
          _request.setPathInfo(info);

          if (_out != null) _out.reopen();

          if (_request._async.isInitial()) {
            _request.setDispatcherType(DispatcherType.REQUEST);
            _connector.customize(_endp, _request);
            server.handle(this);
          } else {
            _request.setDispatcherType(DispatcherType.ASYNC);
            server.handleAsync(this);
          }
        } catch (ContinuationThrowable e) {
          LOG.ignore(e);
        } catch (EofException e) {
          LOG.debug(e);
          error = true;
          _request.setHandled(true);
        } catch (RuntimeIOException e) {
          LOG.debug(e);
          error = true;
          _request.setHandled(true);
        } catch (HttpException e) {
          LOG.debug(e);
          error = true;
          _request.setHandled(true);
          _response.sendError(e.getStatus(), e.getReason());
        } catch (Throwable e) {
          if (e instanceof ThreadDeath) throw (ThreadDeath) e;

          LOG.warn(String.valueOf(_uri), e);
          error = true;
          _request.setHandled(true);
          _generator.sendError(info == null ? 400 : 500, null, null, true);
        } finally {
          handling = !_request._async.unhandle() && server.isRunning() && _server != null;
        }
      }
    } finally {
      if (threadName != null) Thread.currentThread().setName(threadName);

      if (_request._async.isUncompleted()) {
        _request._async.doComplete();

        if (_expect100Continue) {
          LOG.debug("100 continues not sent");
          // We didn't send 100 continues, but the latest interpretation
          // of the spec (see httpbis) is that the client will either
          // send the body anyway, or close.  So we no longer need to
          // do anything special here other than make the connection not persistent
          _expect100Continue = false;
          if (!_response.isCommitted()) _generator.setPersistent(false);
        }

        if (_endp.isOpen()) {
          if (error) {
            _endp.shutdownOutput();
            _generator.setPersistent(false);
            if (!_generator.isComplete()) _response.complete();
          } else {
            if (!_response.isCommitted() && !_request.isHandled())
              _response.sendError(HttpServletResponse.SC_NOT_FOUND);
            _response.complete();
            if (_generator.isPersistent()) _connector.persist(_endp);
          }
        } else {
          _response.complete();
        }

        _request.setHandled(true);
      }
    }
  }
Пример #8
0
 /**
  * {@inheritDoc}
  *
  * @see net.sourceforge.eclipsejetty.starter.common.ServerAdapter#isRunning()
  */
 @Override
 public boolean isRunning() {
   return server.isRunning();
 }