Java Code Examples for org.eclipse.jetty.webapp.WebAppContext

The following examples show how to use org.eclipse.jetty.webapp.WebAppContext. These examples are extracted from open source projects. 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 Project: nifi-registry   Source File: JettyServer.java    License: Apache License 2.0 6 votes vote down vote up
public void start() {
    try {
        // start the server
        server.start();

        // ensure everything started successfully
        for (Handler handler : server.getChildHandlers()) {
            // see if the handler is a web app
            if (handler instanceof WebAppContext) {
                WebAppContext context = (WebAppContext) handler;

                // see if this webapp had any exceptions that would
                // cause it to be unavailable
                if (context.getUnavailableException() != null) {
                    startUpFailure(context.getUnavailableException());
                }
            }
        }

        dumpUrls();
    } catch (final Throwable t) {
        startUpFailure(t);
    }
}
 
Example 2
public synchronized void updateHandler(WebAppContext context) throws Exception {
    Handler[] hl0 = getHandlers();
    List<Handler> hl = hl0!=null ? new ArrayList<Handler>(Arrays.asList(hl0)) : new ArrayList<Handler>();
    // remove any previous version
    removeContextFromList(hl, context.getContextPath());
    // have to add before the root war (remove root war then add back)
    Handler oldRoot = removeContextFromList(hl, "/");
    // now add and add back any root
    hl.add(context);
    if (oldRoot!=null) hl.add(oldRoot);
    setHandlers(hl.toArray(new Handler[0]));
    
    // and if we are already running, start the new context
    if (isRunning()) {
        context.start();
    }
}
 
Example 3
Source Project: zstack   Source File: WebBeanConstructor.java    License: Apache License 2.0 6 votes vote down vote up
private void prepareJetty() throws IOException {
    File dir = new File(BASE_DIR);
    FileUtils.deleteDirectory(dir);
    FileUtils.forceMkdir(dir);

    generateWarFile();

    jetty = new Server();
    ServerConnector http = new ServerConnector(jetty);
    http.setHost("0.0.0.0");
    http.setPort(port);
    http.setDefaultProtocol("HTTP/1.1");
    jetty.addConnector(http);
    final WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(new File(BASE_DIR, APP_NAME + ".war").getAbsolutePath());
    jetty.setHandler(webapp);
}
 
Example 4
Source Project: java-specialagent   Source File: Spring3WebMvcTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  server = new Server(0);

  final WebAppContext webAppContext = new WebAppContext();
  webAppContext.setServer(server);
  webAppContext.setContextPath("/");
  webAppContext.setWar("src/test/webapp");

  server.setHandler(webAppContext);
  server.start();

  // jetty starts on random port
  final int port = ((ServerConnector)server.getConnectors()[0]).getLocalPort();
  url = "http://localhost:" + port;
}
 
Example 5
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
 
Example 6
Source Project: nano-framework   Source File: JettyCustomServer.java    License: Apache License 2.0 6 votes vote down vote up
private void applyHandle(final String contextPath, final String warPath) {
    final ContextHandlerCollection handler = new ContextHandlerCollection();
    final WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    webapp.setDefaultsDescriptor(WEB_DEFAULT);
    if (StringUtils.isEmpty(warPath)) {
        webapp.setResourceBase(DEFAULT_RESOURCE_BASE);
        webapp.setDescriptor(DEFAULT_WEB_XML_PATH);
    } else {
        webapp.setWar(warPath);
    }
    
    applySessionHandler(webapp);
    
    handler.addHandler(webapp);
    super.setHandler(handler);
}
 
