Search in sources :

Example 66 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project ignite by apache.

the class WebSessionSelfTest method startServerWithLoginService.

/**
     * Starts server with Login Service and create a realm file.
     *
     * @param port Port number.
     * @param cfg Configuration.
     * @param igniteInstanceName Ignite instance name.
     * @param servlet Servlet.
     * @return Server.
     * @throws Exception In case of error.
     */
private Server startServerWithLoginService(int port, @Nullable String cfg, @Nullable String igniteInstanceName, HttpServlet servlet) throws Exception {
    Server srv = new Server(port);
    WebAppContext ctx = getWebContext(cfg, igniteInstanceName, keepBinary(), servlet);
    HashLoginService hashLoginService = new HashLoginService();
    hashLoginService.setName("Test Realm");
    createRealm();
    hashLoginService.setConfig("/tmp/realm.properties");
    ctx.getSecurityHandler().setLoginService(hashLoginService);
    srv.setHandler(ctx);
    srv.start();
    return srv;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HashLoginService(org.eclipse.jetty.security.HashLoginService) Server(org.eclipse.jetty.server.Server)

Example 67 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project ignite by apache.

the class WebSessionSelfTest method getWebContext.

/**
     * @param cfg Configuration.
     * @param igniteInstanceName Ignite instance name.
     * @param servlet Servlet.
     * @return Servlet container web context for this test.
     */
protected WebAppContext getWebContext(@Nullable String cfg, @Nullable String igniteInstanceName, boolean keepBinaryFlag, HttpServlet servlet) {
    final String path = keepBinaryFlag ? "modules/core/src/test/webapp" : "modules/web/src/test/webapp2";
    WebAppContext ctx = new WebAppContext(U.resolveIgnitePath(path).getAbsolutePath(), "/ignitetest");
    ctx.setInitParameter("IgniteConfigurationFilePath", cfg);
    ctx.setInitParameter("IgniteWebSessionsGridName", igniteInstanceName);
    ctx.setInitParameter("IgniteWebSessionsCacheName", getCacheName());
    ctx.setInitParameter("IgniteWebSessionsMaximumRetriesOnFail", "100");
    ctx.setInitParameter("IgniteWebSessionsKeepBinary", Boolean.toString(keepBinaryFlag));
    ctx.addServlet(new ServletHolder(servlet), "/*");
    return ctx;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 68 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project jena by apache.

the class JettyFuseki method buildServerWebapp.

private void buildServerWebapp(String contextPath, String jettyConfig) {
    if (jettyConfig != null)
        // --jetty-config=jetty-fuseki.xml
        // for detailed configuration of the server using Jetty features.
        configServer(jettyConfig);
    else
        defaultServerConfig(serverConfig.port, serverConfig.loopback);
    WebAppContext webapp = createWebApp(contextPath);
    if (false) /*enable symbolic links */
    {
        // See http://www.eclipse.org/jetty/documentation/current/serving-aliased-files.html
        // Record what would be needed:
        // 1 - Allow all symbolic links without checking
        webapp.addAliasCheck(new ContextHandler.ApproveAliases());
        // 2 - Check links are to valid resources. But default for Unix?
        webapp.addAliasCheck(new AllowSymLinkAliasChecker());
    }
    servletContext = webapp.getServletContext();
    server.setHandler(webapp);
    // Replaced by Shiro.
    if (jettyConfig == null && serverConfig.authConfigFile != null)
        security(webapp, serverConfig.authConfigFile);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker)

Example 69 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project lucene-solr by apache.

the class JettyWebappTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    System.setProperty("solr.solr.home", SolrJettyTestBase.legacyExampleCollection1SolrHome());
    System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
    System.setProperty("solr.tests.doContainerStreamCloseAssert", "false");
    File dataDir = createTempDir().toFile();
    dataDir.mkdirs();
    System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
    String path = ExternalPaths.WEBAPP_HOME;
    server = new Server(port);
    // insecure: only use for tests!!!!
    server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
    new WebAppContext(server, path, context);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
    connector.setIdleTimeout(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(0);
    server.setConnectors(new Connector[] { connector });
    server.setStopAtShutdown(true);
    server.start();
    port = connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) Random(java.util.Random) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) File(java.io.File) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager)

Example 70 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project hbase by apache.

the class HMaster method putUpJettyServer.

// return the actual infoPort, -1 means disable info server.
private int putUpJettyServer() throws IOException {
    if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
        return -1;
    }
    final int infoPort = conf.getInt("hbase.master.info.port.orig", HConstants.DEFAULT_MASTER_INFOPORT);
    // -1 is for disabling info server, so no redirecting
    if (infoPort < 0 || infoServer == null) {
        return -1;
    }
    if (infoPort == infoServer.getPort()) {
        return infoPort;
    }
    final String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
    if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
        String msg = "Failed to start redirecting jetty server. Address " + addr + " does not belong to this host. Correct configuration parameter: " + "hbase.master.info.bindAddress";
        LOG.error(msg);
        throw new IOException(msg);
    }
    // TODO I'm pretty sure we could just add another binding to the InfoServer run by
    // the RegionServer and have it run the RedirectServlet instead of standing up
    // a second entire stack here.
    masterJettyServer = new Server();
    final ServerConnector connector = new ServerConnector(masterJettyServer);
    connector.setHost(addr);
    connector.setPort(infoPort);
    masterJettyServer.addConnector(connector);
    masterJettyServer.setStopAtShutdown(true);
    final String redirectHostname = shouldUseThisHostnameInstead() ? useThisHostnameInstead : null;
    final RedirectServlet redirect = new RedirectServlet(infoServer, redirectHostname);
    final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS);
    context.addServlet(new ServletHolder(redirect), "/*");
    context.setServer(masterJettyServer);
    try {
        masterJettyServer.start();
    } catch (Exception e) {
        throw new IOException("Failed to start redirecting jetty server", e);
    }
    return connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) InfoServer(org.apache.hadoop.hbase.http.InfoServer) RpcServer(org.apache.hadoop.hbase.ipc.RpcServer) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) BypassCoprocessorException(org.apache.hadoop.hbase.coprocessor.BypassCoprocessorException) CoordinatedStateException(org.apache.hadoop.hbase.CoordinatedStateException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) ServletException(javax.servlet.ServletException) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) KeeperException(org.apache.zookeeper.KeeperException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)142 Server (org.eclipse.jetty.server.Server)58 File (java.io.File)37 Test (org.junit.Test)29 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)18 URL (java.net.URL)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 URI (java.net.URI)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)9 FileWriter (java.io.FileWriter)7 Configuration (org.apache.hadoop.conf.Configuration)7 HashLoginService (org.eclipse.jetty.security.HashLoginService)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)7 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)7 BeforeClass (org.junit.BeforeClass)7 OutputStream (java.io.OutputStream)6 InitialContext (javax.naming.InitialContext)6