Ejemplo n.º 1
0
  private void initialize(int port) throws Exception {
    System.out.println("Starting web server...");

    webServer = new Server(port);

    ServletContextHandler requestHandler = new ServletContextHandler();
    requestHandler.setContextPath("/");
    requestHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
    requestHandler.addServlet(new ServletHolder(new RequestServlet()), "/xmlrpc/*");

    ServletContextHandler uploadHandler = new ServletContextHandler();
    uploadHandler.setContextPath("/upload");
    uploadHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
    uploadHandler.addFilter(MultiPartFilter.class, "/", FilterMapping.ALL);
    uploadHandler.addServlet(new ServletHolder(new DesignUploadServlet()), "/");

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);
    resourceHandler.setResourceBase("./web");
    resourceHandler.setWelcomeFiles(new String[] {"index.html"});

    HandlerList handlers = new HandlerList();
    handlers.addHandler(requestHandler);
    handlers.addHandler(uploadHandler);
    handlers.addHandler(resourceHandler);

    webServer.setHandler(handlers);
  }
 @Override
 public Handler createHandler() throws ConfigurationException {
   // set up jersey servlet
   ResourceConfig config = new ResourceConfig();
   // we package everything into a runnable jar using OneJAR, which provides its own class loader.
   // as the result, Jersey classpath scanning won't work properly for now.
   // hopefully this can be fixed soon. right now we need to specify classes.
   config.register(Echo.class);
   config.register(LogService.class);
   config.register(PageService.class);
   config.register(TaskService.class);
   // binder for HK2 to inject the controller to Jersey resource instances
   config.register(
       new AbstractBinder() {
         @Override
         protected void configure() {
           bind(controller).to(Controller.class);
         }
       });
   ServletContainer container = new ServletContainer(config);
   ServletContextHandler handler = new ServletContextHandler();
   handler.setContextPath("/DownloaderPool");
   handler.addServlet(new ServletHolder(container), "/*");
   return handler;
 }
  @Before
  public void setUp() throws Exception {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setOutputBufferSize(4096);
    _connector = new ServerConnector(_server, new HttpConnectionFactory(http_config));

    _server.setConnectors(new Connector[] {_connector});
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/ctx");
    _server.setHandler(context);
    _servletHandler = context.getServletHandler();

    ServletHolder holder = new ServletHolder(_servlet0);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/path/*");

    ServletHolder holder2 = new ServletHolder(_servlet2);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder2, "/path2/*");

    _server.start();
    _port = _connector.getLocalPort();

    _owp.set(0);
    _oda.set(0);
    _read.set(0);
  }
Ejemplo n.º 4
0
  public static void main(String[] args) throws Exception {

    Server server = new Server(Integer.valueOf(System.getenv("PORT")));
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(
        new ServletHolder(
            new HttpServlet() {
              protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                  throws ServletException, IOException {
                resp.getWriter()
                    .print(
                        "<h1>umlet-github web service</h1>"
                            + "<p>"
                            + "<a href=\"https://github.com/CalumJEadie/umlet-github/\">"
                            + "https://github.com/CalumJEadie/umlet-github/"
                            + "</a>"
                            + "</p>");
              }
            }),
        "/");

    context.addServlet(new ServletHolder(new UmletGithub()), "/convert/uxf/svg/");

    server.start();
    server.join();
  }
  @BeforeClass
  public static void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    container.addEndpoint(CaptureHeadersSocket.class);
    container.addEndpoint(EmptySocket.class);
    container.addEndpoint(NoExtensionsSocket.class);

    server.start();
    String host = connector.getHost();
    if (host == null) {
      host = "localhost";
    }
    int port = connector.getLocalPort();
    baseServerUri = new URI(String.format("ws://%s:%d/", host, port));
    LOG.debug("Server started on {}", baseServerUri);
  }
Ejemplo n.º 6
0
  private void init() {
    logger.info("Initializing Broker Http Metrics Reporter");

    InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port);

    server = new Server(inetSocketAddress);

    ServletContextHandler servletContextHandler = new ServletContextHandler();

    servletContextHandler.setContextPath("/");

    servletContextHandler.addEventListener(new MetricsServletContextListener());
    servletContextHandler.addEventListener(new JVMMetricsServletContextListener());
    servletContextHandler.addEventListener(new HealthCheckServletContextListener());

    servletContextHandler.addServlet(new ServletHolder(new HermesServlet()), "/hermes");
    servletContextHandler.addServlet(new ServletHolder(new MetricsServlet()), "/metrics/metrics");
    servletContextHandler.addServlet(
        new ServletHolder(new ThreadDumpServlet()), "/metrics/threads");
    servletContextHandler.addServlet(
        new ServletHolder(new HealthCheckServlet()), "/metrics/healthcheck");
    servletContextHandler.addServlet(new ServletHolder(new PingServlet()), "/metrics/ping");

    server.setHandler(servletContextHandler);
    logger.info("Finished initializing Broker Http Metrics Reporter");
  }
  public RestTransportServer(RestContact contact, final AppServerHandler appServerHandler) {
    this.contact = contact;

    server = new Server(contact.getPort());
    ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.setContextPath("/");

    // servletContextHandler.addServlet(new ServletHolder(new
    // RestTransportServlet(appServerHandler)), "/*");
    servletContextHandler.addServlet(new ServletHolder(new NotFoundServlet()), "/*");

    final Injector injector =
        Guice.createInjector(
            new ReefyServletModule(),
            new AbstractModule() {
              @Override
              protected void configure() {
                binder().requireExplicitBindings();
                bind(GuiceFilter.class);
                bind(new TypeLiteral<AppServerHandler<RestContact>>() {})
                    .toInstance(appServerHandler);
              }
            });

    final FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
    servletContextHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));

    server.setHandler(servletContextHandler);
  }
Ejemplo n.º 8
0
  public static void main(String[] args) throws Exception {
    Server server = new Server();

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(7080);
    server.setConnectors(new Connector[] {connector});

    ServletContextHandler webApiContext = new ServletContextHandler();
    webApiContext.setContextPath("/");

    webApiContext.addServlet(new ServletHolder(AppTokenServer.class), "/sts/*");
    webApiContext.addServlet(new ServletHolder(CallbackServer.class), "/callback/*");
    webApiContext.addServlet(new ServletHolder(PostObjectPolicy.class), "/get-post-policy/*");

    //    webApiContext.addServlet(new ServletHolder(STSToken.class), "/2/*");
    //    webApiContext.addServlet(new ServletHolder(CallbackServer.class), "/3/*");
    //    webApiContext.addServlet(new ServletHolder(DownloadApi.class), "/download/*");
    webApiContext.setSessionHandler(new SessionHandler());

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

    server.setHandler(handlers);
    server.start();
    server.join();
  }
  @Test
  public void testReplaceServletHandlerWithoutServlet() throws Exception {
    ServletContextHandler context = new ServletContextHandler();
    context.addServlet(TestServlet.class, "/test");
    context.setContextPath("/");
    _server.setHandler(context);
    _server.start();

    StringBuffer request = new StringBuffer();
    request.append("GET /test HTTP/1.0\n");
    request.append("Host: localhost\n");
    request.append("\n");

    String response = _connector.getResponses(request.toString());
    assertResponseContains("Test", response);

    context.stop();
    ServletHandler srvHnd = new ServletHandler();
    context.setServletHandler(srvHnd);
    context.start();

    context.addServlet(HelloServlet.class, "/hello");

    request = new StringBuffer();
    request.append("GET /hello HTTP/1.0\n");
    request.append("Host: localhost\n");
    request.append("\n");

    response = _connector.getResponses(request.toString());
    assertResponseContains("Hello World", response);
  }
Ejemplo n.º 10
0
  public static void main(String[] args) throws Exception {
    if (args.length < 1) {
      throw new RuntimeException("Expected >=1 command line arguments");
    }
    String sourceDir = args[0];
    logger.log(Level.INFO, "Source directory: " + sourceDir);

    int port = args.length > 1 ? Integer.parseInt(args[1]) : 8080;
    Server server = new Server(port);

    ServletContextHandler servletHandler =
        new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setContextPath("/");
    servletHandler.addServlet(ProxyingServlet.class, "/mirror");
    servletHandler.addServlet(AwtThumbnailServlet.class, "/thumb");
    servletHandler.addServlet(OAuthServlet.class, "/oauth");

    final ResourceHandler fileServlet = new ResourceHandler();
    fileServlet.setResourceBase(sourceDir);
    fileServlet.setDirectoriesListed(true);
    // Don't let the corp proxy cache content served out of the filesystem,
    // since we expect this may be used by a developer who's modifying it.
    fileServlet.setCacheControl("no-cache");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(
        new Handler[] {
          fileServlet, servletHandler, new DartHandler(sourceDir), new DefaultHandler()
        });
    server.setHandler(handlers);

    System.out.println("Sample dart apps served at:\n" + "http://localhost:" + port + "/samples/");
    server.start();
    server.join();
  }
Ejemplo n.º 11
0
  public static void main(String[] args) {
    GTFSDB.InitializeDB();
    Datasource ds = Datasource.getInstance();
    ds.getConnection();

    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.setResourceBase(BASE_RESOURCE);

    server.setHandler(context);

    context.addServlet(GetFeedJSON.class, "/getFeed");
    context.addServlet(DefaultServlet.class, "/");

    ServletHolder jerseyServlet =
        context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/api/*");
    jerseyServlet.setInitOrder(1);
    jerseyServlet.setInitParameter(
        "jersey.config.server.provider.classnames",
        "org.glassfish.jersey.moxy.json.MoxyJsonFeature");
    jerseyServlet.setInitParameter(
        "jersey.config.server.provider.packages", "edu.usf.cutr.gtfsrtvalidator.api.resource");

    try {
      server.start();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 12
0
  @Before
  public void init() throws Exception {
    _server = new Server();
    _connector = new LocalConnector(_server);
    ServletContextHandler context =
        new ServletContextHandler(
            ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    _server.addConnector(_connector);
    _server.setHandler(context);

    context.setContextPath("/");

    context.addServlet(DefaultServlet.class, "/");
    context.addServlet(FailServlet.class, "/fail/*");
    context.addServlet(ErrorServlet.class, "/error/*");

    ErrorPageErrorHandler error = new ErrorPageErrorHandler();
    context.setErrorHandler(error);
    error.addErrorPage(599, "/error/599");
    error.addErrorPage(IllegalStateException.class.getCanonicalName(), "/error/TestException");
    error.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/error/GlobalErrorPage");

    _server.start();
    ((StdErrLog) Log.getLogger(ServletHandler.class)).setHideStacks(true);
  }
Ejemplo n.º 13
0
  public void start(Injector injector) throws Exception {
    ResourceHandler resHandler = new ResourceHandler();
    resHandler.setDirectoriesListed(false);
    resHandler.setWelcomeFiles(new String[] {"index.html"});
    resHandler.setResourceBase(args.get("jetty.resourcebase", "./src/main/webapp"));

    server = new Server();
    // getSessionHandler and getSecurityHandler should always return null
    ServletContextHandler servHandler =
        new ServletContextHandler(
            ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    servHandler.setContextPath("/");

    servHandler.addServlet(new ServletHolder(new InvalidRequestServlet()), "/*");

    FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
    servHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));

    SelectChannelConnector connector0 = new SelectChannelConnector();
    int httpPort = args.getInt("jetty.port", 8989);
    String host = args.get("jetty.host", "");
    connector0.setPort(httpPort);
    if (!host.isEmpty()) connector0.setHost(host);

    server.addConnector(connector0);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resHandler, servHandler});
    server.setHandler(handlers);
    server.start();
    logger.info("Started server at HTTP " + host + ":" + httpPort);
  }
  @Before
  public void init() throws Exception {
    server = new Server();

    connector = new LocalConnector(server);
    connector
        .getConnectionFactory(HttpConfiguration.ConnectionFactory.class)
        .getHttpConfiguration()
        .setSendServerVersion(false);

    context = new ServletContextHandler();
    context.setContextPath("/context");
    context.setWelcomeFiles(new String[] {"index.html", "index.jsp", "index.htm"});

    server.setHandler(context);
    server.addConnector(connector);

    testdir.ensureEmpty();
    File resBase = testdir.getFile("docroot");
    FS.ensureDirExists(resBase);
    File data = new File(resBase, "data.txt");
    createFile(data, DATA);
    String resBasePath = resBase.getAbsolutePath();

    ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
    defholder.setInitParameter("acceptRanges", "true");
    defholder.setInitParameter("resourceBase", resBasePath);

    server.start();
  }
Ejemplo n.º 15
0
  @Before
  public void setup() throws Exception {
    try (ServerSocket serverSocket = new ServerSocket(0)) {
      googlePort = serverSocket.getLocalPort();
    }
    googleServer = new Server(googlePort);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    googleServer.setHandler(context);
    context.addServlet(new ServletHolder(userinfoServlet), "/oauth2/v2/userinfo");
    context.addServlet(new ServletHolder(tokenServlet), "/o/oauth2/token");
    googleServer.start();

    // Allow attributes to be set and got from a session.
    final Map<String, Object> attributes = Maps.newHashMap();
    Answer<Void> setAttributeAnswer =
        new Answer<Void>() {
          @Override
          public Void answer(InvocationOnMock invocation) throws Throwable {
            attributes.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
            return null;
          }
        };
    Answer<Object> getAttributeAnswer =
        new Answer<Object>() {
          @Override
          public Object answer(InvocationOnMock invocation) throws Throwable {
            return attributes.get((String) invocation.getArguments()[0]);
          }
        };
    when(session.getAttribute(anyString())).thenAnswer(getAttributeAnswer);
    when(session.getId()).thenReturn("sessionID");
    doAnswer(setAttributeAnswer).when(session).setAttribute(anyString(), anyObject());
  }
  public static void main(String[] args) {
    int port = 8889;

    JettyImageServerServlet service = new JettyImageServerServlet();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addServlet(new ServletHolder(service), "/*");
    Collection<String> sharedDisplayables = new ArrayList<String>();
    String base = "/Users/niko/TileSources/displayables/";
    String[] disps =
        new String[] {
          "tpg-plan-centre-9-decembre-12-4-1.disp",
          "tpg-plan-peripherique-9-decembre-12-2.disp",
          "tpg-plan-schematique-9-decembre-12-3.disp"
        };
    for (String d : disps) {
      sharedDisplayables.add(base + d);
    }
    service.setSharedDisplayables(sharedDisplayables);
    Server server = new Server(port);
    server.setHandler(context);
    try {
      server.start();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
Ejemplo n.º 17
0
  /**
   * Configure the web application(s).
   *
   * @param handlers
   * @throws Exception
   */
  protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception {
    /* *************
     * Manager API
     * ************* */
    ServletContextHandler apiManServer = new ServletContextHandler(ServletContextHandler.SESSIONS);
    apiManServer.setSecurityHandler(createSecurityHandler());
    apiManServer.setContextPath("/apiman");
    apiManServer.addEventListener(new Listener());
    apiManServer.addEventListener(new BeanManagerResourceBindingListener());
    apiManServer.addEventListener(new ResteasyBootstrap());
    apiManServer.addFilter(
        DatabaseSeedFilter.class, "/db-seeder", EnumSet.of(DispatcherType.REQUEST));
    //        apiManServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(ApimanCorsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(DisableCachingFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(AuthenticationFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(
        DefaultSecurityContextFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(
        TransactionWatchdogFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(RootResourceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    ServletHolder resteasyServlet = new ServletHolder(new HttpServletDispatcher());
    resteasyServlet.setInitParameter(
        "javax.ws.rs.Application", TestManagerApiApplication.class.getName());
    apiManServer.addServlet(resteasyServlet, "/*");

    apiManServer.setInitParameter(
        "resteasy.injector.factory", "org.jboss.resteasy.cdi.CdiInjectorFactory");
    apiManServer.setInitParameter("resteasy.scan", "true");
    apiManServer.setInitParameter("resteasy.servlet.mapping.prefix", "");

    // Add the web contexts to jetty
    handlers.addHandler(apiManServer);

    /* *************
     * Mock Gateway (to test publishing of Services from dt to rt)
     * ************* */
    ServletContextHandler mockGatewayServer =
        new ServletContextHandler(ServletContextHandler.SESSIONS);
    mockGatewayServer.setSecurityHandler(createSecurityHandler());
    mockGatewayServer.setContextPath("/mock-gateway");
    ServletHolder mockGatewayServlet = new ServletHolder(new MockGatewayServlet());
    mockGatewayServer.addServlet(mockGatewayServlet, "/*");

    // Add the web contexts to jetty
    handlers.addHandler(mockGatewayServer);
  }
Ejemplo n.º 18
0
 public static Server createTestServer() {
   ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
   handler.addServlet(new ServletHolder(new CamelHttpTransportServlet()), "/camel/*");
   handler.setContextPath("/");
   Server server = new Server(TestConfig.getPort());
   server.setHandler(handler);
   return server;
 }
Ejemplo n.º 19
0
 public static void server(int port, String mapping, String routes, Object api) throws Exception {
   ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
   handler.setContextPath("/");
   handler.setAttribute("api", api);
   ServletHolder holder = new ServletHolder(new Servlet());
   holder.setInitParameter("routes", routes);
   handler.addServlet(holder, mapping);
   server(port, handler);
 }
Ejemplo n.º 20
0
 public static void main(String[] args) throws Exception {
   Server server = new Server(Integer.valueOf(System.getenv("PORT")));
   ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
   context.setContextPath("/");
   server.setHandler(context);
   context.addServlet(new ServletHolder(new Homepage()), "/*");
   server.start();
   server.join();
 }
  /**
   * Initialize server handlers, rest resources.
   *
   * @throws Exception
   */
  protected void initServer() throws Exception {
    _server = new Server();
    initThreadPool();
    initConnectors();

    // AuthN servlet filters
    servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setContextPath("/");
    _server.setHandler(servletHandler);

    ((AbstractSessionManager) servletHandler.getSessionHandler().getSessionManager())
        .setUsingCookies(false);

    if (_disabler != null) {
      final FilterHolder securityFilterHolder =
          new FilterHolder(new DelegatingFilterProxy(_disablingFilter));
      servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
      _log.warn("security checks are disabled... skipped adding security filters");
    } else {
      final FilterHolder securityFilterHolder =
          new FilterHolder(new DelegatingFilterProxy(_secFilters));
      servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
    }

    // Add the REST resources
    if (_app != null) {
      ResourceConfig config = new DefaultResourceConfig();
      config.add(_app);
      Map<String, MediaType> type = config.getMediaTypeMappings();
      type.put("json", MediaType.APPLICATION_JSON_TYPE);
      type.put("xml", MediaType.APPLICATION_XML_TYPE);
      servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
      // AuthZ resource filters
      Map<String, Object> props = new HashMap<String, Object>();
      props.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, _resourceFilterFactory);

      // Adding the ContainerResponseFilter
      props.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, _responseFilter);
      config.setPropertiesAndFeatures(props);
    }
    if (_dbClient != null) {
      // in some cases, like syssvc, we don't want the service to be blocked by dbsvc startup.
      // Otherwise there could be a dependency loop between services.
      if (startDbClientInBackground) {
        _log.info("starting dbclient in background");
        new Thread() {
          public void run() {
            _dbClient.start();
          }
        }.start();
      } else {
        _log.info("starting dbclient");
        _dbClient.start();
      }
    }
  }
Ejemplo n.º 22
0
 private static ServletContextHandler getServletContextHandler(WebApplicationContext context)
     throws IOException {
   ServletContextHandler contextHandler = new ServletContextHandler();
   contextHandler.setErrorHandler(null);
   contextHandler.setContextPath(CONTEXT_PATH);
   contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
   contextHandler.addEventListener(new ContextLoaderListener(context));
   contextHandler.setResourceBase("webapp");
   return contextHandler;
 }
Ejemplo n.º 23
0
 /**
  * Starts a test jetty doc server at /docs. Blocks until the server is terminated.
  *
  * @param port the port to which the server will connect.
  * @throws Exception if the server couldn't be started.
  */
 public void startupServer(int port) throws Exception {
   jettyServer = new Server(port);
   ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
   context.setContextPath("/");
   jettyServer.setHandler(context);
   context.addServlet(new ServletHolder(this), SERVER_CONTEXT_LOC);
   jettyServer.start();
   jettyPort = jettyServer.getConnectors()[0].getLocalPort();
   jettyServer.join();
 }
Ejemplo n.º 24
0
  public void start(Filter filterToTest) throws Exception {
    server = new Server(8080);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(new ServletHolder(new TestServlet()), "/*");
    context.addFilter(new FilterHolder(filterToTest), "/*", EnumSet.of(DispatcherType.REQUEST));
    server.start();
  }
Ejemplo n.º 25
0
  public static void main(final String[] args) throws Exception {

    final Server server = new Server(8080);

    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(new ServletHolder(new CallmebackServlet()), "/callmeback");

    server.start();
    server.join();
  }
Ejemplo n.º 26
0
  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
    context.addServlet(new ServletHolder(new DumpServlet()), "/dump/*");

    server.start();
    server.join();
  }
