protected Handler createHandler() {
    /*TODO: Context "/hub" is here only for backwards compatibility.
    src/org/openqa/grid/web/Hub.java has the following line:
    ''' root.addServlet("/wd/hub/*", DriverServlet.class.getName()); '''
    This seems to imply "/wd/hub" is the correct Context to use everywhere.
    */
    org.mortbay.jetty.servlet.Context old_root =
        new org.mortbay.jetty.servlet.Context(
            server, "/hub", org.mortbay.jetty.servlet.Context.SESSIONS);
    old_root.addServlet(new ServletHolder(new AndroidNativeDriverServlet()), "/*");

    org.mortbay.jetty.servlet.Context root =
        new org.mortbay.jetty.servlet.Context(
            server, "/wd/hub", org.mortbay.jetty.servlet.Context.SESSIONS);
    root.addServlet(new ServletHolder(new AndroidNativeDriverServlet()), "/*");

    org.mortbay.jetty.servlet.Context gridhealthstatus =
        new org.mortbay.jetty.servlet.Context(
            server, "/wd/hub/status", org.mortbay.jetty.servlet.Context.NO_SECURITY);
    gridhealthstatus.addServlet(new ServletHolder(new HealthStatusServlet()), "/*");

    HandlerList handlers = new HandlerList();

    handlers.setHandlers(
        new org.mortbay.jetty.Handler[] {old_root, gridhealthstatus, root, new DefaultHandler()});
    return handlers;
  }
 public static void start(String resourceBase) throws Exception {
   FileServer.resourceBase = resourceBase;
   if (isStarted()) return;
   server = new Server(HTTP_PORT);
   server.setConnectors(
       new Connector[] {getPlainConnector(HTTP_PORT), getSslConnector(HTTPS_PORT)});
   ResourceHandler resourceHandler = new ResourceHandler();
   resourceHandler.setResourceBase(resourceBase);
   HandlerList handlers = new HandlerList();
   handlers.setHandlers(new Handler[] {resourceHandler, new DefaultHandler()});
   server.setHandler(handlers);
   server.start();
 }
Пример #3
0
  public S2RobotWebServer(final int port, final File docRoot) {
    this.port = port;
    this.docRoot = docRoot;

    server = new Server(port);

    final ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setWelcomeFiles(new String[] {"index.html"});
    resource_handler.setResourceBase(docRoot.getAbsolutePath());
    Log.info("serving " + resource_handler.getBaseResource());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resource_handler, new DefaultHandler()});
    server.setHandler(handlers);
  }
Пример #4
0
  protected void startHttpServer() throws Exception {
    Server server = new Server();
    SocketConnector sc = new SocketConnector();
    sc.setHost("127.0.0.1");
    sc.setPort(7777);
    server.addConnector(sc);
    ResourceHandler rhandler = new ResourceHandler();
    rhandler.setResourceBase(getSrcHtdocs().getAbsolutePath());

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {rhandler, new DefaultHandler()});
    server.setHandler(handlers);

    this.httpServer = server;
    server.start();
  }
  /**
   * Verify that repositories which have both releases and snapshots disabled aren't touched when
   * looking for plugin prefix mappings.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4771");

    final List<String> requestedUris = Collections.synchronizedList(new ArrayList<String>());

    AbstractHandler logHandler =
        new AbstractHandler() {
          public void handle(
              String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
              throws IOException, ServletException {
            requestedUris.add(request.getRequestURI());
          }
        };

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(logHandler);
    handlerList.addHandler(new DefaultHandler());

    Server server = new Server(0);
    server.setHandler(handlerList);
    server.start();

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    try {
      verifier.setAutoclean(false);
      verifier.deleteDirectory("target");
      Properties filterProps = verifier.newDefaultFilterProperties();
      filterProps.setProperty("@port@", Integer.toString(server.getConnectors()[0].getLocalPort()));
      verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", filterProps);
      verifier.addCliOption("-U");
      verifier.addCliOption("-s");
      verifier.addCliOption("settings.xml");
      verifier.executeGoal("mng4771:touch");
      verifier.verifyErrorFreeLog();
      fail("Build should have failed to resolve unknown prefix");
    } catch (VerificationException e) {
      assertTrue(true);
    } finally {
      verifier.resetStreams();
      server.stop();
    }

    assertTrue(requestedUris.toString(), requestedUris.isEmpty());
  }
  /**
   * Starts the web server on the default {@link #PORT}. The given resourceBase is used to be the
   * ROOT directory that serves the default context.
   *
   * <p><b>Don't forget to stop the returned HttpServer after the test</b>
   *
   * @param resourceBase the base of resources for the default context
   * @throws Exception if the test fails
   */
  protected void startWebServer(final String resourceBase) throws Exception {
    if (server_ != null) {
      throw new IllegalStateException("startWebServer() can not be called twice");
    }
    server_ = new Server(PORT);

    final WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    context.setResourceBase(resourceBase);

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(resourceBase);
    resourceHandler.getMimeTypes().addMimeMapping("js", "application/javascript");

    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resourceHandler, context});
    server_.setHandler(handlers);
    server_.setHandler(resourceHandler);
    server_.start();
  }
  public static void main(String[] args) throws Exception {
    SocketConnector socketConnector = new SocketConnector();
    socketConnector.setPort(6080);

    SslSocketConnector sslSocketConnector = new SslSocketConnector();
    sslSocketConnector.setPort(6443);
    //        sslSocketConnector.setNeedClientAuth(true); //why not use mutual authentication when
    // we can

    String serverKeystore =
        MockHttpListenerWithAuthentication.class
            .getClassLoader()
            .getResource("cert/serverkeystore.jks")
            .getPath();
    sslSocketConnector.setKeystore(serverKeystore);
    sslSocketConnector.setKeyPassword("serverpass");
    String serverTruststore =
        MockHttpListenerWithAuthentication.class
            .getClassLoader()
            .getResource("cert/servertruststore.jks")
            .getPath();
    sslSocketConnector.setTruststore(serverTruststore);
    sslSocketConnector.setTrustPassword("serverpass");

    server.addConnector(socketConnector);
    server.addConnector(sslSocketConnector);

    SecurityHandler securityHandler = createBasicAuthenticationSecurityHandler();

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(securityHandler);
    handlerList.addHandler(
        new AbstractHandler() {
          @Override
          public void handle(
              String s,
              HttpServletRequest httpServletRequest,
              HttpServletResponse httpServletResponse,
              int i)
              throws IOException, ServletException {
            System.out.println("uri: " + httpServletRequest.getRequestURI());
            System.out.println("queryString: " + httpServletRequest.getQueryString());
            System.out.println("method: " + httpServletRequest.getMethod());

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(httpServletRequest.getInputStream(), baos);

            System.out.println("body: " + baos.toString());

            PrintWriter writer = httpServletResponse.getWriter();
            writer.append("testsvar");
            Random r = new Random();
            for (int j = 0; j < 10; j++) {
              int value = r.nextInt(Integer.MAX_VALUE);
              writer.append(value + "");
            }
            System.out.println();
            writer.close();
            httpServletResponse.setStatus(HttpServletResponse.SC_OK);
          }
        });

    server.addHandler(handlerList);
    server.start();
  }