Example 7
Source Project: FXDesktopSearch   Source File: FrontendEmbeddedWebServer.java    License: Apache License 2.0 6 votes vote down vote up
public FrontendEmbeddedWebServer(
        final Stage aStage, final Backend aBackend, final PreviewProcessor aPreviewProcessor) {
    jetty = new Server(PORT_NUMMER);

    final var theWebApp = new WebAppContext();
    theWebApp.setContextPath("/");
    theWebApp.setBaseResource(Resource.newClassPathResource("/webapp"));
    theWebApp.setDescriptor("WEB-INF/web.xml");
    theWebApp.setClassLoader(getClass().getClassLoader());
    theWebApp.addServlet(new ServletHolder(new SearchServlet(aBackend, "http://127.0.0.1:" + PORT_NUMMER)), SearchServlet.URL + "/*");
    theWebApp.addServlet(new ServletHolder(new BringToFrontServlet(aStage)), BringToFrontServlet.URL);
    theWebApp.addServlet(new ServletHolder(new SuggestionServlet(aBackend)), SuggestionServlet.URL);
    theWebApp.addServlet(new ServletHolder(new ThumbnailServlet(aBackend, aPreviewProcessor)), ThumbnailServlet.URL + "/*");

    jetty.setHandler(theWebApp);
}
 
Example 8
Source Project: javasimon   Source File: Start.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) {
	Server server = new Server(8080);

	WebAppContext bb = new WebAppContext();
	bb.setServer(server);
	bb.setContextPath("/");
	bb.setWar("src/main/webapp");

	server.setHandler(bb);

	try {
		System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
		server.start();
		//noinspection ResultOfMethodCallIgnored
		System.in.read();
		System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
		server.stop();
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
Example 9
Source Project: ignite   Source File: WebSessionSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source Project: junit-servers   Source File: EmbeddedJettyTest.java    License: MIT License 6 votes vote down vote up
@Test
void it_should_add_parent_classloader(@TempDir Path tmp) throws Exception {
	final File tmpFile = Files.createTempFile(tmp, null, null).toFile();
	final File dir = tmpFile.getParentFile();
	final URL url = dir.toURI().toURL();
	final String name = tmpFile.getName();

	try (URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url })) {
		assertThat(urlClassLoader.getResource(name)).isNotNull();

		jetty = new EmbeddedJetty(EmbeddedJettyConfiguration.builder()
			.withWebapp(dir)
			.withParentClasspath(url)
			.build());

		jetty.start();

		WebAppContext ctx = (WebAppContext) jetty.getDelegate().getHandler();
		ClassLoader cl = ctx.getClassLoader();

		assertThat(cl).isNotNull();
		assertThat(cl.getResource("custom-web.xml")).isNotNull();
		assertThat(cl.getResource(name)).isNotNull();
	}
}
 
Example 11
Source Project: gocd   Source File: WebappSessionConfigIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetSessionTrackingModeToCookieOnly() throws Exception {
    Server server = new Server(1234);
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setWar(webapp.getAbsolutePath());
    webAppContext.setContextPath("/");
    server.setHandler(webAppContext);
    try {
        server.start();
        Set<SessionTrackingMode> effectiveSessionTrackingModes = ((WebAppContext) server.getHandlers()[0]).getServletContext().getEffectiveSessionTrackingModes();
        assertThat(effectiveSessionTrackingModes.size(), is(1));
        assertThat(effectiveSessionTrackingModes.contains(SessionTrackingMode.COOKIE), is(true));
    } finally {
        server.stop();
    }
}
 
Example 12
Source Project: Openfire   Source File: HttpBindManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Jetty context handler that can be used to expose static files.
 *
 * Note that an invocation of this method will not register the handler (and thus make the related functionality
 * available to the end user). Instead, the created handler is returned by this method, and will need to be
 * registered with the embedded Jetty webserver by the caller.
 *
 * @return A Jetty context handler, or null when the static content could not be accessed.
 */
