Java Code Examples for org.mortbay.jetty.servlet.Context#addServlet()

The following examples show how to use org.mortbay.jetty.servlet.Context#addServlet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHTestCase.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
@TestJetty
public void testJetty() throws Exception {
  Context context = new Context();
  context.setContextPath("/");
  context.addServlet(MyServlet.class, "/bar");
  Server server = TestJettyHelper.getJettyServer();
  server.addHandler(context);
  server.start();
  URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  assertEquals(reader.readLine(), "foo");
  reader.close();
}
 
Example 2
Source File: TestStringsWithRestEasy.java    From curator with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void         setup() throws Exception
{
    RestEasyApplication.singletonsRef.set(new RestEasySingletons());

    ResteasyProviderFactory.setInstance(new ResteasyProviderFactory());

    HttpServletDispatcher   dispatcher = new HttpServletDispatcher();

    port = InstanceSpec.getRandomPort();
    server = new Server(port);
    Context root = new Context(server, "/", Context.SESSIONS);
    root.getInitParams().put("javax.ws.rs.Application", RestEasyApplication.class.getName());
    root.addServlet(new ServletHolder(dispatcher), "/*");
    root.addEventListener(new ResteasyBootstrap());
    server.start();
}
 
Example 3
Source File: TestHTestCase.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
@TestJetty
public void testJetty() throws Exception {
  Context context = new Context();
  context.setContextPath("/");
  context.addServlet(MyServlet.class, "/bar");
  Server server = TestJettyHelper.getJettyServer();
  server.addHandler(context);
  server.start();
  URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  assertEquals(reader.readLine(), "foo");
  reader.close();
}
 
Example 4
Source File: AuthenticatorTestCase.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected void startJetty() throws Exception {
  server = new Server(0);
  context = new Context();
  context.setContextPath("/foo");
  server.setHandler(context);
  context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(TestServlet.class), "/bar");
  host = "localhost";
  port = getLocalPort();
  server.getConnectors()[0].setHost(host);
  server.getConnectors()[0].setPort(port);
  server.start();
  System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
 
Example 5
Source File: TestWebDelegationToken.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalDelegationTokenSecretManager() throws Exception {
  DummyDelegationTokenSecretManager secretMgr
      = new DummyDelegationTokenSecretManager();
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(AFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(PingServlet.class), "/bar");
  try {
    secretMgr.startThreads();
    context.setAttribute(DelegationTokenAuthenticationFilter.
            DELEGATION_TOKEN_SECRET_MANAGER_ATTR, secretMgr);
    jetty.start();
    URL authURL = new URL(getJettyURL() + "/foo/bar?authenticated=foo");

    DelegationTokenAuthenticatedURL.Token token =
        new DelegationTokenAuthenticatedURL.Token();
    DelegationTokenAuthenticatedURL aUrl =
        new DelegationTokenAuthenticatedURL();

    aUrl.getDelegationToken(authURL, token, FOO_USER);
    Assert.assertNotNull(token.getDelegationToken());
    Assert.assertEquals(new Text("fooKind"),
        token.getDelegationToken().getKind());

  } finally {
    jetty.stop();
    secretMgr.stopThreads();
  }
}
 
Example 6
Source File: HttpServer2.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Add default apps.
 * @param appDir The application directory
 * @throws IOException
 */
