org.eclipse.jetty.webapp.WebAppContext.setBaseResource()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.eclipse.jetty.webapp.WebAppContext.setBaseResource()方法的一些代码示例,展示了WebAppContext.setBaseResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebAppContext.setBaseResource()方法的具体详情如下:
包路径:org.eclipse.jetty.webapp.WebAppContext
类名称:WebAppContext
方法名:setBaseResource

WebAppContext.setBaseResource介绍

暂无

代码示例

代码示例来源:origin: Dreampie/Resty

webAppContext.setBaseResource(new ResourceCollection(resourceUrls.toArray(new String[resourceUrls.size()])));

代码示例来源:origin: neo4j/neo4j

staticContext.setBaseResource( resource );

代码示例来源:origin: org.springframework.boot/spring-boot

private void configureDocumentRoot(WebAppContext handler) {
  File root = getValidDocumentRoot();
  File docBase = (root != null) ? root : createTempDir("jetty-docbase");
  try {
    List<Resource> resources = new ArrayList<>();
    Resource rootResource = (docBase.isDirectory()
        ? Resource.newResource(docBase.getCanonicalFile())
        : JarResource.newJarResource(Resource.newResource(docBase)));
    resources.add((root != null) ? new LoaderHidingResource(rootResource)
        : rootResource);
    for (URL resourceJarUrl : this.getUrlsOfJarsWithMetaInfResources()) {
      Resource resource = createResource(resourceJarUrl);
      if (resource.exists() && resource.isDirectory()) {
        resources.add(resource);
      }
    }
    handler.setBaseResource(
        new ResourceCollection(resources.toArray(new Resource[0])));
  }
  catch (Exception ex) {
    throw new IllegalStateException(ex);
  }
}

代码示例来源:origin: apache/shiro

ctx.setBaseResource(newResource(webapp));

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

context.setBaseResource(web_app);
  LOG.debug("context.resourcebase = "+rc);
context.setBaseResource(rc);

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

@Override
public void deconfigure(WebAppContext context) throws Exception
{
  //if we're not persisting the temp dir contents delete it
  if (!context.isPersistTempDirectory())
  {
    IO.delete(context.getTempDirectory());
  }
  
  //if it wasn't explicitly configured by the user, then unset it
  Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED);
  if (tmpdirConfigured != null && !tmpdirConfigured) 
    context.setTempDirectory(null);
  //reset the base resource back to what it was before we did any unpacking of resources
  if (context.getBaseResource() != null)
    context.getBaseResource().close();
  context.setBaseResource(_preUnpackBaseResource);
}

代码示例来源:origin: line/armeria

static WebAppContext newWebAppContext() throws MalformedURLException {
  final WebAppContext handler = new WebAppContext();
  handler.setContextPath("/");
  handler.setBaseResource(Resource.newResource(webAppRoot()));
  handler.setClassLoader(new URLClassLoader(
      new URL[] {
          Resource.newResource(new File(webAppRoot(),
                         "WEB-INF" + File.separatorChar +
                         "lib" + File.separatorChar +
                         "hello.jar")).getURI().toURL()
      },
      JettyService.class.getClassLoader()));
  handler.addBean(new ServletContainerInitializersStarter(handler), true);
  handler.setAttribute(
      "org.eclipse.jetty.containerInitializers",
      Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null)));
  return handler;
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

for (Resource resource : resources)
  collection[i++]=resource;
context.setBaseResource(new ResourceCollection(collection));

代码示例来源:origin: stackoverflow.com

WebAppContext webapp = new WebAppContext();
webapp.setBaseResource(myBaseDirectory);
webapp.setContextPath(myContextPath);

代码示例来源:origin: cd.connect.common/connect-runnable-war

@SuppressWarnings("unchecked")
@Override
public void configure(WebAppContext context) throws Exception {
  List<Resource> resources = (List<Resource>) context.getAttribute(RESOURCE_URLS);
  if (resources != null) {
    if (resources.size() > 1) {
      List<Resource> temp = new ArrayList<>();
      temp.add(context.getBaseResource());
      temp.addAll(resources);
      context.setBaseResource(new ResourceCollection(temp.toArray(new Resource[temp.size()])));
    } else if (resources.size() == 1) {
      context.setBaseResource(resources.get(0));
    }
  }
}

代码示例来源:origin: stackoverflow.com