protected Handler createStaticContentHandler()
{
    final File spankDirectory = new File( JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank" );
    if ( spankDirectory.exists() )
    {
        if ( spankDirectory.canRead() )
        {
            final WebAppContext context = new WebAppContext( null, spankDirectory.getPath(), "/" );
            context.setWelcomeFiles( new String[] { "index.html" } );

            return context;
        }
        else
        {
            Log.warn( "Openfire cannot read the directory: " + spankDirectory );
        }
    }
    return null;
}
 
Example 13
Source Project: Explorer   Source File: ExplorerServer.java    License: Apache License 2.0 6 votes vote down vote up
private static WebAppContext setupWebAppContext(ExplorerConfiguration conf) {
    WebAppContext webApp = new WebAppContext();
    File webapp = new File(conf.getString(ExplorerConfiguration.ConfVars.EXPLORER_WAR));
    if (webapp.isDirectory()) { // Development mode, read from FS
        webApp.setDescriptor(webapp+"/WEB-INF/web.xml");
        webApp.setResourceBase(webapp.getPath());
        webApp.setContextPath("/");
        webApp.setParentLoaderPriority(true);
    } else { //use packaged WAR
        webApp.setWar(webapp.getAbsolutePath());
    }

    ServletHolder servletHolder = new ServletHolder(new DefaultServlet());
    servletHolder.setInitParameter("cacheControl","private, max-age=0, must-revalidate");
    webApp.addServlet(servletHolder, "/*");
    return webApp;
}
 
Example 14
Source Project: cxf   Source File: ResolverTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void startServer() throws Throwable {
    Server server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));

    WebAppContext webappcontext = new WebAppContext();
    webappcontext.setContextPath("/resolver");
    webappcontext.setBaseResource(Resource.newClassPathResource("/resolver"));

    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
    server.setHandler(handlers);
    server.start();
    Throwable e = webappcontext.getUnavailableException();
    if (e != null) {
        throw e;
    }
    server.stop();
}
 
Example 15
Source Project: mysql_perf_analyzer   Source File: App.java    License: Apache License 2.0 6 votes vote down vote up
public boolean startServer() throws Exception {
	removeShutdownFile();
	File workDirectory = new File(this.getWorkDirectoryPath());
	File logDirectory = new File(this.getLogDirectoryPath());
	String deployedApplicationPath = this.getJettyHome()
			+ File.separatorChar + "webapps" + File.separatorChar
			+ this.getWarFile();
	if (!(isMeetingRequirementsToRunServer(workDirectory, logDirectory,
			deployedApplicationPath)))
		return false;
	WebAppContext deployedApplication = createDeployedApplicationInstance(
			workDirectory, deployedApplicationPath);

	// server = new Server(port);
	jettyServer = new Server();
	ServerConnector connector = this.isUseHttps()?this.sslConnector():connector();
	jettyServer.addConnector(connector);
	jettyServer.setHandler(deployedApplication);
	jettyServer.start();
	// server.join();

	// dump server state
	System.out.println(jettyServer.dump());
	this.serverURI = getServerUri(connector);
	return true;
}
 
Example 16
Source Project: zeppelin   Source File: ZeppelinServer.java    License: Apache License 2.0 6 votes vote down vote up
private static void setupRestApiContextHandler(WebAppContext webapp, ZeppelinConfiguration conf) {
  final ServletHolder servletHolder =
      new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer());

  servletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
  servletHolder.setName("rest");
  servletHolder.setForcedPath("rest");
  webapp.setSessionHandler(new SessionHandler());
  webapp.addServlet(servletHolder, "/api/*");

  String shiroIniPath = conf.getShiroPath();
  if (!StringUtils.isBlank(shiroIniPath)) {
    webapp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
    webapp
        .addFilter(ShiroFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class))
        .setInitParameter("staticSecurityManagerEnabled", "true");
    webapp.addEventListener(new EnvironmentLoaderListener());
  }
}
 
Example 17
Source Project: varOne   Source File: VarOneServer.java    License: MIT License 6 votes vote down vote up
private static WebAppContext setupWebAppContext(VarOneConfiguration conf) {
	WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(conf.getServerContextPath());
    File warPath = new File(conf.getString(ConfVars.VARONE_WAR));
    if (warPath.isDirectory()) {
      webApp.setResourceBase(warPath.getPath());
      webApp.setParentLoaderPriority(true);
    } else {
      // use packaged WAR
      webApp.setWar(warPath.getAbsolutePath());
      File warTempDirectory = new File(conf.getRelativeDir(ConfVars.VARONE_WAR_TEMPDIR));
      warTempDirectory.mkdir();
      LOG.info("VarOneServer Webapp path: {}" + warTempDirectory.getPath());
      webApp.setTempDirectory(warTempDirectory);
    }
    // Explicit bind to root
    webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    return webApp;
}
 