protected void addDefaultApps(ContextHandlerCollection parent,
    final String appDir, Configuration conf) throws IOException {
  // set up the context for "/logs/" if "hadoop.log.dir" property is defined.
  String logDir = System.getProperty("hadoop.log.dir");
  if (logDir != null) {
    Context logContext = new Context(parent, "/logs");
    logContext.setResourceBase(logDir);
    logContext.addServlet(AdminAuthorizedServlet.class, "/*");
    if (conf.getBoolean(
        CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES,
        CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
      @SuppressWarnings("unchecked")
      Map<String, String> params = logContext.getInitParams();
      params.put(
          "org.mortbay.jetty.servlet.Default.aliases", "true");
    }
    logContext.setDisplayName("logs");
    setContextAttributes(logContext, conf);
    addNoCacheFilter(webAppContext);
    defaultContexts.put(logContext, true);
  }
  // set up the context for "/static/*"
  Context staticContext = new Context(parent, "/static");
  staticContext.setResourceBase(appDir + "/static");
  staticContext.addServlet(DefaultServlet.class, "/*");
  staticContext.setDisplayName("static");
  setContextAttributes(staticContext, conf);
  defaultContexts.put(staticContext, true);
}
 
Example 7
Source File: HttpServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Add default apps.
 * @param appDir The application directory
 * @throws IOException
 */
protected void addDefaultApps(ContextHandlerCollection parent,
    final String appDir, Configuration conf) throws IOException {
  // set up the context for "/logs/" if "hadoop.log.dir" property is defined. 
  String logDir = System.getProperty("hadoop.log.dir");
  if (logDir != null) {
    Context logContext = new Context(parent, "/logs");
    logContext.setResourceBase(logDir);
    logContext.addServlet(AdminAuthorizedServlet.class, "/*");
    if (conf.getBoolean(
        CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES,
        CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
      logContext.getInitParams().put(
          "org.mortbay.jetty.servlet.Default.aliases", "true");
    }
    logContext.setDisplayName("logs");
    setContextAttributes(logContext, conf);
    addNoCacheFilter(webAppContext);
    defaultContexts.put(logContext, true);
  }
  // set up the context for "/static/*"
  Context staticContext = new Context(parent, "/static");
  staticContext.setResourceBase(appDir + "/static");
  staticContext.addServlet(DefaultServlet.class, "/*");
  staticContext.setDisplayName("static");
  setContextAttributes(staticContext, conf);
  defaultContexts.put(staticContext, true);
}
 
Example 8
Source File: TestMapsWithJersey.java    From curator with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void         setup() throws Exception
{
    context = new MapDiscoveryContext(new MockServiceDiscovery<Map<String, String>>(), new RandomStrategy<Map<String, String>>(), 1000);
    serviceNamesMarshaller = new JsonServiceNamesMarshaller();
    serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<Map<String, String>>(context);
    serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<Map<String, String>>(context);

    Application                                     application = new DefaultResourceConfig()
    {
        @Override
        public Set<Class<?>> getClasses()
        {
            Set<Class<?>>       classes = Sets.newHashSet();
            classes.add(MapDiscoveryResource.class);
            return classes;
        }

        @Override
        public Set<Object> getSingletons()
        {
            Set<Object>     singletons = Sets.newHashSet();
            singletons.add(context);
            singletons.add(serviceNamesMarshaller);
            singletons.add(serviceInstanceMarshaller);
            singletons.add(serviceInstancesMarshaller);
            return singletons;
        }
    };
    ServletContainer        container = new ServletContainer(application);

    port = InstanceSpec.getRandomPort();
    server = new Server(port);
    Context root = new Context(server, "/", Context.SESSIONS);
    root.addServlet(new ServletHolder(container), "/*");
    server.start();
}
 
Example 9
Source File: TestStringsWithJersey.java    From curator with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void         setup() throws Exception
{
    context = new StringDiscoveryContext(new MockServiceDiscovery<String>(), new RandomStrategy<String>(), 1000);
    serviceNamesMarshaller = new JsonServiceNamesMarshaller();
    serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<String>(context);
    serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<String>(context);

    Application                                     application = new DefaultResourceConfig()
    {
        @Override
        public Set<Class<?>> getClasses()
        {
            Set<Class<?>>       classes = Sets.newHashSet();
            classes.add(StringDiscoveryResource.class);
            return classes;
        }

        @Override
        public Set<Object> getSingletons()
        {
            Set<Object>     singletons = Sets.newHashSet();
            singletons.add(context);
            singletons.add(serviceNamesMarshaller);
            singletons.add(serviceInstanceMarshaller);
            singletons.add(serviceInstancesMarshaller);
            return singletons;
        }
    };
    ServletContainer        container = new ServletContainer(application);

    port = InstanceSpec.getRandomPort();
    server = new Server(port);
    Context root = new Context(server, "/", Context.SESSIONS);
    root.addServlet(new ServletHolder(container), "/*");
    server.start();
}
 
Example 10
Source File: AuthenticatorTestCase.java    From registry with Apache License 2.0 5 votes vote down vote up
protected void startJetty() throws Exception {
    server = new Server(0);
    context = new Context();
    context.setContextPath("/foo");
    server.setHandler(context);
    context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
    context.addServlet(new ServletHolder(TestServlet.class), "/bar");
    host = "localhost";
    port = getLocalPort();
    server.getConnectors()[0].setHost(host);
    server.getConnectors()[0].setPort(port);
    server.start();
    System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
 
Example 11
Source File: Main.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
	Server server = new Server(PORT);
	
	// Static file handler
	Context fileContext = new Context(server, "/mxgraph", Context.SESSIONS);
	ResourceHandler fileHandler = new ResourceHandler();
	fileHandler.setResourceBase(".");
	fileContext.setHandler(fileHandler);

	// Servlets
	Context context = new Context(server, "/", Context.SESSIONS);
	context.addServlet(new ServletHolder(new Roundtrip()), "/Roundtrip");
	context.addServlet(new ServletHolder(new ServerView()), "/ServerView");
	context.addServlet(new ServletHolder(new ExportServlet()), "/Export");
	context.addServlet(new ServletHolder(new EchoServlet()), "/Echo");
	context.addServlet(new ServletHolder(new Deploy()), "/Deploy");
	context.addServlet(new ServletHolder(new Link()), "/Link");
	context.addServlet(new ServletHolder(new EmbedImage()), "/EmbedImage");
	context.addServlet(new ServletHolder(new Backend()), "/Backend");

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

	System.out.println("Go to http://localhost:" + PORT + "/");
	
	server.start();
	server.join();
}
 
Example 12
Source File: TestWebDelegationToken.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalDelegationTokenSecretManager() throws Exception {
  DummyDelegationTokenSecretManager secretMgr
      = new DummyDelegationTokenSecretManager();
  final Server jetty = createJettyServer();
  Context context = new Context();
  context.setContextPath("/foo");
  jetty.setHandler(context);
  context.addFilter(new FilterHolder(AFilter.class), "/*", 0);
  context.addServlet(new ServletHolder(PingServlet.class), "/bar");
  try {
    secretMgr.startThreads();
    context.setAttribute(DelegationTokenAuthenticationFilter.
            DELEGATION_TOKEN_SECRET_MANAGER_ATTR, secretMgr);
    jetty.start();
    URL authURL = new URL(getJettyURL() + "/foo/bar?authenticated=foo");

    DelegationTokenAuthenticatedURL.Token token =
        new DelegationTokenAuthenticatedURL.Token();
    DelegationTokenAuthenticatedURL aUrl =
        new DelegationTokenAuthenticatedURL();

    aUrl.getDelegationToken(authURL, token, FOO_USER);
    Assert.assertNotNull(token.getDelegationToken());
    Assert.assertEquals(new Text("fooKind"),
        token.getDelegationToken().getKind());

  } finally {
    jetty.stop();
    secretMgr.stopThreads();
  }
}
 
Example 13
Source File: HttpServer.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Add default apps.
 * @param appDir The application directory
 * @throws IOException
 */
protected void addDefaultApps(ContextHandlerCollection parent,
    final String appDir, Configuration conf) throws IOException {
  // set up the context for "/logs/" if "hadoop.log.dir" property is defined. 
  String logDir = System.getProperty("hadoop.log.dir");
  if (logDir != null) {
    Context logContext = new Context(parent, "/logs");
    logContext.setResourceBase(logDir);
    logContext.addServlet(AdminAuthorizedServlet.class, "/*");
    if (conf.getBoolean(
        CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES,
        CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
      logContext.getInitParams().put(
          "org.mortbay.jetty.servlet.Default.aliases", "true");
    }
    logContext.setDisplayName("logs");
    setContextAttributes(logContext, conf);
    addNoCacheFilter(webAppContext);
    defaultContexts.put(logContext, true);
  }
  // set up the context for "/static/*"
  Context staticContext = new Context(parent, "/static");
  staticContext.setResourceBase(appDir + "/static");
  staticContext.addServlet(DefaultServlet.class, "/*");
  staticContext.setDisplayName("static");
  setContextAttributes(staticContext, conf);
  defaultContexts.put(staticContext, true);
}
 
Example 14
Source File: ConsumerAndProviderTest.java    From openid4java with Apache License 2.0 5 votes vote down vote up
public ConsumerAndProviderTest(final String testName) throws Exception
{
    super(testName);
    int servletPort = Integer.parseInt(System.getProperty("SERVLET_PORT", "8989"));
    _server = new Server(servletPort);

    Context context = new Context(_server, "/", Context.SESSIONS);
    _baseUrl = "http://localhost:" + servletPort; // +
    // context.getContextPath();

    SampleConsumer consumer = new SampleConsumer(_baseUrl + "/loginCallback");
    context.addServlet(new ServletHolder(new LoginServlet(consumer)), "/login");
    context.addServlet(new ServletHolder(new LoginCallbackServlet(consumer)), "/loginCallback");

    context.addServlet(new ServletHolder(new UserInfoServlet()), "/user");

    SampleServer server = new SampleServer(_baseUrl + "/provider")
    {
        protected List userInteraction(ParameterList request) throws ServerException
        {
            List back = new ArrayList();
            back.add("userSelectedClaimedId"); // userSelectedClaimedId
            back.add(Boolean.TRUE); // authenticatedAndApproved
            back.add("[email protected]"); // email
            return back;
        }
    };
    context.addServlet(new ServletHolder(new ProviderServlet(server)), "/provider");
}
 
Example 15
Source File: Main.java    From stanbol-freeling with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args);
    args = line.getArgs();
    if(line.hasOption('h')){
        printHelp();
        System.exit(0);
    }
    //Parse the Freeling parameter and init the Freeling instance
    String sharedFolder = System.getenv(ENV_FREELING_SHARED_FOLDER);
    sharedFolder = System.getProperty(PROPERTY_FREELING_SHARED_FOLDER, sharedFolder);
    sharedFolder = line.getOptionValue('s', sharedFolder);
    if(sharedFolder == null){
        System.err.println("The Freeling shared Folder MUST BE set! \n");
        printHelp();
        System.exit(0);
    }
    File shared = new File(sharedFolder);
    if(!shared.isDirectory()){
        System.err.println("The configured Freeling shared folder '"
            + sharedFolder + "' is not a directory!\n");
        System.exit(1);
    }
    String configFolder = FilenameUtils.concat(sharedFolder, "config");
    configFolder = System.getProperty(PROPERTY_FREELING_CONFIG_FOLDER, configFolder);
    configFolder = line.getOptionValue('c', configFolder);
    File config = new File(configFolder);
    if(!config.isDirectory()){
        System.err.println("The configured Freeling config folder '"
            + configFolder + "' is not a directory!\n");
        System.exit(1);
    }
    String nativeLib = FilenameUtils.concat(sharedFolder, Freeling.DEFAULT_FREELING_LIB_PATH);
    if(new File(Freeling.DEFAULT_FREELING_LIB_PATH).isFile()){
        nativeLib = Freeling.DEFAULT_FREELING_LIB_PATH;
    }
    nativeLib = line.getOptionValue('l', nativeLib);
    if(!new File(nativeLib).isFile()){
        System.err.println("The configured Freeling native lib '"
                + nativeLib + "' is not a file!\n");
        System.exit(1);
    }
    Freeling freeling = new Freeling(
        config.getPath(), Freeling.DEFAULT_CONFIGURATION_FILENAME_SUFFIX, 
        shared.getPath(), nativeLib, Freeling.DEFAULT_FREELING_LOCALE, 
        getInt(line, 'i', DEFAULT_INIT_THREADS), 
        getInt(line, 'm', DEFAULT_MAX_POOL_SIZE), 
        getInt(line, 'q', DEFAULT_MIN_QUEUE_SIZE));
    
    
    //init the Jetty Server
    Server server = new Server();
    Connector con = new SelectChannelConnector();
    //we need the port
    con.setPort(getInt(line,'p',DEFAULT_PORT));
    server.addConnector(con);

    //init the Servlet and the ServletContext
    Context context = new Context(server, "/", Context.SESSIONS);
    ServletHolder holder = new ServletHolder(RestServlet.class);
    holder.setInitParameter("javax.ws.rs.Application", FreelingApplication.class.getName());
    context.addServlet(holder, "/*");
    
    //now initialise the servlet context
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_CONTENT_ITEM_FACTORY, 
        lookupService(ContentItemFactory.class));
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_FREELING, freeling);
    context.setAttribute(Constants.SERVLET_ATTRIBUTE_MAX_RESOURCE_WAIT_TIEM, 
        getLong(line,'w',Constants.DEFAULT_RESOURCE_WAIT_TIME));
    //Freeling
    
    server.start();
    try {
        server.join();
    }catch (InterruptedException e) {
    }
    System.err.println("Shutting down Freeling");
    freeling.close();
}
 