Пример #8
0
  @BeforeClass
  @SuppressWarnings("unchecked")
  public static void setUpClass() throws Exception {

    URI webappUri = EmbeddedJettyServer.extractResourceDir("webapp", true);
    server = new Server(port);

    ServletHolder jerseyServletHolder = new ServletHolder(ServletContainer.class);
    jerseyServletHolder.setInitParameter(
        "com.sun.jersey.config.property.resourceConfigClass",
        "com.sun.jersey.api.core.PackagesResourceConfig");
    jerseyServletHolder.setInitParameter(
        "com.sun.jersey.config.property.packages", "fr.inria.edelweiss.kgramserver.webservice");
    Context servletCtx = new Context(server, "/kgram", Context.SESSIONS);
    servletCtx.addServlet(jerseyServletHolder, "/*");
    logger.info("----------------------------------------------");
    logger.info("Corese/KGRAM endpoint started on http://localhost:" + port + "/kgram");
    logger.info("----------------------------------------------");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setWelcomeFiles(new String[] {"index.html"});
    resource_handler.setResourceBase(webappUri.getRawPath());
    ContextHandler staticContextHandler = new ContextHandler();
    staticContextHandler.setContextPath("/");
    staticContextHandler.setHandler(resource_handler);
    logger.info("----------------------------------------------");
    logger.info("Corese/KGRAM webapp UI started on http://localhost:" + port);
    logger.info("----------------------------------------------");

    HandlerList handlers_s1 = new HandlerList();
    handlers_s1.setHandlers(new Handler[] {staticContextHandler, servletCtx});
    server.setHandler(handlers_s1);

    try {
      server.start();
    } catch (Exception e) {
      e.printStackTrace();
    }

    ///// Data extraction
    humanData = File.createTempFile("human", ".rdf");
    FileWriter fw = new FileWriter(humanData);
    InputStream is =
        RDFS_entailmentsTest.class.getClassLoader().getResourceAsStream("human_2007_09_11.rdf");
    int c;
    while ((c = is.read()) != -1) {
      fw.write(c);
    }
    is.close();
    fw.close();

    humanOnt = File.createTempFile("humanOnt", ".rdfs");
    fw = new FileWriter(humanOnt);
    is = RDFS_entailmentsTest.class.getClassLoader().getResourceAsStream("human_2007_09_11.rdfs");
    while ((c = is.read()) != -1) {
      fw.write(c);
    }
    is.close();
    fw.close();

    ///// Data upload
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client.resource(new URI("http://localhost:" + port + "/kgram"));

    // entailments
    MultivaluedMap formData = new MultivaluedMapImpl();
    formData.add("entailments", "true");
    service.path("sparql").path("reset").post(formData);

    formData = new MultivaluedMapImpl();
    formData.add("remote_path", humanOnt.getAbsolutePath());
    service.path("sparql").path("load").post(formData);

    formData = new MultivaluedMapImpl();
    formData.add("remote_path", humanData.getAbsolutePath());
    service.path("sparql").path("load").post(formData);
  }