Example 18
public static void initWebAppContext(Server server, int type) throws Exception {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
Example 19
public static void initWebAppContext(Server server, int type) throws Exception {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
Example 20
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.
	ArrayList jarNameExprssions = Lists.newArrayList(".*/[^/]*servlet-api-[^/]*\\.jar$",
		".*/javax.servlet.jsp.jstl-.*\\.jar$", ".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(jarNameExprssions, '|'));
}
 
Example 21
public static void initWebAppContext(Server server, int type) throws Exception {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
Example 22
public static void initWebAppContext(Server server, int type) {
	System.out.println("[INFO] Application loading");
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	webAppContext.setContextPath(CONTEXT);
	webAppContext.setResourceBase(getAbsolutePath() + RESOURCE_BASE_PATH);
	webAppContext.setDescriptor(getAbsolutePath() + RESOURCE_BASE_PATH + WEB_XML_PATH);

	if (IDE_INTELLIJ == type) {
		webAppContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
		supportJspAndSetTldJarNames(server, TLD_JAR_NAMES);
	} else {
		webAppContext.setParentLoaderPriority(true);
	}

	System.out.println("[INFO] Application loaded");
}
 
Example 23
public static void supportJspAndSetTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in
	// order to correctly set up the jsp container
	org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList
		.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
		"org.eclipse.jetty.annotations.AnnotationConfiguration");
	// Set the ContainerIncludeJarPattern so that jetty examines these container-path
	// jars for
	// tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will scan for
	// them
	// instead.
	ArrayList jarNameExprssions = Lists.newArrayList(".*/[^/]*servlet-api-[^/]*\\.jar$",
		".*/javax.servlet.jsp.jstl-.*\\.jar$", ".*/[^/]*taglibs.*\\.jar$");

	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.io.github.dunwu.javaee.server.webapp.ContainerIncludeJarPattern",
		StringUtils.join(jarNameExprssions, '|'));
}
 
Example 24
Source Project: submarine   Source File: SubmarineServer.java    License: Apache License 2.0 5 votes vote down vote up
private static void setupRestApiContextHandler(WebAppContext webapp, SubmarineConfiguration conf) {
  final ServletHolder servletHolder =
      new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer());

  servletHolder.setInitParameter("javax.ws.rs.Application", SubmarineServer.class.getName());
  servletHolder.setName("rest");
  servletHolder.setForcedPath("rest");
  webapp.setSessionHandler(new SessionHandler());
  webapp.addServlet(servletHolder, "/api/*");
}
 
Example 25
Source Project: submarine   Source File: SubmarineServer.java    License: Apache License 2.0 5 votes vote down vote up
private static WebAppContext setupWebAppContext(HandlerList handlers,
    SubmarineConfiguration conf) {
  WebAppContext webApp = new WebAppContext();
  webApp.setContextPath("/");
  File warPath = new File(conf.getString(SubmarineConfVars.ConfVars.WORKBENCH_WEB_WAR));
  LOG.info("workbench web war file path is {}.",
      conf.getString(SubmarineConfVars.ConfVars.WORKBENCH_WEB_WAR));
  if (warPath.isDirectory()) {
    // Development mode, read from FS
    webApp.setResourceBase(warPath.getPath());
    webApp.setParentLoaderPriority(true);
  } else {
    // use packaged WAR
    webApp.setWar(warPath.getAbsolutePath());
    File warTempDirectory = new File("webapps");
    warTempDirectory.mkdir();
    webApp.setTempDirectory(warTempDirectory);
  }

  webApp.addServlet(new ServletHolder(new DefaultServlet()), "/");
  // When requesting the workbench page, the content of index.html needs to be returned,
  // otherwise a 404 error will be displayed
  // NOTE: If you modify the workbench directory in the front-end URL,
  // you need to modify the `/workbench/*` here.
  webApp.addServlet(new ServletHolder(RefreshServlet.class), "/user/*");
  webApp.addServlet(new ServletHolder(RefreshServlet.class), "/workbench/*");

  handlers.setHandlers(new Handler[] { webApp });

  return webApp;
}
 