Server server = new Server(80);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
ResourceCollection resources = new ResourceCollection(new String[] {
  "project1/src/main/webapp", 
  "project2/src/main/webapp", 
});
context.setBaseResource(resources);
server.setHandler(context);
server.start();

代码示例来源:origin: io.provis/provisio-webserver-jetty8

private WebAppContext inSituWebApp(String context, File currentWorkingDirectory) throws IOException {
 WebAppContext webAppContext = new WebAppContext();
 webAppContext.setContextPath(context);
 File webAppDirectory = new File(currentWorkingDirectory, "src/main/webapp");
 if (!webAppDirectory.exists()) {
  throw new RuntimeException("Expecting to find a standard webapp project but there is no src/main/webapp directory.");
 }
 webAppContext.setBaseResource(Resource.newResource(webAppDirectory));
 webAppContext.setParentLoaderPriority(true);
 return webAppContext;
}

代码示例来源:origin: com.github.dapeng-soa/dapeng-api-doc

public static Server createServer(int port) throws MalformedURLException, URISyntaxException {
  Server server = new Server();
  server.setStopAtShutdown(true);
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  connector.setReuseAddress(true);
  server.setConnectors(new Connector[]{connector});
  WebAppContext webContext = new WebAppContext("webapp", CONTEXT);
  webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), ".")));
  webContext.setClassLoader(ApiWebSite.class.getClassLoader());
  server.setHandler(webContext);
  return server;
}

代码示例来源:origin: dapeng-soa/dapeng-soa

public static Server createServer(int port) throws MalformedURLException, URISyntaxException {
  Server server = new Server();
  server.setStopAtShutdown(true);
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  connector.setReuseAddress(true);
  server.setConnectors(new Connector[]{connector});
  WebAppContext webContext = new WebAppContext("webapp", CONTEXT);
  webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), ".")));
  webContext.setClassLoader(ApiWebSite.class.getClassLoader());
  server.setHandler(webContext);
  return server;
}

代码示例来源:origin: isuwang/isuwang-soa

public static Server createServer(int port) throws MalformedURLException, URISyntaxException {
  Server server = new Server();
  server.setStopAtShutdown(true);
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  connector.setReuseAddress(false);
  server.setConnectors(new Connector[]{connector});
  WebAppContext webContext = new WebAppContext("webapp", CONTEXT);
  webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), ".")));
  webContext.setClassLoader(ApiWebSite.class.getClassLoader());
  server.setHandler(webContext);
  return server;
}

代码示例来源:origin: org.unidal.framework/test-framework

protected void configure(WebAppContext context) throws Exception {
 File warRoot = getWarRoot();
 m_resource = new WebModuleResource(warRoot);
 context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
 context.setContextPath(getContextPath());
 context.setDescriptor(new File(warRoot, "WEB-INF/web.xml").getPath());
 context.setBaseResource(m_resource);
}

代码示例来源:origin: org.secnod.shiro/shiro-jersey

public static Server start(int port) throws Exception {
  Server server = new Server(port);
  WebAppContext webapp = new WebAppContext();
  webapp.setContextPath("/");
  String resourcePath = JettyServer.class.getPackage().getName().replace('.', '/');
  webapp.setBaseResource(Resource.newClassPathResource(resourcePath));
  webapp.setParentLoaderPriority(true);
  server.setHandler(webapp);
  server.setStopTimeout(5000);
  server.start();
  return server;
}

代码示例来源:origin: apache/cxf

protected void run() {
  //System.out.println("Starting Server");
  server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
  WebAppContext webappcontext = new WebAppContext();
  webappcontext.setContextPath("/");
  webappcontext.setBaseResource(Resource.newClassPathResource("/webapp"));
  server.setHandler(new HandlerCollection(webappcontext, new DefaultHandler()));
  try {
    server.start();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
public void tearDown() throws Exception {

代码示例来源:origin: apache/cxf

protected void run() {
  server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
  WebAppContext webappcontext = new WebAppContext();
  webappcontext.setContextPath("/digestauth");
  webappcontext.setBaseResource(Resource.newClassPathResource("/digestauth"));
  HandlerCollection handlers = new HandlerCollection();
  handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
  server.setHandler(handlers);
  try {
    configureServer();
    server.start();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
public void tearDown() throws Exception {

代码示例来源:origin: apache/cxf

@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();
}

相关文章

WebAppContext类方法