Ejemplo n.º 27
0
  public static void main(String[] args) throws Exception {

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/*");
    Server jettyServer = new Server(8080);
    jettyServer.setHandler(context);
    ServletHolder jerseyServlet =
        context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
    jerseyServlet.setInitOrder(0);
    jerseyServlet.setInitParameter(
        "jersey.config.server.provider.classnames", FizzBuzzWs.class.getCanonicalName());
    jettyServer.start();
  }
 @BeforeClass
 public static void setUpClass() throws Exception {
   server = new Server(8082);
   ServletHolder servletHolder =
       new ServletHolder(org.glassfish.jersey.servlet.ServletContainer.class);
   servletHolder.setInitParameter("javax.ws.rs.Application", ApplicationConfig.class.getName());
   ServletContextHandler contextHandler =
       new ServletContextHandler(ServletContextHandler.SESSIONS);
   contextHandler.setContextPath("/");
   contextHandler.addServlet(servletHolder, "/api/*");
   server.setHandler(contextHandler);
   server.start();
 }
Ejemplo n.º 29
0
 public static void main(String[] args) throws Exception {
     String port = System.getenv("PORT");
     if(port==null)
         port ="8000";
     Server server = new Server(Integer.valueOf(port));
     ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
     context.setContextPath("/");
     server.setHandler(context);
     context.addServlet(new ServletHolder(new basicWait()),"/basic_wait");
     context.addServlet(new ServletHolder(new delayedWait()),"/delayed_wait");
     server.start();
     server.join();
 }
Ejemplo n.º 30
0
  /**
   * Main entry point to application. Sets up the resources and launches the Jetty server.
   *
   * @param args The command line arguments.
   * @throws Exception When there is an issue launching the application.
   */
  public static void main(String[] args) {
    // set up command line options
    Options options = new Options();
    options.addOption("p", "port", true, "Port to bind to [default: 8080]");

    // parse command line parameters
    CommandLine commandLine = null;
    try {
      commandLine = new PosixParser().parse(options, args);
    } catch (ParseException e) {
      LOG.error("Could not parse command line args: ", e);
      printUsageAndExit(options, -1);
    }

    int port = 8080;
    // user provided value precedes config value
    if (commandLine != null && commandLine.hasOption("port")) {
      String val = commandLine.getOptionValue("port");
      // get port to bind to
      port = Integer.parseInt(val);
      LOG.debug("Port set to: " + val);
    }

    LOG.info("DNS Web server setup.");
    // create server and configure basic settings
    Server server = new Server();
    server.setStopAtShutdown(true);
    // set up connector
    Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    // connector.setHost("127.0.0.1");
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new DnsServ()), "/*");
    // context.addServlet(new ServletHolder(new
    // HelloServlet("TYPE1 Request")), "/TYPE1/*");

    // start the server
    try {
      server.start();
      server.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }