org.eclipse.jetty.webapp.WebAppContext Java Examples

The following examples show how to use org.eclipse.jetty.webapp.WebAppContext. 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: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 #2
Source File: FrontendEmbeddedWebServer.java    From FXDesktopSearch with 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 #3
Source File: JettyCustomServer.java    From nano-framework with 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 #4
Source File: WebappSessionConfigIntegrationTest.java    From gocd with 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 #5
Source File: Start.java    From javasimon with 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 #6
Source File: EmbeddedJettyTest.java    From junit-servers with 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 #7
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 #8
Source File: VarOneServer.java    From varOne with 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 #9
Source File: ZeppelinServer.java    From zeppelin with 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 #10
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 #11
Source File: EmbeddedServer.java    From xdocreport.samples with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #12
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 #13
Source File: App.java    From mysql_perf_analyzer with 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 #14
Source File: WebSessionSelfTest.java    From ignite with 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 #15
Source File: HttpBindManager.java    From Openfire with 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 #16
Source File: Spring3WebMvcTest.java    From java-specialagent with 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 #17
Source File: WebBeanConstructor.java    From zstack with 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 #18
Source File: ResolverTest.java    From cxf with 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 #19
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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 #20
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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
Source File: ContextHandlerCollectionHotSwappable.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: ExplorerServer.java    From Explorer with 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 #23
Source File: JettyServer.java    From nifi-registry with 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 #24
Source File: StartHelper.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.projectforge.webserver.AbstractStartHelper#getWebAppContext()
 */
@Override
protected WebAppContext getWebAppContext()
{
  final WebAppContext webAppContext = new WebAppContext();
  webAppContext.setClassLoader(this.getClass().getClassLoader());
  webAppContext.setConfigurationClasses(CONFIGURATION_CLASSES);
  webAppContext.setContextPath("/ProjectForge");
  webAppContext.setWar("src/main/webapp");
  webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
  webAppContext.setExtraClasspath("target/classes");
  webAppContext.setInitParameter("development", String.valueOf(startSettings.isDevelopment()));
  webAppContext.setInitParameter("stripWicketTags", String.valueOf(startSettings.isStripWicketTags()));
  return webAppContext;
}
 
Example #25
Source File: WebInfFolderExtendedConfiguration.java    From logsniffer with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected List<Resource> findJars(final WebAppContext context) throws Exception {
	List<Resource> r = super.findJars(context); // let original
												// WebInfConfiguration do
												// it's thing first
	if (r == null) {
		r = new LinkedList<Resource>();
	}

	final List<Resource> containerJarResources = context.getMetaData().getOrderedWebInfJars();
	r.addAll(containerJarResources);

	return r;
}
 
Example #26
Source File: JettyFactory.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void reloadWebAppContext(Server server) throws Exception {
	WebAppContext webAppContext = (WebAppContext) server.getHandler();
	System.out.println("[INFO] Application reloading");
	webAppContext.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
	classLoader.addClassPath(getAbsolutePath() + "target/classes");
	classLoader.addClassPath(getAbsolutePath() + "target/test-classes");
	webAppContext.setClassLoader(classLoader);
	webAppContext.start();
	System.out.println("[INFO] Application reloaded");
}
 
Example #27
Source File: JettyPlusIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 * onAppStart
 * 
 * @param args
 */
public void onAppStart(Object... args) {

    WebAppContext sc = getWebAppContext(args);

    if (sc == null) {
        return;
    }

    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STARTED);
    context.put(InterceptConstants.WEBAPPLOADER, sc.getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getServletContext().getRealPath(""));
    context.put(InterceptConstants.CONTEXTPATH, sc.getContextPath());
    context.put(InterceptConstants.APPNAME, sc.getDisplayName());

    ServletContext sContext = sc.getServletContext();

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    iSupport.doIntercept(context);

    // GlobalFilter
    sc.addFilter("com.creditease.monitor.jee.filters.GlobalFilter", "/*", EnumSet.of(DispatcherType.REQUEST));
}
 
Example #28
Source File: TapestrySecurityIntegrationTest.java    From tapestry-security with Apache License 2.0 5 votes vote down vote up
@Override
public WebAppContext buildContext()
{
	WebAppContext context = new WebAppContext("src/test/webapp", "/test");
	/*
	 * Sets the classloading model for the context to avoid an strange "ClassNotFoundException: org.slf4j.Logger"
	 */
	context.setParentLoaderPriority(true);
	return context;
}
 
Example #29
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private WebAppContext createWebAppContext(String contextPath, String[] virtualHost) {
    WebAppContext webApp = new WebAppContext();
    webApp.setParentLoaderPriority(true);
    // The following setting allows to avoid conflicts between server jackson jars and individual war jackson versions.
    webApp.addServerClass("com.fasterxml.jackson.");
    webApp.addServerClass("com.google.gson.");
    webApp.setContextPath(contextPath);
    webApp.setVirtualHosts(virtualHost);
    return webApp;
}
 
Example #30
Source File: HttpServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Add the path spec to the filter path mapping.
 * @param pathSpec The path spec
 * @param webAppCtx The WebApplicationContext to add to
 */
protected void addFilterPathMapping(String pathSpec,
    WebAppContext webAppCtx) {
  for(String name : filterNames) {
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(name);
    fmap.setDispatches(FilterMapping.ALL);
    webAppCtx.getServletHandler().addFilterMapping(fmap);
  }
}