當前位置: 首頁>>代碼示例>>Java>>正文


Java WebAppContext.setAttribute方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.webapp.WebAppContext.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java WebAppContext.setAttribute方法的具體用法?Java WebAppContext.setAttribute怎麽用?Java WebAppContext.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.webapp.WebAppContext的用法示例。


在下文中一共展示了WebAppContext.setAttribute方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

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

        WebAppContext context = new WebAppContext();
        context.setServer(server);
        context.setContextPath("/");
        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$");
        context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
        context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
        context.addBean(new ServletContainerInitializersStarter(context), true);

        // Prevent loading of logging classes
        context.getSystemClasspathPattern().add("org.apache.log4j.");
        context.getSystemClasspathPattern().add("org.slf4j.");
        context.getSystemClasspathPattern().add("org.apache.commons.logging.");

        ProtectionDomain protectionDomain = EmbeddedJettyServer.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();
        context.setWar(location.toExternalForm());

        server.setHandler(context);
        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:37,代碼來源:EmbeddedJettyServer.java

示例2: preConfigure

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
@Override
public void preConfigure(WebAppContext context) throws Exception {
	final Set<String> set = Collections.singleton(AutoPivotWebAppInitializer.class.getName());
	final Map<String, Set<String>> map = new ClassInheritanceMap();
	map.put(WebApplicationInitializer.class.getName(), set);
	context.setAttribute(CLASS_INHERITANCE_MAP, map);
	_classInheritanceHandler = new ClassInheritanceHandler(map);
}
 
開發者ID:activeviam,項目名稱:autopivot,代碼行數:9,代碼來源:AutoPivotLauncher.java

示例3: createWebApp

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
     * Creates a web-app deployment for a war file gives as path
     * @param webappWar
     *  path to the war file
     * @return
     *  a webApplication context that can be deployed on the jetty server.
     */
    private static WebAppContext createWebApp(final Path webappWar) throws IOException {

//        Path tempWar = Files.createTempFile("bdj-", webappWar.getFileName().toString());
//        LOG.info("Creating temporary copy of war " + tempWar);
//        Files.copy(webappWar, tempWar, StandardCopyOption.REPLACE_EXISTING);
//        LOG.info("Deploying web app from " + tempWar);

        final WebAppContext webapp = new WebAppContext();
        webapp.setSystemClasses(new String[] {
                Configuration.class.getName(), ConfigChangeListener.class.getName()
        });
        webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                            ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

		/*
         * Configure the application to support the compilation of JSP files.
		 * We need a new class loader and some stuff so that Jetty can call the
		 * onStartup() methods as required.
		 */
        webapp.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
        webapp.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
        webapp.addBean(new ServletContainerInitializersStarter(webapp), true);
        webapp.setContextPath("/");
        webapp.setWar(webappWar.toString());
        return webapp;
    }
 
開發者ID:gmuecke,項目名稱:boutique-de-jus,代碼行數:34,代碼來源:BoutiqueDeJusWebServer.java

示例4: loadWar

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private static WebAppContext loadWar(final File warFile, final String contextPath, final ClassLoader parentClassLoader) throws IOException {
    final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
    webappContext.setContextPath(contextPath);
    webappContext.setDisplayName(contextPath);

    // instruction jetty to examine these jars for tlds, web-fragments, etc
    webappContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\\\.jar$|.*/[^/]*taglibs.*\\.jar$" );

    // remove slf4j server class to allow WAR files to have slf4j dependencies in WEB-INF/lib
    List<String> serverClasses = new ArrayList<>(Arrays.asList(webappContext.getServerClasses()));
    serverClasses.remove("org.slf4j.");
    webappContext.setServerClasses(serverClasses.toArray(new String[0]));
    webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);

    // get the temp directory for this webapp
    File tempDir = Paths.get(C2_SERVER_HOME, "tmp", warFile.getName()).toFile();
    if (tempDir.exists() && !tempDir.isDirectory()) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " is not a directory");
    } else if (!tempDir.exists()) {
        final boolean made = tempDir.mkdirs();
        if (!made) {
            throw new RuntimeException(tempDir.getAbsolutePath() + " could not be created");
        }
    }
    if (!(tempDir.canRead() && tempDir.canWrite())) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " directory does not have read/write privilege");
    }

    // configure the temp dir
    webappContext.setTempDirectory(tempDir);

    // configure the max form size (3x the default)
    webappContext.setMaxFormContentSize(600000);

    webappContext.setClassLoader(new WebAppClassLoader(parentClassLoader, webappContext));

    logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
    return webappContext;
}
 
開發者ID:apache,項目名稱:nifi-minifi,代碼行數:40,代碼來源:JettyServer.java

示例5: addResource

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private void addResource(WebAppContext context, Resource jar) {
	@SuppressWarnings("unchecked")
	Set<Resource> list = (Set<Resource>) context.getAttribute(METAINF_RESOURCES);
	if (list == null) {
		list = new LinkedHashSet<Resource>();
		context.setAttribute(METAINF_RESOURCES, list);
	}
	if (!list.contains(jar)) {
		list.add(jar);
	}
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:12,代碼來源:AbstractClassPathService.java

示例6: setTldJarNames

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * 設置除jstl-*.jar外其他含tld文件的jar包的名稱.
 * jar名稱不需要版本號,如sitemesh, shiro-web
 */
public static void setTldJarNames(Server server, String... jarNames) {
	WebAppContext context = (WebAppContext) server.getHandler();
	List<String> jarNameExprssions = Lists.newArrayList(".*/jstl-[^/]*\\.jar$", ".*/.*taglibs[^/]*\\.jar$");
	for (String jarName : jarNames) {
		jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
	}

	context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
			StringUtils.join(jarNameExprssions, '|'));

}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:16,代碼來源:JettyFactory.java

示例7: main

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public static void main(final String[] args) {
  InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 8080);
  final Server server = new Server(_inetSocketAddress);
  WebAppContext _webAppContext = new WebAppContext();
  final Procedure1<WebAppContext> _function = (WebAppContext it) -> {
    it.setResourceBase("WebRoot");
    it.setWelcomeFiles(new String[] { "index.html" });
    it.setContextPath("/");
    AnnotationConfiguration _annotationConfiguration = new AnnotationConfiguration();
    WebXmlConfiguration _webXmlConfiguration = new WebXmlConfiguration();
    WebInfConfiguration _webInfConfiguration = new WebInfConfiguration();
    MetaInfConfiguration _metaInfConfiguration = new MetaInfConfiguration();
    it.setConfigurations(new Configuration[] { _annotationConfiguration, _webXmlConfiguration, _webInfConfiguration, _metaInfConfiguration });
    it.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/com\\.hribol\\.bromium\\.dsl\\.web/.*,.*\\.jar");
    it.setInitParameter("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
  };
  WebAppContext _doubleArrow = ObjectExtensions.<WebAppContext>operator_doubleArrow(_webAppContext, _function);
  server.setHandler(_doubleArrow);
  String _name = ServerLauncher.class.getName();
  final Slf4jLog log = new Slf4jLog(_name);
  try {
    server.start();
    URI _uRI = server.getURI();
    String _plus = ("Server started " + _uRI);
    String _plus_1 = (_plus + "...");
    log.info(_plus_1);
    final Runnable _function_1 = () -> {
      try {
        log.info("Press enter to stop the server...");
        final int key = System.in.read();
        if ((key != (-1))) {
          server.stop();
        } else {
          log.warn("Console input is not available. In order to stop the server, you need to cancel process manually.");
        }
      } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
      }
    };
    new Thread(_function_1).start();
    server.join();
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exception = (Exception)_t;
      log.warn(exception.getMessage());
      System.exit(1);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:52,代碼來源:ServerLauncher.java

示例8: main

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public static void main(final String[] args) {
  InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 8080);
  final Server server = new Server(_inetSocketAddress);
  WebAppContext _webAppContext = new WebAppContext();
  final Procedure1<WebAppContext> _function = (WebAppContext it) -> {
    it.setResourceBase("WebRoot");
    it.setWelcomeFiles(new String[] { "index.html" });
    it.setContextPath("/");
    AnnotationConfiguration _annotationConfiguration = new AnnotationConfiguration();
    WebXmlConfiguration _webXmlConfiguration = new WebXmlConfiguration();
    WebInfConfiguration _webInfConfiguration = new WebInfConfiguration();
    MetaInfConfiguration _metaInfConfiguration = new MetaInfConfiguration();
    it.setConfigurations(new Configuration[] { _annotationConfiguration, _webXmlConfiguration, _webInfConfiguration, _metaInfConfiguration });
    it.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/org\\.xtext\\.dsl\\.restaurante\\.web/.*,.*\\.jar");
    it.setInitParameter("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
  };
  WebAppContext _doubleArrow = ObjectExtensions.<WebAppContext>operator_doubleArrow(_webAppContext, _function);
  server.setHandler(_doubleArrow);
  String _name = ServerLauncher.class.getName();
  final Slf4jLog log = new Slf4jLog(_name);
  try {
    server.start();
    URI _uRI = server.getURI();
    String _plus = ("Server started " + _uRI);
    String _plus_1 = (_plus + "...");
    log.info(_plus_1);
    final Runnable _function_1 = () -> {
      try {
        log.info("Press enter to stop the server...");
        final int key = System.in.read();
        if ((key != (-1))) {
          server.stop();
        } else {
          log.warn("Console input is not available. In order to stop the server, you need to cancel process manually.");
        }
      } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
      }
    };
    new Thread(_function_1).start();
    server.join();
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exception = (Exception)_t;
      log.warn(exception.getMessage());
      System.exit(1);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
開發者ID:vicegd,項目名稱:org.xtext.dsl.restaurante,代碼行數:52,代碼來源:ServerLauncher.java

示例9: initJSP

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private void initJSP(WebAppContext ctx) throws IOException {
    ctx.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    ctx.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    ctx.addBean(new ServletContainerInitializersStarter(ctx), true);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:steve-plugsurfing,代碼行數:6,代碼來源:SteveAppContext.java


注:本文中的org.eclipse.jetty.webapp.WebAppContext.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。