Example 16
Source File: WebServer.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public WebServer(int httpport, DataStore data, MetadataStore metadata) throws IOException, URISyntaxException {
    super(httpport);

    extractWebUI();

    this.data = data;
    this.metadata = metadata;

    // Initialize Velocity template engine
    try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
        Velocity.setProperty("runtime.log.logsystem.log4j.logger", "edu.berkeley.xtrace.server.XTraceServer");
        Velocity.setProperty("file.resource.loader.path", webui + "/templates");
        Velocity.setProperty("file.resource.loader.cache", "true");
        Velocity.init();
    } catch (Exception e) {
        LOG.warn("Failed to initialize Velocity", e);
    }

    // Create Jetty server
    Context context = new Context(this, "/");

    // Create a CGI servlet for scripts in webui/cgi-bin
    ServletHolder cgiHolder = new ServletHolder(new CGI());
    cgiHolder.setInitParameter("cgibinResourceBase", webui + "/cgi-bin");

    // Pass any special PATH setting on to the execution environment
    if (System.getenv("PATH") != null)
        cgiHolder.setInitParameter("Path", System.getenv("PATH"));

    context.addServlet(cgiHolder, "*.cgi");
    context.addServlet(cgiHolder, "*.pl");
    context.addServlet(cgiHolder, "*.py");
    context.addServlet(cgiHolder, "*.rb");
    context.addServlet(cgiHolder, "*.tcl");
    context.addServlet(new ServletHolder(new GetReportsServlet()), "/reports/*");
    context.addServlet(new ServletHolder(new TagServlet()), "/tag/*");
    context.addServlet(new ServletHolder(new TitleServlet()), "/title/*");
    context.addServlet(new ServletHolder(new TitleLikeServlet()), "/titleLike/*");

    // JSON APIs for interactive visualization
    context.addServlet(new ServletHolder(new GetJSONReportsServlet()), "/interactive/reports/*");
    context.addServlet(new ServletHolder(new GetOverlappingTasksServlet()), "/interactive/overlapping/*");
    context.addServlet(new ServletHolder(new GetTagsForTaskServlet()), "/interactive/tags/*");
    context.addServlet(new ServletHolder(new GetTasksForTags()), "/interactive/taggedwith/*");

    context.setResourceBase(webui + "/html");
    context.addServlet(new ServletHolder(new IndexServlet()), "/");
}
 