Example 26
Source Project: knox   Source File: HttpServer2.java    License: Apache License 2.0 5 votes vote down vote up
private static WebAppContext createWebAppContext(Builder b,
                                                 AccessControlList adminsAcl, final String appDir) {
  WebAppContext ctx = new WebAppContext();
  ctx.setDefaultsDescriptor(null);
  ServletHolder holder = new ServletHolder(new DefaultServlet());
  Map<String, String> params = ImmutableMap. <String, String> builder()
                                   .put("acceptRanges", "true")
                                   .put("dirAllowed", "false")
                                   .put("gzip", "true")
                                   .put("useFileMappedBuffer", "true")
                                   .build();
  holder.setInitParameters(params);
  ctx.setWelcomeFiles(new String[] {"index.html"});
  ctx.addServlet(holder, "/");
  ctx.setDisplayName(b.name);
  ctx.setContextPath("/");
  ctx.setWar(appDir + "/" + b.name);
  String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY);
  if (tempDirectory != null && !tempDirectory.isEmpty()) {
    ctx.setTempDirectory(new File(tempDirectory));
    ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory);
  }
  ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf);
  ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
  addNoCacheFilter(ctx);
  return ctx;
}
 
Example 27
Source Project: gocd   Source File: GoServerLoadingIndicationHandler.java    License: Apache License 2.0 5 votes vote down vote up
GoServerLoadingIndicationHandler(WebAppContext webAppContext, SystemEnvironment systemEnvironment) {
    setContextPath("/");
    setHandler(new LoadingHandler());

    this.webAppContext = webAppContext;
    this.isWebAppStarting = !webAppContext.isAvailable();
    this.systemEnvironment = systemEnvironment;
}
 
Example 28
Source Project: tutorials   Source File: JettyServerFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a server which delegates the request handling to a web
 * application.
 * 
 * @return a server
 */
public static Server createWebAppServer() {
    // Adds an handler to a server and returns it.
    Server server = createBaseServer();
    String webAppFolderPath = JettyServerFactory.class.getClassLoader().getResource("jetty-embedded-demo-app.war").getPath();
    Handler webAppHandler = new WebAppContext(webAppFolderPath, APP_PATH);
    server.setHandler(webAppHandler);

    return server;
}
 
Example 29
Source Project: joynr   Source File: ClusteredBounceProxyWithDispatcher.java    License: Apache License 2.0 5 votes vote down vote up
private WebAppContext createBpContext(ClusterNode instance) {

        String bounceProxyUrl = serverBaseUrl + instance.getContextPath() + SL + CONTEXT_BOUNCEPROXY + SL;
        String bounceProxyDispatcherUrl = serverBaseUrl + CONTEXT_DISPATCHER + SL + CONTEXT_BOUNCEPROXY + SL;

        Properties bpProps = new Properties();
        bpProps.setProperty("joynr.bounceproxy.id", instance.getBounceProxyId());
        bpProps.setProperty("joynr.bounceproxy.controller.baseurl", bpcDispatcherUrl);
        bpProps.setProperty("joynr.bounceproxy.url4cc", bounceProxyDispatcherUrl);
        bpProps.setProperty("joynr.bounceproxy.url4bpc", bounceProxyUrl);
        bpProps.setProperty("jvmRoute", String.valueOf(instance.getInstanceId()));

        return ServersUtil.createControlledBounceproxyWebApp(instance.getContextPath(), bpProps);
    }
 
Example 30
Source Project: java-specialagent   Source File: SpringWebMvcITest.java    License: Apache License 2.0 5 votes vote down vote up
private static Server startServer() throws Exception {
  final Server server = new Server(8080);

  final WebAppContext context = new WebAppContext();
  context.setServer(server);
  context.setContextPath("/");
  context.setWar(installWebApp().getPath());

  server.setHandler(context);
  server.start();

  return server;
}