Example 17
Source File: HbaseRestLocalCluster.java    From hadoop-mini-clusters with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws Exception {
    VersionInfo.logVersion();
    Configuration conf = builder.getHbaseConfiguration();

    conf.set("hbase.rest.port", hbaseRestPort.toString());
    conf.set("hbase.rest.readonly", (hbaseRestReadOnly == null) ? "true" : hbaseRestReadOnly.toString());
    conf.set("hbase.rest.info.port", (hbaseRestInfoPort == null) ? "8085" : hbaseRestInfoPort.toString());
    String hbaseRestHost = (this.hbaseRestHost == null) ? "0.0.0.0" : this.hbaseRestHost;

    Integer hbaseRestThreadMax = (this.hbaseRestThreadMax == null) ? 100 : this.hbaseRestThreadMax;
    Integer hbaseRestThreadMin = (this.hbaseRestThreadMin == null) ? 2 : this.hbaseRestThreadMin;

    UserProvider userProvider = UserProvider.instantiate(conf);
    Pair<FilterHolder, Class<? extends ServletContainer>> pair = loginServerPrincipal(userProvider, conf);
    FilterHolder authFilter = pair.getFirst();
    Class<? extends ServletContainer> containerClass = pair.getSecond();
    RESTServlet.getInstance(conf, userProvider);

    // set up the Jersey servlet container for Jetty
    ServletHolder sh = new ServletHolder(containerClass);
    sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName());
    sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty");
    ServletHolder shPojoMap = new ServletHolder(containerClass);
    Map<String, String> shInitMap = sh.getInitParameters();
    for (Map.Entry<String, String> e : shInitMap.entrySet()) {
        shPojoMap.setInitParameter(e.getKey(), e.getValue());
    }
    shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");

    // set up Jetty and run the embedded server

    server = new Server();

    Connector connector = new SelectChannelConnector();
    if (conf.getBoolean(RESTServer.REST_SSL_ENABLED, false)) {
        SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
        String keystore = conf.get(RESTServer.REST_SSL_KEYSTORE_STORE);
        String password = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_PASSWORD, null);
        String keyPassword = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_KEYPASSWORD, password);
        sslConnector.setKeystore(keystore);
        sslConnector.setPassword(password);
        sslConnector.setKeyPassword(keyPassword);
        connector = sslConnector;
    }
    connector.setPort(hbaseRestPort);
    connector.setHost(hbaseRestHost);
    connector.setHeaderBufferSize(8192);


    server.addConnector(connector);

    QueuedThreadPool threadPool = new QueuedThreadPool(hbaseRestThreadMax);
    threadPool.setMinThreads(hbaseRestThreadMin);
    server.setThreadPool(threadPool);

    server.setSendServerVersion(false);
    server.setSendDateHeader(false);
    server.setStopAtShutdown(true);
    // set up context
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(shPojoMap, "/status/cluster");
    context.addServlet(sh, "/*");
    if (authFilter != null) {
        context.addFilter(authFilter, "/*", 1);
    }

    HttpServerUtil.constrainHttpMethods(context);

    // Put up info server.
    int port = (hbaseRestInfoPort == null) ? 8085 : hbaseRestInfoPort;
    if (port >= 0) {
        conf.setLong("startcode", System.currentTimeMillis());
        String a = hbaseRestHost;
        infoServer = new InfoServer("rest", a, port, false, conf);
        infoServer.setAttribute("hbase.conf", conf);
        infoServer.start();
    }
    // start server
    server.start();
}
 
Example 18
Source File: SlackNotificationTestProxyServer.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
public SlackNotificationTestProxyServer(String host, Integer port) {
	server = new Server(port);
	Context root = new Context(server,"/",Context.SESSIONS);
	root.addServlet(new ServletHolder(new ProxyServerServlet()), "/*");
}
 
Example 19
Source File: SlackNotificationTestProxyServer.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
public SlackNotificationTestProxyServer(String host, Integer port, String proxyUsername, String proxyPassword) {
server = new Server(port);
Context root = new Context(server,"/",Context.SESSIONS);
root.addServlet(new ServletHolder(new ProxyServerServlet(proxyUsername, proxyPassword)), "/*");	}
 
Example 20
Source File: YadisResolverTest.java    From openid4java with Apache License 2.0 3 votes vote down vote up
public void setUp() throws Exception
{

    _resolver = new YadisResolver(new HttpFetcherFactory());

    _server = new Server(_servletPort);

    Context context = new Context(_server, "/", Context.SESSIONS);
    context.addServlet(new ServletHolder(new YadisTestServlet()), "/*");

    _server.start();

}